Search in sources :

Example 1 with LKBoost

use of edu.neu.ccs.pyramid.classification.lkboost.LKBoost in project pyramid by cheng-li.

the class GBClassifier method test.

private static void test(Config config) throws Exception {
    String output = config.getString("output.folder");
    File serializedModel = new File(output, "model");
    LKBoost lkBoost = (LKBoost) Serialization.deserialize(serializedModel);
    String sparsity = config.getString("input.matrixType");
    DataSetType dataSetType = null;
    switch(sparsity) {
        case "dense":
            dataSetType = DataSetType.CLF_DENSE;
            break;
        case "sparse":
            dataSetType = DataSetType.CLF_SPARSE;
            break;
        default:
            throw new IllegalArgumentException("input.matrixType should be dense or sparse");
    }
    ClfDataSet testSet = TRECFormat.loadClfDataSet(config.getString("input.testData"), dataSetType, true);
    System.out.println("test accuracy = " + Accuracy.accuracy(lkBoost, testSet));
    File reportFile = new File(output, "test_predictions.txt");
    report(lkBoost, testSet, reportFile);
    System.out.println("predictions on the test set are written to " + reportFile.getAbsolutePath());
    File probabilitiesFile = new File(output, "test_predicted_probabilities.txt");
    probabilities(lkBoost, testSet, probabilitiesFile);
    System.out.println("predicted probabilities on the test set are written to " + probabilitiesFile.getAbsolutePath());
}
Also used : DataSetType(edu.neu.ccs.pyramid.dataset.DataSetType) ClfDataSet(edu.neu.ccs.pyramid.dataset.ClfDataSet) File(java.io.File) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost)

Example 2 with LKBoost

use of edu.neu.ccs.pyramid.classification.lkboost.LKBoost in project pyramid by cheng-li.

the class SparkCBMOptimizer method updateMultiClassBoost.

private void updateMultiClassBoost() {
    int numComponents = cbm.numComponents;
    int numIterations = numIterationsMultiClass;
    double shrinkage = shrinkageMultiClass;
    LKBoost boost = (LKBoost) this.cbm.multiClassClassifier;
    RegTreeConfig regTreeConfig = new RegTreeConfig().setMaxNumLeaves(numLeavesMultiClass);
    RegTreeFactory regTreeFactory = new RegTreeFactory(regTreeConfig);
    regTreeFactory.setLeafOutputCalculator(new LKBOutputCalculator(numComponents));
    LKBoostOptimizer optimizer = new LKBoostOptimizer(boost, dataSet, regTreeFactory, gammas);
    optimizer.setShrinkage(shrinkage);
    optimizer.initialize();
    optimizer.iterate(numIterations);
}
Also used : LKBoostOptimizer(edu.neu.ccs.pyramid.classification.lkboost.LKBoostOptimizer) RegTreeConfig(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeConfig) RegTreeFactory(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeFactory) LKBOutputCalculator(edu.neu.ccs.pyramid.classification.lkboost.LKBOutputCalculator) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost)

Example 3 with LKBoost

use of edu.neu.ccs.pyramid.classification.lkboost.LKBoost in project pyramid by cheng-li.

the class GBCBMOptimizer method updateMultiClassClassifier.

@Override
protected void updateMultiClassClassifier() {
    if (logger.isDebugEnabled()) {
        logger.debug("start updateMultiClassClassifier");
    }
    // parallel
    LKBoost boost = (LKBoost) this.cbm.multiClassClassifier;
    RegTreeConfig regTreeConfig = new RegTreeConfig().setMaxNumLeaves(numLeaves);
    RegTreeFactory regTreeFactory = new RegTreeFactory(regTreeConfig);
    regTreeFactory.setLeafOutputCalculator(new LKBOutputCalculator(cbm.getNumComponents()));
    LKBoostOptimizer optimizer = new LKBoostOptimizer(boost, dataSet, regTreeFactory, gammas);
    optimizer.setShrinkage(shrinkage);
    optimizer.initialize();
    optimizer.iterate(multiclassUpdatesPerIter);
    if (logger.isDebugEnabled()) {
        logger.debug("finish updateMultiClassClassifier");
    }
}
Also used : LKBoostOptimizer(edu.neu.ccs.pyramid.classification.lkboost.LKBoostOptimizer) RegTreeConfig(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeConfig) RegTreeFactory(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeFactory) LKBOutputCalculator(edu.neu.ccs.pyramid.classification.lkboost.LKBOutputCalculator) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost)

Example 4 with LKBoost

use of edu.neu.ccs.pyramid.classification.lkboost.LKBoost in project pyramid by cheng-li.

the class CBMUtilityOptimizer method updateMultiClassBoost.

private void updateMultiClassBoost() {
    int numComponents = cbm.numComponents;
    int numIterations = numIterationsMultiClass;
    double shrinkage = shrinkageMultiClass;
    LKBoost boost = (LKBoost) this.cbm.multiClassClassifier;
    RegTreeConfig regTreeConfig = new RegTreeConfig().setMaxNumLeaves(numLeavesMultiClass);
    RegTreeFactory regTreeFactory = new RegTreeFactory(regTreeConfig);
    regTreeFactory.setLeafOutputCalculator(new LKBOutputCalculator(numComponents));
    LKBoostOptimizer optimizer = new LKBoostOptimizer(boost, dataSet, regTreeFactory, gammas);
    optimizer.setShrinkage(shrinkage);
    optimizer.initialize();
    optimizer.iterate(numIterations);
}
Also used : LKBoostOptimizer(edu.neu.ccs.pyramid.classification.lkboost.LKBoostOptimizer) RegTreeConfig(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeConfig) RegTreeFactory(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeFactory) LKBOutputCalculator(edu.neu.ccs.pyramid.classification.lkboost.LKBOutputCalculator) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost)

Example 5 with LKBoost

use of edu.neu.ccs.pyramid.classification.lkboost.LKBoost in project pyramid by cheng-li.

the class CBMUtilityOptimizer method updateBinaryBoosting.

private void updateBinaryBoosting(int componentIndex, int labelIndex) {
    int numIterations = numIterationsBinary;
    double shrinkage = shrinkageBinary;
    LKBoost boost = (LKBoost) this.cbm.binaryClassifiers[componentIndex][labelIndex];
    RegTreeConfig regTreeConfig = new RegTreeConfig().setMaxNumLeaves(numLeavesBinary);
    RegTreeFactory regTreeFactory = new RegTreeFactory(regTreeConfig);
    regTreeFactory.setLeafOutputCalculator(new LKBOutputCalculator(2));
    LKBoostOptimizer optimizer = new LKBoostOptimizer(boost, dataSet, regTreeFactory, gammasT[componentIndex], binaryTargetsDistributions[labelIndex]);
    optimizer.setShrinkage(shrinkage);
    optimizer.initialize();
    optimizer.iterate(numIterations);
}
Also used : LKBoostOptimizer(edu.neu.ccs.pyramid.classification.lkboost.LKBoostOptimizer) RegTreeConfig(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeConfig) RegTreeFactory(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeFactory) LKBOutputCalculator(edu.neu.ccs.pyramid.classification.lkboost.LKBOutputCalculator) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost)

Aggregations

LKBoost (edu.neu.ccs.pyramid.classification.lkboost.LKBoost)11 LKBOutputCalculator (edu.neu.ccs.pyramid.classification.lkboost.LKBOutputCalculator)10 LKBoostOptimizer (edu.neu.ccs.pyramid.classification.lkboost.LKBoostOptimizer)10 RegTreeConfig (edu.neu.ccs.pyramid.regression.regression_tree.RegTreeConfig)10 RegTreeFactory (edu.neu.ccs.pyramid.regression.regression_tree.RegTreeFactory)10 ClfDataSet (edu.neu.ccs.pyramid.dataset.ClfDataSet)2 DataSetType (edu.neu.ccs.pyramid.dataset.DataSetType)2 File (java.io.File)2 PriorProbClassifier (edu.neu.ccs.pyramid.classification.PriorProbClassifier)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1