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);
}
}
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);
}
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);
}
}
}
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);
}
}
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;
}
Aggregations