use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorToMatrixTest method testCross.
/** */
@Test
public void testCross() {
consumeSampleVectors((v, desc) -> {
if (!availableForTesting(v))
return;
fillWithNonZeroes(v);
for (int delta : new int[] { -1, 0, 1 }) {
final int size2 = v.size() + delta;
if (size2 < 1)
return;
final Vector v2 = new DenseLocalOnHeapVector(size2);
for (Vector.Element e : v2.all()) e.set(size2 - e.index());
assertCross(v, v2, desc);
}
});
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class AbstractMultipleLinearRegressionTest method testNewSample.
/**
* Verifies that newSampleData methods consistently insert unitary columns
* in design matrix. Confirms the fix for MATH-411.
*/
@Test
public void testNewSample() {
double[] design = new double[] { 1, 19, 22, 33, 2, 20, 30, 40, 3, 25, 35, 45, 4, 27, 37, 47 };
double[] y = new double[] { 1, 2, 3, 4 };
double[][] x = new double[][] { { 19, 22, 33 }, { 20, 30, 40 }, { 25, 35, 45 }, { 27, 37, 47 } };
AbstractMultipleLinearRegression regression = createRegression();
regression.newSampleData(design, 4, 3, new DenseLocalOnHeapMatrix());
Matrix flatX = regression.getX().copy();
Vector flatY = regression.getY().copy();
regression.newXSampleData(new DenseLocalOnHeapMatrix(x));
regression.newYSampleData(new DenseLocalOnHeapVector(y));
Assert.assertEquals(flatX, regression.getX());
Assert.assertEquals(flatY, regression.getY());
// No intercept
regression.setNoIntercept(true);
regression.newSampleData(design, 4, 3, new DenseLocalOnHeapMatrix());
flatX = regression.getX().copy();
flatY = regression.getY().copy();
regression.newXSampleData(new DenseLocalOnHeapMatrix(x));
regression.newYSampleData(new DenseLocalOnHeapVector(y));
Assert.assertEquals(flatX, regression.getX());
Assert.assertEquals(flatY, regression.getY());
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class CacheVectorTest method testTimesVector.
/** */
public void testTimesVector() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
cacheVector.assign(1d);
Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
try {
cacheVector.times(testVec);
TestCase.fail();
} catch (UnsupportedOperationException ignored) {
}
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class OLSMultipleLinearRegressionTest method testNewSample2.
/**
* Verifies that setting X and Y separately has the same effect as newSample(X,Y).
*/
@Test
public void testNewSample2() {
double[] y = new double[] { 1, 2, 3, 4 };
double[][] x = new double[][] { { 19, 22, 33 }, { 20, 30, 40 }, { 25, 35, 45 }, { 27, 37, 47 } };
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
regression.newSampleData(new DenseLocalOnHeapVector(y), new DenseLocalOnHeapMatrix(x));
Matrix combinedX = regression.getX().copy();
Vector combinedY = regression.getY().copy();
regression.newXSampleData(new DenseLocalOnHeapMatrix(x));
regression.newYSampleData(new DenseLocalOnHeapVector(y));
Assert.assertEquals(combinedX, regression.getX());
Assert.assertEquals(combinedY, regression.getY());
// No intercept
regression.setNoIntercept(true);
regression.newSampleData(new DenseLocalOnHeapVector(y), new DenseLocalOnHeapMatrix(x));
combinedX = regression.getX().copy();
combinedY = regression.getY().copy();
regression.newXSampleData(new DenseLocalOnHeapMatrix(x));
regression.newYSampleData(new DenseLocalOnHeapVector(y));
Assert.assertEquals(combinedX, regression.getX());
Assert.assertEquals(combinedY, regression.getY());
}
Aggregations