Search in sources :

Example 11 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor 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 12 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor 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 13 with Regressor

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

the class IMLGBTrainer method iterate.

public void iterate() {
    for (int k = 0; k < this.boosting.getNumClasses(); k++) {
        if (!shouldStop[k]) {
            if (logger.isDebugEnabled()) {
                logger.debug("updating class " + k);
            }
            /**
                 * parallel by feature
                 */
            Regressor regressor = this.fitClassK(k);
            this.boosting.addRegressor(regressor, k);
            /**
                 * parallel by data
                 */
            this.updateStagedClassScores(regressor, k);
        }
    }
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 14 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor 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 15 with Regressor

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

the class IMLGradientBoosting method predictClassScore.

/**
     *
     * @param vector
     * @param k class index
     * @return
     */
public double predictClassScore(Vector vector, int k) {
    List<Regressor> regressorsClassK = this.regressors.get(k);
    double score = 0;
    for (Regressor regressor : regressorsClassK) {
        score += regressor.predict(vector);
    }
    return score;
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor)

Aggregations

Regressor (edu.neu.ccs.pyramid.regression.Regressor)17 ConstantRegressor (edu.neu.ccs.pyramid.regression.ConstantRegressor)11 PriorProbClassifier (edu.neu.ccs.pyramid.classification.PriorProbClassifier)1 LKBoost (edu.neu.ccs.pyramid.classification.lkboost.LKBoost)1 LabelTranslator (edu.neu.ccs.pyramid.dataset.LabelTranslator)1 Feature (edu.neu.ccs.pyramid.feature.Feature)1 TopFeatures (edu.neu.ccs.pyramid.feature.TopFeatures)1 RegTreeInspector (edu.neu.ccs.pyramid.regression.regression_tree.RegTreeInspector)1 RegressionTree (edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1