Search in sources :

Example 6 with DenseVector

use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.

the class Vectors method concatenate.

public static Vector concatenate(Vector vector, Vector vector2) {
    Vector con = null;
    if (vector instanceof DenseVector) {
        con = new DenseVector(vector.size() + vector2.size());
    }
    if (vector instanceof RandomAccessSparseVector) {
        con = new RandomAccessSparseVector(vector.size() + vector2.size());
    }
    if (vector instanceof SequentialAccessSparseVector) {
        con = new SequentialAccessSparseVector(vector.size() + vector2.size());
    }
    for (Vector.Element nonZeros : vector.nonZeroes()) {
        int index = nonZeros.index();
        double value = nonZeros.get();
        con.set(index, value);
    }
    for (Vector.Element nonZeros : vector2.nonZeroes()) {
        int index = nonZeros.index();
        double value = nonZeros.get();
        con.set(index + vector.size(), value);
    }
    return con;
}
Also used : RandomAccessSparseVector(org.apache.mahout.math.RandomAccessSparseVector) DenseVector(org.apache.mahout.math.DenseVector) RandomAccessSparseVector(org.apache.mahout.math.RandomAccessSparseVector) SequentialAccessSparseVector(org.apache.mahout.math.SequentialAccessSparseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector) SequentialAccessSparseVector(org.apache.mahout.math.SequentialAccessSparseVector)

Example 7 with DenseVector

use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.

the class Vectors method concatenate.

public static Vector concatenate(Vector vector, double[] numbers) {
    Vector con = null;
    if (vector instanceof DenseVector) {
        con = new DenseVector(vector.size() + numbers.length);
    }
    if (vector instanceof RandomAccessSparseVector) {
        con = new RandomAccessSparseVector(vector.size() + numbers.length);
    }
    if (vector instanceof SequentialAccessSparseVector) {
        con = new SequentialAccessSparseVector(vector.size() + numbers.length);
    }
    for (Vector.Element nonZeros : vector.nonZeroes()) {
        int index = nonZeros.index();
        double value = nonZeros.get();
        con.set(index, value);
    }
    for (int i = 0; i < numbers.length; i++) {
        con.set(i + vector.size(), numbers[i]);
    }
    return con;
}
Also used : RandomAccessSparseVector(org.apache.mahout.math.RandomAccessSparseVector) DenseVector(org.apache.mahout.math.DenseVector) RandomAccessSparseVector(org.apache.mahout.math.RandomAccessSparseVector) SequentialAccessSparseVector(org.apache.mahout.math.SequentialAccessSparseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector) SequentialAccessSparseVector(org.apache.mahout.math.SequentialAccessSparseVector)

Example 8 with DenseVector

use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.

the class FusedKolmogorovFilter method generateInputsEachClass.

public List<List<Double>> generateInputsEachClass(Vector vector, int[] labels, int numClasses) {
    Vector input;
    if (vector.isDense()) {
        input = vector;
    } else {
        input = new DenseVector(vector);
    }
    List<List<Double>> inputsEachClass = new ArrayList<>();
    for (int k = 0; k < numClasses; k++) {
        inputsEachClass.add(new ArrayList<>());
    }
    for (int i = 0; i < labels.length; i++) {
        int label = labels[i];
        inputsEachClass.get(label).add(input.get(i));
    }
    return inputsEachClass;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 9 with DenseVector

use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.

the class MLACPlattScaling method predictClassProbs.

@Override
public double[] predictClassProbs(Vector vector) {
    double[] scores = scoreEstimator.predictClassScores(vector);
    Vector scoreVector = new DenseVector(scores.length);
    for (int i = 0; i < scores.length; i++) {
        scoreVector.set(i, scores[i]);
    }
    return this.logisticRegression.predictClassProbs(scoreVector);
}
Also used : DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 10 with DenseVector

use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.

the class MLPlattScaling method predictClassProb.

@Override
public double predictClassProb(Vector vector, int classIndex) {
    double score = scoreEstimator.predictClassScore(vector, classIndex);
    Vector scoreVector = new DenseVector(1);
    scoreVector.set(0, score);
    return logisticRegressions.get(classIndex).predictClassProb(scoreVector, 1);
}
Also used : DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Aggregations

DenseVector (org.apache.mahout.math.DenseVector)79 Vector (org.apache.mahout.math.Vector)73 MultiLabel (edu.neu.ccs.pyramid.dataset.MultiLabel)9 RandomAccessSparseVector (org.apache.mahout.math.RandomAccessSparseVector)8 MultiLabelClfDataSet (edu.neu.ccs.pyramid.dataset.MultiLabelClfDataSet)7 SequentialAccessSparseVector (org.apache.mahout.math.SequentialAccessSparseVector)6 Pair (edu.neu.ccs.pyramid.util.Pair)4 List (java.util.List)3 IntStream (java.util.stream.IntStream)3 EnumeratedIntegerDistribution (org.apache.commons.math3.distribution.EnumeratedIntegerDistribution)3 LogisticRegression (edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression)2 DataSet (edu.neu.ccs.pyramid.dataset.DataSet)2 EmpiricalCDF (edu.neu.ccs.pyramid.util.EmpiricalCDF)2 IntegerDistribution (org.apache.commons.math3.distribution.IntegerDistribution)2 MultivariateNormalDistribution (org.apache.commons.math3.distribution.MultivariateNormalDistribution)2 Classifier (edu.neu.ccs.pyramid.classification.Classifier)1 Weights (edu.neu.ccs.pyramid.classification.logistic_regression.Weights)1 RegDataSet (edu.neu.ccs.pyramid.dataset.RegDataSet)1 ConstantRegressor (edu.neu.ccs.pyramid.regression.ConstantRegressor)1 BernoulliDistribution (edu.neu.ccs.pyramid.util.BernoulliDistribution)1