Search in sources :

Example 11 with DenseLocalOnHeapVector

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

the class IgniteColumnDecisionTreeGiniBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
    // because we create ignite cache internally.
    IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), this.getClass().getSimpleName(), new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            // IMPL NOTE originally taken from ColumnDecisionTreeTrainerTest#testCacheMixedGini
            int totalPts = 1 << 10;
            int featCnt = 2;
            HashMap<Integer, Integer> catsInfo = new HashMap<>();
            catsInfo.put(1, 3);
            SplitDataGenerator<DenseLocalOnHeapVector> gen = new SplitDataGenerator<>(featCnt, catsInfo, () -> new DenseLocalOnHeapVector(featCnt + 1)).split(0, 1, new int[] { 0, 2 }).split(1, 0, -10.0);
            gen.testByGen(totalPts, ContinuousSplitCalculators.GINI.apply(ignite), RegionCalculators.GINI, RegionCalculators.MEAN, ignite);
        }
    });
    igniteThread.start();
    igniteThread.join();
    return true;
}
Also used : HashMap(java.util.HashMap) IgniteThread(org.apache.ignite.thread.IgniteThread) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)

Example 12 with DenseLocalOnHeapVector

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

the class IgniteColumnDecisionTreeVarianceBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
    // because we create ignite cache internally.
    IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), this.getClass().getSimpleName(), new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            // IMPL NOTE originally taken from ColumnDecisionTreeTrainerTest#testCacheMixed
            int totalPts = 1 << 10;
            int featCnt = 2;
            HashMap<Integer, Integer> catsInfo = new HashMap<>();
            catsInfo.put(1, 3);
            SplitDataGenerator<DenseLocalOnHeapVector> gen = new SplitDataGenerator<>(featCnt, catsInfo, () -> new DenseLocalOnHeapVector(featCnt + 1)).split(0, 1, new int[] { 0, 2 }).split(1, 0, -10.0);
            gen.testByGen(totalPts, ContinuousSplitCalculators.VARIANCE, RegionCalculators.VARIANCE, RegionCalculators.MEAN, ignite);
        }
    });
    igniteThread.start();
    igniteThread.join();
    return true;
}
Also used : HashMap(java.util.HashMap) IgniteThread(org.apache.ignite.thread.IgniteThread) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)

Example 13 with DenseLocalOnHeapVector

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

the class AbstractMatrix method getRow.

/**
 * {@inheritDoc}
 */
@Override
public Vector getRow(int row) {
    checkRowIndex(row);
    Vector res = new DenseLocalOnHeapVector(columnSize());
    for (int i = 0; i < columnSize(); i++) res.setX(i, getX(row, i));
    return res;
}
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 14 with DenseLocalOnHeapVector

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

the class MultilayerPerceptron method paramsAsVector.

/**
 * Flatten this MLP parameters as vector.
 *
 * @param layersParams List of layers parameters.
 * @return This MLP parameters as vector.
 */
protected Vector paramsAsVector(List<MLPLayer> layersParams) {
    int off = 0;
    Vector res = new DenseLocalOnHeapVector(architecture().parametersCount());
    for (MLPLayer layerParams : layersParams) {
        off = writeToVector(res, layerParams.weights, off);
        if (layerParams.biases != null)
            off = writeToVector(res, layerParams.biases, off);
    }
    return res;
}
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 15 with DenseLocalOnHeapVector

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

the class MultilayerPerceptron method initLayers.

/**
 * Init layers parameters with initializer.
 *
 * @param initializer Parameters initializer.
 */
private void initLayers(MLPInitializer initializer) {
    int prevSize = architecture.inputSize();
    for (int i = 1; i < architecture.layersCount(); i++) {
        TransformationLayerArchitecture layerCfg = architecture.transformationLayerArchitecture(i);
        int neuronsCnt = layerCfg.neuronsCount();
        DenseLocalOnHeapMatrix weights = new DenseLocalOnHeapMatrix(neuronsCnt, prevSize);
        initializer.initWeights(weights);
        DenseLocalOnHeapVector biases = null;
        if (layerCfg.hasBias()) {
            biases = new DenseLocalOnHeapVector(neuronsCnt);
            initializer.initBiases(biases);
        }
        layers.add(new MLPLayer(weights, biases));
        prevSize = layerCfg.neuronsCount();
    }
}
Also used : DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) TransformationLayerArchitecture(org.apache.ignite.ml.nn.architecture.TransformationLayerArchitecture)

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