use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector 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.vector.DenseLocalOnHeapVector 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.vector.DenseLocalOnHeapVector in project ignite by apache.
the class ColumnDecisionTreeTrainerTest method testCacheMixed.
/**
* Test {@link ColumnDecisionTreeTrainerTest} for mixed (continuous and categorical) data with Variance impurity.
*/
public void testCacheMixed() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
int totalPts = 1 << 10;
int featCnt = 2;
HashMap<Integer, Integer> catsInfo = new HashMap<>();
catsInfo.put(1, 3);
Random rnd = new Random(12349L);
SplitDataGenerator<DenseLocalOnHeapVector> gen = new SplitDataGenerator<>(featCnt, catsInfo, () -> new DenseLocalOnHeapVector(featCnt + 1), rnd).split(0, 1, new int[] { 0, 2 }).split(1, 0, -10.0);
testByGen(totalPts, catsInfo, gen, ContinuousSplitCalculators.VARIANCE, RegionCalculators.VARIANCE, RegionCalculators.MEAN, rnd);
}
use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector in project ignite by apache.
the class ColumnDecisionTreeTrainerTest method testCacheMixedGini.
/**
* Test {@link ColumnDecisionTreeTrainerTest} for mixed (continuous and categorical) data with Gini impurity.
*/
public void testCacheMixedGini() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
int totalPts = 1 << 10;
int featCnt = 2;
HashMap<Integer, Integer> catsInfo = new HashMap<>();
catsInfo.put(1, 3);
Random rnd = new Random(12349L);
SplitDataGenerator<DenseLocalOnHeapVector> gen = new SplitDataGenerator<>(featCnt, catsInfo, () -> new DenseLocalOnHeapVector(featCnt + 1), rnd).split(0, 1, new int[] { 0, 2 }).split(1, 0, -10.0);
testByGen(totalPts, catsInfo, gen, ContinuousSplitCalculators.GINI.apply(ignite), RegionCalculators.GINI, RegionCalculators.MEAN, rnd);
}
use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector in project ignite by apache.
the class BlasTest method testGemvSparseSparseDense.
/**
* Tests 'gemv' operation for sparse matrix A, sparse vector x and dense vector y.
*/
@Test
public void testGemvSparseSparseDense() {
// y := alpha * A * x + beta * y
double alpha = 3.0;
DenseLocalOnHeapMatrix a = new DenseLocalOnHeapMatrix(new double[][] { { 10.0, 11.0 }, { 0.0, 1.0 } }, 2);
SparseLocalVector x = sparseFromArray(new double[] { 1.0, 2.0 });
double beta = 2.0;
DenseLocalOnHeapVector y = new DenseLocalOnHeapVector(new double[] { 3.0, 4.0 });
DenseLocalOnHeapVector exp = (DenseLocalOnHeapVector) y.times(beta).plus(a.times(x).times(alpha));
Blas.gemv(alpha, a, x, beta, y);
Assert.assertEquals(exp, y);
}
Aggregations