use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class VectorImplementationsTest method assignVectorTest.
/**
*/
@Test
public void assignVectorTest() {
consumeSampleVectors((v, desc) -> {
if (readOnly())
return;
final int size = v.size();
final double[] ref = new double[size];
final ElementsChecker checker = new ElementsChecker(v, ref, desc);
for (int idx = 0; idx < size; idx++) ref[idx] = -ref[idx];
v.assign(new DenseVector(ref));
checker.assertCloseEnough(v, ref);
assignVectorWrongCardinality(v, desc);
});
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class VectorToMatrixTest method testCross.
/**
*/
@Test
public void testCross() {
consumeSampleVectors((v, desc) -> {
if (!availableForTesting(v))
return;
fillWithNonZeroes(v);
for (int delta : new int[] { -1, 0, 1 }) {
final int size2 = v.size() + delta;
if (size2 < 1)
return;
final Vector v2 = new DenseVector(size2);
for (Vector.Element e : v2.all()) e.set(size2 - e.index());
assertCross(v, v2, desc);
}
});
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class PipelineMdlTest method verifyPredict.
/**
*/
private void verifyPredict(PipelineMdl mdl) {
Vector observation = new DenseVector(new double[] { 1.0, 1.0 });
TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
observation = new DenseVector(new double[] { 2.0, 1.0 });
TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 2.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
observation = new DenseVector(new double[] { 1.0, 2.0 });
TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 + 3.0 * 2.0), mdl.predict(observation), PRECISION);
observation = new DenseVector(new double[] { -2.0, 1.0 });
TestUtils.assertEquals(sigmoid(1.0 - 2.0 * 2.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
observation = new DenseVector(new double[] { 1.0, -2.0 });
TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 - 3.0 * 2.0), mdl.predict(observation), PRECISION);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class LUDecompositionTest method solveVec.
/**
*/
@Test
public void solveVec() throws Exception {
Vector sol = new LUDecomposition(testMatrix).solve(new DenseVector(testMatrix.rowSize()));
assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size());
for (int i = 0; i < sol.size(); i++) assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class DelegatingVectorConstructorTest method basicTest.
/**
*/
@Test
public void basicTest() {
final Vector parent = new DenseVector(new double[] { 0, 1 });
final DelegatingVector delegate = new DelegatingVector(parent);
final int size = parent.size();
assertEquals("Delegate size differs from expected.", size, delegate.size());
assertEquals("Delegate vector differs from expected.", parent, delegate.getVector());
for (int idx = 0; idx < size; idx++) assertDelegate(parent, delegate, idx);
}
Aggregations