Search in sources :

Example 6 with ConstantRegressor

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

the class HMLGBTrainer method setPriorProbs.

//========================= PRIVATE ==============================
/**
     * not sure whether this is good for performance
     * start with prior probabilities
     * should be called before setTrainConfig
     * @param probs
     */
private void setPriorProbs(double[] probs) {
    if (probs.length != this.boosting.getNumClasses()) {
        throw new IllegalArgumentException("probs.length!=this.numClasses");
    }
    double average = Arrays.stream(probs).map(Math::log).average().getAsDouble();
    for (int k = 0; k < this.boosting.getNumClasses(); k++) {
        double score = Math.log(probs[k] - average);
        Regressor constant = new ConstantRegressor(score);
        this.boosting.addRegressor(constant, k);
    }
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 7 with ConstantRegressor

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

the class LADBoostOptimizer 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)

Example 8 with ConstantRegressor

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

the class IMLGBTrainer method setPriorProbs.

//    public void setActiveFeatures(int[] activeFeatures) {
//        this.config.setActiveFeatures(activeFeatures);
//    }
//
//    public void setActiveDataPoints(int[] activeDataPoints) {
//        this.config.setActiveDataPoints(activeDataPoints);
//    }
//========================== PRIVATE ============================
/**
     * not sure whether this is good for performance
     * start with prior probabilities
     * should be called before setTrainConfig
     * @param probs
     */
private void setPriorProbs(double[] probs) {
    if (probs.length != this.boosting.getNumClasses()) {
        throw new IllegalArgumentException("probs.length!=this.numClasses");
    }
    for (int k = 0; k < this.boosting.getNumClasses(); k++) {
        double score = MathUtil.inverseSigmoid(probs[k]);
        // we don't want the prior to be overly strong
        double soft = Math.sqrt(Math.abs(score));
        if (score < 0) {
            soft = -soft;
        }
        Regressor constant = new ConstantRegressor(soft);
        this.boosting.addRegressor(constant, k);
    }
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 9 with ConstantRegressor

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

the class AdaBoostMHTrainer method setPriorProbs.

private void setPriorProbs(double[] probs) {
    if (probs.length != this.boosting.getNumClasses()) {
        throw new IllegalArgumentException("probs.length!=this.numClasses");
    }
    double average = Arrays.stream(probs).map(Math::log).average().getAsDouble();
    for (int k = 0; k < this.boosting.getNumClasses(); k++) {
        double score = Math.log(probs[k] - average);
        Regressor constant = new ConstantRegressor(score);
        this.boosting.addRegressor(constant, k);
    }
}
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