use of org.apache.ignite.ml.math.primitives.matrix.Matrix in project ignite by apache.
the class AbstractVector method toMatrixPlusOne.
/**
* {@inheritDoc}
*/
@Override
public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
Matrix res = likeMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1);
if (res == null)
return null;
res.set(0, 0, zeroVal);
if (rowLike)
new ViewMatrix(res, 0, 1, 1, size()).assignRow(0, this);
else
new ViewMatrix(res, 1, 0, size(), 1).assignColumn(0, this);
return res;
}
use of org.apache.ignite.ml.math.primitives.matrix.Matrix in project ignite by apache.
the class VectorToMatrixTest method availableForTesting.
/**
*/
private boolean availableForTesting(Vector v) {
assertNotNull("Error in test: vector is null", v);
final boolean availableForTesting = typesMap.get(v.getClass()) != null;
final Matrix actualLikeMatrix = v.likeMatrix(1, 1);
assertTrue("Need to enable matrix testing for vector type " + v.getClass().getSimpleName(), availableForTesting || actualLikeMatrix == null);
return availableForTesting;
}
use of org.apache.ignite.ml.math.primitives.matrix.Matrix in project ignite by apache.
the class VectorToMatrixTest method testLikeMatrix.
/**
*/
@Test
public void testLikeMatrix() {
consumeSampleVectors((v, desc) -> {
if (!availableForTesting(v))
return;
final Matrix matrix = v.likeMatrix(1, 1);
Class<? extends Vector> key = v.getClass();
Class<? extends Matrix> expMatrixType = typesMap.get(key);
assertNotNull("Expect non-null matrix for " + key.getSimpleName() + " in " + desc, matrix);
Class<? extends Matrix> actualMatrixType = matrix.getClass();
assertTrue("Expected matrix type " + expMatrixType.getSimpleName() + " should be assignable from actual type " + actualMatrixType.getSimpleName() + " in " + desc, expMatrixType.isAssignableFrom(actualMatrixType));
for (int rows : new int[] { 1, 2 }) for (int cols : new int[] { 1, 2 }) {
final Matrix actualMatrix = v.likeMatrix(rows, cols);
String details = "rows " + rows + " cols " + cols;
assertNotNull("Expect non-null matrix for " + details + " in " + desc, actualMatrix);
assertEquals("Unexpected number of rows in " + desc, rows, actualMatrix.rowSize());
assertEquals("Unexpected number of cols in " + desc, cols, actualMatrix.columnSize());
}
});
}
use of org.apache.ignite.ml.math.primitives.matrix.Matrix in project ignite by apache.
the class VectorToMatrixTest method assertCross.
/**
*/
private void assertCross(Vector v1, Vector v2, String desc) {
assertNotNull(v1);
assertNotNull(v2);
final Matrix res = v1.cross(v2);
assertNotNull("Cross matrix is expected to be not null in " + desc, res);
assertEquals("Unexpected number of rows in cross Matrix in " + desc, v1.size(), res.rowSize());
assertEquals("Unexpected number of cols in cross Matrix in " + desc, v2.size(), res.columnSize());
for (int row = 0; row < v1.size(); row++) for (int col = 0; col < v2.size(); col++) {
final Metric metric = new Metric(v1.get(row) * v2.get(col), res.get(row, col));
assertTrue("Not close enough cross " + metric + " at row " + row + " at col " + col + " in " + desc, metric.closeEnough());
}
}
use of org.apache.ignite.ml.math.primitives.matrix.Matrix in project ignite by apache.
the class TracerTest method testAsciiMatrixTracer.
/**
*/
@Test
public void testAsciiMatrixTracer() {
Matrix mtx = makeRandomMatrix(10, 10);
Tracer.showAscii(mtx);
Tracer.showAscii(mtx, "%2f");
Tracer.showAscii(mtx, "%.3g");
}
Aggregations