Search in sources :

Example 16 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class EigenDecompositionTest method assertEigenvalues.

/** */
private void assertEigenvalues(EigenDecomposition decomposition, double[] expRealEigenValues) {
    Vector real = decomposition.getRealEigenValues();
    Vector imag = decomposition.getImagEigenvalues();
    assertEquals("Real values size differs from expected.", expRealEigenValues.length, real.size());
    assertEquals("Imag values size differs from expected.", expRealEigenValues.length, imag.size());
    for (int idx = 0; idx < expRealEigenValues.length; idx++) {
        assertEquals("Real eigen value differs from expected at " + idx, expRealEigenValues[idx], real.get(idx), 0d);
        assertEquals("Imag eigen value differs from expected at " + idx, 0d, imag.get(idx), 0d);
    }
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 17 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class AbstractVector method minus.

/** {@inheritDoc} */
@Override
public Vector minus(Vector vec) {
    checkCardinality(vec);
    Vector cp = copy();
    return cp.map(vec, Functions.MINUS);
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 18 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class AbstractMatrix method foldColumns.

/** {@inheritDoc} */
@Override
public Vector foldColumns(IgniteFunction<Vector, Double> fun) {
    int cols = columnSize();
    Vector vec = likeVector(cols);
    for (int i = 0; i < cols; i++) vec.setX(i, fun.apply(viewColumn(i)));
    return vec;
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 19 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class VectorExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     */
public static void main(String[] args) {
    System.out.println();
    System.out.println(">>> Basic Vector API usage example started.");
    System.out.println("\n>>> Creating perpendicular vectors.");
    double[] data1 = new double[] { 1, 0, 3, 0, 5, 0 };
    double[] data2 = new double[] { 0, 2, 0, 4, 0, 6 };
    Vector v1 = new DenseLocalOnHeapVector(data1);
    Vector v2 = new DenseLocalOnHeapVector(data2);
    System.out.println(">>> First vector: " + Arrays.toString(data1));
    System.out.println(">>> Second vector: " + Arrays.toString(data2));
    double dotProduct = v1.dot(v2);
    boolean dotProductIsAsExp = dotProduct == 0;
    System.out.println("\n>>> Dot product of vectors: [" + dotProduct + "], it is 0 as expected: [" + dotProductIsAsExp + "].");
    Vector hypotenuse = v1.plus(v2);
    System.out.println("\n>>> Hypotenuse (sum of vectors): " + Arrays.toString(hypotenuse.getStorage().data()));
    double lenSquared1 = v1.getLengthSquared();
    double lenSquared2 = v2.getLengthSquared();
    double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
    boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
    System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
    System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
    System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse + "], equals sum of squared lengths of two original vectors as expected: [" + lenSquaredHypotenuseIsAsExp + "].");
    System.out.println("\n>>> Basic Vector API usage example completed.");
}
Also used : 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)

Example 20 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class SparseVectorExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     */
public static void main(String[] args) {
    System.out.println();
    System.out.println(">>> Sparse vector API usage example started.");
    System.out.println("\n>>> Creating perpendicular sparse vectors.");
    double[] data1 = new double[] { 1, 0, 3, 0, 5, 0 };
    double[] data2 = new double[] { 0, 2, 0, 4, 0, 6 };
    Vector v1 = new SparseLocalVector(data1.length, RANDOM_ACCESS_MODE);
    Vector v2 = new SparseLocalVector(data2.length, RANDOM_ACCESS_MODE);
    v1.assign(data1);
    v2.assign(data2);
    System.out.println(">>> First vector: " + Arrays.toString(data1));
    System.out.println(">>> Second vector: " + Arrays.toString(data2));
    double dotProduct = v1.dot(v2);
    boolean dotProductIsAsExp = dotProduct == 0;
    System.out.println("\n>>> Dot product of vectors: [" + dotProduct + "], it is 0 as expected: [" + dotProductIsAsExp + "].");
    Vector hypotenuse = v1.plus(v2);
    System.out.println("\n>>> Hypotenuse (sum of vectors): " + Arrays.toString(hypotenuse.getStorage().data()));
    double lenSquared1 = v1.getLengthSquared();
    double lenSquared2 = v2.getLengthSquared();
    double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
    boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
    System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
    System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
    System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse + "], equals sum of squared lengths of two original vectors as expected: [" + lenSquaredHypotenuseIsAsExp + "].");
    System.out.println("\n>>> Sparse vector API usage example completed.");
}
Also used : Vector(org.apache.ignite.ml.math.Vector) SparseLocalVector(org.apache.ignite.ml.math.impls.vector.SparseLocalVector) SparseLocalVector(org.apache.ignite.ml.math.impls.vector.SparseLocalVector)

Aggregations

Vector (org.apache.ignite.ml.math.Vector)44 Test (org.junit.Test)17 DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)13 DenseLocalOffHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector)7 IdentityValueMapper (org.apache.ignite.ml.math.IdentityValueMapper)5 Matrix (org.apache.ignite.ml.math.Matrix)5 UnsupportedOperationException (org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)5 SparseLocalVector (org.apache.ignite.ml.math.impls.vector.SparseLocalVector)5 ExternalizeTest (org.apache.ignite.ml.math.ExternalizeTest)4 RandomVector (org.apache.ignite.ml.math.impls.vector.RandomVector)4 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)3 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 CardinalityException (org.apache.ignite.ml.math.exceptions.CardinalityException)1 PivotedMatrixView (org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView)1 SparseDistributedMatrix (org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix)1 AbstractVector (org.apache.ignite.ml.math.impls.vector.AbstractVector)1 MatrixUtil.likeVector (org.apache.ignite.ml.math.util.MatrixUtil.likeVector)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Assert.assertFalse (org.junit.Assert.assertFalse)1