Search in sources :

Example 71 with DenseVector

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

the class CBMInspector method distanceFromMean.

public static double distanceFromMean(CBM bmm, int label) {
    Classifier.ProbabilityEstimator[][] logistics = bmm.getBinaryClassifiers();
    int numClusters = bmm.getNumComponents();
    int numFeatures = ((LogisticRegression) logistics[0][0]).getNumFeatures();
    Vector positiveAverageVector = new DenseVector(numFeatures);
    for (int k = 0; k < numClusters; k++) {
        Vector positiveVector = ((LogisticRegression) logistics[k][label]).getWeights().getWeightsWithoutBiasForClass(1);
        positiveAverageVector = positiveAverageVector.plus(positiveVector);
    }
    positiveAverageVector = positiveAverageVector.divide(numClusters);
    double dis = 0;
    for (int k = 0; k < numClusters; k++) {
        Vector positiveVector = ((LogisticRegression) logistics[k][label]).getWeights().getWeightsWithoutBiasForClass(1);
        dis += positiveVector.minus(positiveAverageVector).norm(2);
    }
    return dis / numClusters;
}
Also used : Classifier(edu.neu.ccs.pyramid.classification.Classifier) LogisticRegression(edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression) DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 72 with DenseVector

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

the class CBMInspector method getMean.

public static Weights getMean(CBM bmm, int label) {
    int numClusters = bmm.getNumComponents();
    int length = ((LogisticRegression) bmm.getBinaryClassifiers()[0][0]).getWeights().getAllWeights().size();
    int numFeatures = ((LogisticRegression) bmm.getBinaryClassifiers()[0][0]).getNumFeatures();
    Vector mean = new DenseVector(length);
    for (int k = 0; k < numClusters; k++) {
        mean = mean.plus(((LogisticRegression) bmm.getBinaryClassifiers()[k][label]).getWeights().getAllWeights());
    }
    mean = mean.divide(numClusters);
    return new Weights(2, numFeatures, mean);
}
Also used : Weights(edu.neu.ccs.pyramid.classification.logistic_regression.Weights) LogisticRegression(edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression) DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 73 with DenseVector

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

the class MLFlatScaling method predictClassProbs.

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

Example 74 with DenseVector

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

the class AugmentedLRLoss method penaltyGradient.

private Vector penaltyGradient() {
    Vector featureWeights = augmentedLR.featureWeights();
    Vector componentWeights = augmentedLR.componentWeights();
    Vector penaltyGradient = new DenseVector(augmentedLR.getAllWeights().size());
    for (int d = 0; d < numFeatures; d++) {
        penaltyGradient.set(d, featureWeights.get(d) / featureWeightVariance);
    }
    for (int k = 0; k < numComponents; k++) {
        penaltyGradient.set(numFeatures + k, componentWeights.get(k) / componentWeightVariance);
    }
    return penaltyGradient;
}
Also used : DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 75 with DenseVector

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

the class MLACPlattScaling method predictAssignmentProb.

@Override
public double predictAssignmentProb(Vector vector, MultiLabel assignment) {
    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 logisticRegression.predictAssignmentProb(scoreVector, assignment);
}
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