Search in sources :

Example 96 with DenseLocalOnHeapVector

use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector in project ignite by apache.

the class LUDecompositionTest method solveVec.

/**
 */
@Test
public void solveVec() throws Exception {
    Vector sol = new LUDecomposition(new PivotedMatrixView(testMatrix)).solve(new DenseLocalOnHeapVector(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);
}
Also used : PivotedMatrixView(org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Vector(org.apache.ignite.ml.math.Vector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Test(org.junit.Test)

Example 97 with DenseLocalOnHeapVector

use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector in project ignite by apache.

the class ColumnDecisionTreeTrainerTest method testCacheCont.

/**
 * Test {@link ColumnDecisionTreeTrainerTest} for continuous data with Variance impurity.
 */
public void testCacheCont() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    int totalPts = 1 << 10;
    int featCnt = 12;
    HashMap<Integer, Integer> catsInfo = new HashMap<>();
    Random rnd = new Random(12349L);
    SplitDataGenerator<DenseLocalOnHeapVector> gen = new SplitDataGenerator<>(featCnt, catsInfo, () -> new DenseLocalOnHeapVector(featCnt + 1), rnd).split(0, 0, -10.0).split(1, 0, 0.0).split(1, 1, 2.0).split(3, 7, 50.0);
    testByGen(totalPts, catsInfo, gen, ContinuousSplitCalculators.VARIANCE, RegionCalculators.VARIANCE, RegionCalculators.MEAN, rnd);
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)

Example 98 with DenseLocalOnHeapVector

use of org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector in project ignite by apache.

the class FuzzyCMeansLocalClusterer method cluster.

/**
 * {@inheritDoc}
 */
@Override
public FuzzyCMeansModel cluster(DenseLocalOnHeapMatrix points, int k, List<Double> weights) throws MathIllegalArgumentException, ConvergenceException {
    GridArgumentCheck.notNull(points, "points");
    GridArgumentCheck.notNull(weights, "weights");
    if (points.rowSize() != weights.size())
        throw new MathIllegalArgumentException("The number of points and the number of weights are not equal");
    if (k < 2)
        throw new MathIllegalArgumentException("The number of clusters is less than 2");
    Matrix centers = new DenseLocalOnHeapMatrix(k, points.columnSize());
    Matrix distances = new DenseLocalOnHeapMatrix(k, points.rowSize());
    Matrix membership = new DenseLocalOnHeapMatrix(k, points.rowSize());
    Vector weightsVector = new DenseLocalOnHeapVector(weights.size());
    for (int i = 0; i < weights.size(); i++) weightsVector.setX(i, weights.get(i));
    initializeCenters(centers, points, k, weightsVector);
    int iteration = 0;
    boolean finished = false;
    while (iteration < maxIterations && !finished) {
        calculateDistances(distances, points, centers);
        Matrix newMembership = calculateMembership(distances, weightsVector);
        Matrix newCenters = calculateNewCenters(points, newMembership);
        if (this.stopCond == StopCondition.STABLE_CENTERS)
            finished = areCentersStable(centers, newCenters);
        else
            finished = areMembershipStable(membership, newMembership);
        centers = newCenters;
        membership = newMembership;
        iteration++;
    }
    if (iteration == maxIterations)
        throw new ConvergenceException("Fuzzy C-Means algorithm has not converged after " + Integer.toString(iteration) + " iterations");
    Vector[] centersArr = new Vector[k];
    for (int i = 0; i < k; i++) centersArr[i] = centers.getRow(i);
    return new FuzzyCMeansModel(centersArr, measure);
}
Also used : Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) MathIllegalArgumentException(org.apache.ignite.ml.math.exceptions.MathIllegalArgumentException) ConvergenceException(org.apache.ignite.ml.math.exceptions.ConvergenceException) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) Vector(org.apache.ignite.ml.math.Vector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)

Aggregations

DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)98 Vector (org.apache.ignite.ml.math.Vector)49 Test (org.junit.Test)44 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)26 Random (java.util.Random)18 HashMap (java.util.HashMap)17 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)14 Matrix (org.apache.ignite.ml.math.Matrix)12 SparseDistributedMatrix (org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix)11 IgniteCache (org.apache.ignite.IgniteCache)8 LabeledDataset (org.apache.ignite.ml.structures.LabeledDataset)8 Arrays (java.util.Arrays)7 Collections (java.util.Collections)6 List (java.util.List)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6 Ignite (org.apache.ignite.Ignite)6 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)6 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)6