Search in sources :

Example 11 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class Blas method syr.

/**
 * A := alpha * x * x^T + A.
 *
 * @param alpha a real scalar that will be multiplied to x * x^T^.
 * @param x the vector x that contains the n elements.
 * @param a the symmetric matrix A. Size of n x n.
 */
void syr(Double alpha, Vector x, DenseMatrix a) {
    int mA = a.rowSize();
    int nA = a.columnSize();
    if (mA != nA)
        throw new NonSquareMatrixException(mA, nA);
    if (mA != x.size())
        throw new CardinalityException(x.size(), mA);
    // TODO: IGNITE-5535, Process DenseLocalOffHeapVector
    if (x instanceof DenseVector)
        syr(alpha, x, a);
    else if (x instanceof SparseVector)
        syr(alpha, x, a);
    else
        throw new IllegalArgumentException("Operation 'syr' does not support vector [class=" + x.getClass().getName() + "].");
}
Also used : NonSquareMatrixException(org.apache.ignite.ml.math.exceptions.math.NonSquareMatrixException) CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException) SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) MathIllegalArgumentException(org.apache.ignite.ml.math.exceptions.math.MathIllegalArgumentException)

Example 12 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class AbstractMatrix method getCol.

/**
 * {@inheritDoc}
 */
@Override
public Vector getCol(int col) {
    checkColumnIndex(col);
    Vector res;
    res = new DenseVector(rowSize());
    for (int i = 0; i < rowSize(); i++) res.setX(i, getX(i, col));
    return res;
}
Also used : Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 13 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class AbstractMatrix method getRow.

/**
 * {@inheritDoc}
 */
@Override
public Vector getRow(int row) {
    checkRowIndex(row);
    Vector res = new DenseVector(columnSize());
    for (int i = 0; i < columnSize(); i++) res.setX(i, getX(row, i));
    return res;
}
Also used : Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 14 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class LocalModelsTest method importExportLinearRegressionModelTest.

/**
 */
@Test
public void importExportLinearRegressionModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        LinearRegressionModel mdl = new LinearRegressionModel(new DenseVector(new double[] { 1, 2 }), 3);
        Exporter<LinearRegressionModel, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        LinearRegressionModel load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        Assert.assertEquals("", mdl, load);
        return null;
    });
}
Also used : LinearRegressionModel(org.apache.ignite.ml.regressions.linear.LinearRegressionModel) FileExporter(org.apache.ignite.ml.FileExporter) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Example 15 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class LocalModelsTest method importExportLogisticRegressionModelTest.

/**
 */
@Test
public void importExportLogisticRegressionModelTest() throws IOException {
    executeModelTest(mdlFilePath -> {
        LogisticRegressionModel mdl = new LogisticRegressionModel(new DenseVector(new double[] { 1, 2 }), 3);
        Exporter<LogisticRegressionModel, String> exporter = new FileExporter<>();
        mdl.saveModel(exporter, mdlFilePath);
        LogisticRegressionModel load = exporter.load(mdlFilePath);
        Assert.assertNotNull(load);
        Assert.assertEquals("", mdl, load);
        return null;
    });
}
Also used : FileExporter(org.apache.ignite.ml.FileExporter) LogisticRegressionModel(org.apache.ignite.ml.regressions.logistic.LogisticRegressionModel) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Aggregations

DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)101 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)59 Test (org.junit.Test)59 Serializable (java.io.Serializable)16 SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)14 HashMap (java.util.HashMap)13 DenseMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix)13 DummyVectorizer (org.apache.ignite.ml.dataset.feature.extractor.impl.DummyVectorizer)10 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)10 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 HashSet (java.util.HashSet)7 TrainerTest (org.apache.ignite.ml.common.TrainerTest)7 KMeansModel (org.apache.ignite.ml.clustering.kmeans.KMeansModel)5 LocalDatasetBuilder (org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder)5 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)5 IgniteDifferentiableVectorToDoubleFunction (org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction)5 MLPArchitecture (org.apache.ignite.ml.nn.architecture.MLPArchitecture)5 OneHotEncoderPreprocessor (org.apache.ignite.ml.preprocessing.encoding.onehotencoder.OneHotEncoderPreprocessor)4 Random (java.util.Random)3