use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class AbstractMultipleLinearRegression method estimateResiduals.
/**
* {@inheritDoc}
*/
@Override
public double[] estimateResiduals() {
Vector b = calculateBeta();
Vector e = yVector.minus(xMatrix.times(b));
return e.getStorage().data();
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorBenchmarkTest method basicMix.
/** */
private void basicMix(int size, Function<Integer, Vector> constructor) {
final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
for (int idx = 0; idx < size; idx++) {
v1.set(idx, idx);
v2.set(idx, size - idx);
}
assertNotNull(v1.sum());
assertNotNull(v1.copy());
assertFalse(v1.getLengthSquared() < 0);
assertNotNull(v1.normalize());
assertNotNull(v1.logNormalize());
assertFalse(v1.getDistanceSquared(v2) < 0);
assertNotNull(v1.divide(2));
assertNotNull(v1.minus(v2));
assertNotNull(v1.plus(v2));
assertNotNull(v1.dot(v2));
assertNotNull(v1.assign(v2));
// IMPL NOTE this would better be last test for it sets all values the same
assertNotNull(v1.assign(1));
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorBenchmarkTest method foldMapMix.
/** */
private void foldMapMix(int size, Function<Integer, Vector> constructor) {
final Vector v1 = constructor.apply(size), v2 = constructor.apply(size);
for (int idx = 0; idx < size; idx++) {
v1.set(idx, idx);
v2.set(idx, size - idx);
}
assertNotNull(v1.map((val) -> (val + 1)));
assertNotNull(v1.map(v2, (one, other) -> one + other / 2.0));
assertNotNull(v1.map((val, val1) -> (val + val1), 2.0));
assertNotNull(v1.foldMap((sum, val) -> (val + sum), (val) -> val, 0.0));
assertNotNull(v1.foldMap(v2, (sum, val) -> (val + sum), (val1, val2) -> val1 + val2, 0.0));
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class CholeskyDecompositionTest method basicTest.
/** */
private void basicTest(Matrix m) {
// This decomposition is useful when dealing with systems of linear equations of the form
// m x = b where m is a Hermitian matrix.
// For such systems Cholesky decomposition provides
// more effective method of solving compared to LU decomposition.
// Suppose we want to solve system
// m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs
// as a matrix of the form
// (b1, b2, ..., bm)
// to the method Cholesky::solve which returns solutions in the form
// (sol1, sol2, ..., solm)
CholeskyDecomposition dec = new CholeskyDecomposition(m);
assertEquals("Unexpected value for decomposition determinant.", 4d, dec.getDeterminant(), 0d);
Matrix l = dec.getL();
Matrix lt = dec.getLT();
assertNotNull("Matrix l is expected to be not null.", l);
assertNotNull("Matrix lt is expected to be not null.", lt);
for (int row = 0; row < l.rowSize(); row++) for (int col = 0; col < l.columnSize(); col++) assertEquals("Unexpected value transposed matrix at (" + row + "," + col + ").", l.get(row, col), lt.get(col, row), 0d);
Matrix bs = new DenseLocalOnHeapMatrix(new double[][] { { 4.0, -6.0, 7.0 }, { 1.0, 1.0, 1.0 } }).transpose();
Matrix sol = dec.solve(bs);
assertNotNull("Solution matrix is expected to be not null.", sol);
assertEquals("Solution rows are not as expected.", bs.rowSize(), sol.rowSize());
assertEquals("Solution columns are not as expected.", bs.columnSize(), sol.columnSize());
for (int i = 0; i < sol.columnSize(); i++) assertNotNull("Solution matrix column is expected to be not null at index " + i, sol.viewColumn(i));
Vector b = new DenseLocalOnHeapVector(new double[] { 4.0, -6.0, 7.0 });
Vector solVec = dec.solve(b);
for (int idx = 0; idx < b.size(); idx++) assertEquals("Unexpected value solution vector at " + idx, b.get(idx), solVec.get(idx), 0d);
dec.destroy();
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class AbstractVector method plus.
/** {@inheritDoc} */
@Override
public Vector plus(Vector vec) {
checkCardinality(vec);
Vector cp = copy();
return cp.map(vec, Functions.PLUS);
}
Aggregations