Search in sources :

Example 1 with ConstantRegressor

use of edu.neu.ccs.pyramid.regression.ConstantRegressor in project pyramid by cheng-li.

the class LSBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    double average = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToDouble(i -> labels[i] * weights[i]).average().getAsDouble();
    Regressor constant = new ConstantRegressor(average);
    boosting.getEnsemble(0).add(constant);
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 2 with ConstantRegressor

use of edu.neu.ccs.pyramid.regression.ConstantRegressor in project pyramid by cheng-li.

the class PBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    double average = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToDouble(i -> labels[i] * weights[i]).average().getAsDouble();
    Regressor constant = new ConstantRegressor(average);
    boosting.getEnsemble(0).add(constant);
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 3 with ConstantRegressor

use of edu.neu.ccs.pyramid.regression.ConstantRegressor in project pyramid by cheng-li.

the class IMLGradientBoostingTest method test5.

private static void test5() {
    IMLGradientBoosting boosting = new IMLGradientBoosting(2);
    boosting.addRegressor(new ConstantRegressor(1), 0);
    boosting.addRegressor(new ConstantRegressor(-1), 1);
    Vector vector = new DenseVector(2);
    MultiLabel label1 = new MultiLabel().addLabel(0);
    MultiLabel label2 = new MultiLabel().addLabel(1);
    MultiLabel label3 = new MultiLabel();
    MultiLabel label4 = new MultiLabel().addLabel(0).addLabel(1);
    List<MultiLabel> assignments = new ArrayList<>();
    assignments.add(label1);
    assignments.add(label2);
    //        assignments.add(label3);
    //        assignments.add(label4);
    boosting.setAssignments(assignments);
    System.out.println(boosting.predictAssignmentProbWithoutConstraint(vector, label1));
    System.out.println(boosting.predictAssignmentProbWithConstraint(vector, label1));
//        for (MultiLabel multiLabel: boosting.getAssignments()){
//            System.out.println("multilabel = "+multiLabel);
//            System.out.println("prob = "+boosting.predictAssignmentProbWithConstraint(vector,multiLabel));
//        }
}
Also used : ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) DenseVector(org.apache.mahout.math.DenseVector) Vector(org.apache.mahout.math.Vector) DenseVector(org.apache.mahout.math.DenseVector)

Example 4 with ConstantRegressor

use of edu.neu.ccs.pyramid.regression.ConstantRegressor in project pyramid by cheng-li.

the class LKBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    PriorProbClassifier priorProbClassifier = new PriorProbClassifier(numClasses);
    priorProbClassifier.fit(dataSet, targetDistribution, weights);
    double[] probs = priorProbClassifier.getClassProbs();
    double[] scores = MathUtil.inverseSoftMax(probs);
    // weaken the priors
    for (int i = 0; i < scores.length; i++) {
        if (scores[i] > 5) {
            scores[i] = 5;
        }
        if (scores[i] < -5) {
            scores[i] = -5;
        }
    }
    for (int k = 0; k < numClasses; k++) {
        Regressor constant = new ConstantRegressor(scores[k]);
        boosting.getEnsemble(k).add(constant);
    }
}
Also used : PriorProbClassifier(edu.neu.ccs.pyramid.classification.PriorProbClassifier) Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 5 with ConstantRegressor

use of edu.neu.ccs.pyramid.regression.ConstantRegressor in project pyramid by cheng-li.

the class MBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    double median = MathUtil.weightedMedian(labels, weights);
    Regressor constant = new ConstantRegressor(median);
    boosting.getEnsemble(0).add(constant);
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Aggregations

ConstantRegressor (edu.neu.ccs.pyramid.regression.ConstantRegressor)9 Regressor (edu.neu.ccs.pyramid.regression.Regressor)8 PriorProbClassifier (edu.neu.ccs.pyramid.classification.PriorProbClassifier)1 DenseVector (org.apache.mahout.math.DenseVector)1 Vector (org.apache.mahout.math.Vector)1