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);
}
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);
}
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);
}
Aggregations