use of org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix in project ignite by apache.
the class FuzzyCMeansLocalClustererTest method equalWeightsTwoDimensions.
/**
* Test FCM on points that forms four clusters on the plane.
*/
@Test
public void equalWeightsTwoDimensions() {
FuzzyCMeansLocalClusterer clusterer = new FuzzyCMeansLocalClusterer(new EuclideanDistance(), 2, BaseFuzzyCMeansClusterer.StopCondition.STABLE_CENTERS, 0.01, 20, null);
double[][] points = new double[][] { { -10, -10 }, { -9, -11 }, { -10, -9 }, { -11, -9 }, { 10, 10 }, { 9, 11 }, { 10, 9 }, { 11, 9 }, { -10, 10 }, { -9, 11 }, { -10, 9 }, { -11, 9 }, { 10, -10 }, { 9, -11 }, { 10, -9 }, { 11, -9 } };
DenseLocalOnHeapMatrix pntMatrix = new DenseLocalOnHeapMatrix(points);
FuzzyCMeansModel mdl = clusterer.cluster(pntMatrix, 4);
Vector[] centers = mdl.centers();
Arrays.sort(centers, Comparator.comparing(vector -> Math.atan2(vector.get(1), vector.get(0))));
DistanceMeasure measure = mdl.distanceMeasure();
assertEquals(0, measure.compute(centers[0], new DenseLocalOnHeapVector(new double[] { -10, -10 })), 1);
assertEquals(0, measure.compute(centers[1], new DenseLocalOnHeapVector(new double[] { 10, -10 })), 1);
assertEquals(0, measure.compute(centers[2], new DenseLocalOnHeapVector(new double[] { 10, 10 })), 1);
assertEquals(0, measure.compute(centers[3], new DenseLocalOnHeapVector(new double[] { -10, 10 })), 1);
}
use of org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix in project ignite by apache.
the class FuzzyCMeansLocalClustererTest method testIllegalNumberOfClusters.
/**
* Test FCM on illegal number of clusters.
*/
@Test(expected = MathIllegalArgumentException.class)
public void testIllegalNumberOfClusters() {
FuzzyCMeansLocalClusterer clusterer = new FuzzyCMeansLocalClusterer(new EuclideanDistance(), 2, BaseFuzzyCMeansClusterer.StopCondition.STABLE_CENTERS, 0.01, 10, null);
double[][] points = new double[][] { { 1 }, { 2 }, { 3 }, { 4 } };
clusterer.cluster(new DenseLocalOnHeapMatrix(points), 1);
}
use of org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix in project ignite by apache.
the class IgniteCholeskyDecompositionBenchmark method runCholeskyDecomposition.
/**
* Based on CholeskyDecompositionTest.
*/
private void runCholeskyDecomposition() {
final DataChanger.Scale scale = new DataChanger.Scale();
Matrix m = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { { 2.0d, -1.0d, 0.0d }, { -1.0d, 2.0d, -1.0d }, { 0.0d, -1.0d, 2.0d } }));
CholeskyDecomposition dec = new CholeskyDecomposition(m);
dec.getL();
dec.getLT();
Matrix bs = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { { 4.0, -6.0, 7.0 }, { 1.0, 1.0, 1.0 } })).transpose();
dec.solve(bs);
Vector b = new DenseLocalOnHeapVector(scale.mutate(new double[] { 4.0, -6.0, 7.0 }));
dec.solve(b);
dec.destroy();
}
use of org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix in project ignite by apache.
the class LUDecompositionTest method setUp.
/**
*/
@Before
public void setUp() {
double[][] rawMatrix = new double[][] { { 2.0d, 1.0d, 1.0d, 0.0d }, { 4.0d, 3.0d, 3.0d, 1.0d }, { 8.0d, 7.0d, 9.0d, 5.0d }, { 6.0d, 7.0d, 9.0d, 8.0d } };
double[][] rawL = { { 1.0d, 0.0d, 0.0d, 0.0d }, { 3.0d / 4.0d, 1.0d, 0.0d, 0.0d }, { 1.0d / 2.0d, -2.0d / 7.0d, 1.0d, 0.0d }, { 1.0d / 4.0d, -3.0d / 7.0d, 1.0d / 3.0d, 1.0d } };
double[][] rawU = { { 8.0d, 7.0d, 9.0d, 5.0d }, { 0.0d, 7.0d / 4.0d, 9.0d / 4.0d, 17.0d / 4.0d }, { 0.0d, 0.0d, -6.0d / 7.0d, -2.0d / 7.0d }, { 0.0d, 0.0d, 0.0d, 2.0d / 3.0d } };
double[][] rawP = new double[][] { { 0, 0, 1.0d, 0 }, { 0, 0, 0, 1.0d }, { 0, 1.0d, 0, 0 }, { 1.0d, 0, 0, 0 } };
rawPivot = new int[] { 3, 4, 2, 1 };
testMatrix = new DenseLocalOnHeapMatrix(rawMatrix);
testL = new DenseLocalOnHeapMatrix(rawL);
testU = new DenseLocalOnHeapMatrix(rawU);
testP = new DenseLocalOnHeapMatrix(rawP);
}
use of org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix in project ignite by apache.
the class SingularValueDecompositionTest method rowsLessThanColumnsTest.
/**
*/
@Test
public void rowsLessThanColumnsTest() {
DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] { { 2.0d, -1.0d, 0.0d }, { -1.0d, 2.0d, -1.0d } });
SingularValueDecomposition dec = new SingularValueDecomposition(m);
assertEquals("Unexpected value for singular values size.", 2, dec.getSingularValues().length);
Matrix s = dec.getS();
Matrix u = dec.getU();
Matrix v = dec.getV();
Matrix covariance = dec.getCovariance(0.5);
assertNotNull("Matrix s is expected to be not null.", s);
assertNotNull("Matrix u is expected to be not null.", u);
assertNotNull("Matrix v is expected to be not null.", v);
assertNotNull("Covariance matrix is expected to be not null.", covariance);
dec.destroy();
}
Aggregations