Search in sources :

Example 6 with RidgeLogisticOptimizer

use of edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer in project pyramid by cheng-li.

the class SparseCBMOptimzer method updateMultiClassLR.

public void updateMultiClassLR() {
    // parallel
    RidgeLogisticOptimizer ridgeLogisticOptimizer = new RidgeLogisticOptimizer((LogisticRegression) cbm.multiClassClassifier, dataSet, gammas, priorVarianceMultiClass, true);
    //TODO maximum iterations
    ridgeLogisticOptimizer.getOptimizer().getTerminator().setMaxIteration(numMulticlassUpdates);
    ridgeLogisticOptimizer.optimize();
}
Also used : RidgeLogisticOptimizer(edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)

Example 7 with RidgeLogisticOptimizer

use of edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer in project pyramid by cheng-li.

the class CBMNoiseOptimizerFixed method updateBinaryLogisticRegression.

private void updateBinaryLogisticRegression(int componentIndex, int labelIndex) {
    RidgeLogisticOptimizer ridgeLogisticOptimizer;
    //        System.out.println("for component "+componentIndex+"  label "+labelIndex);
    //        System.out.println("weights="+Arrays.toString(gammasT[componentIndex]));
    //        System.out.println("binary target distribution="+Arrays.deepToString(binaryTargetsDistributions[labelIndex]));
    //        double posProb = 0;
    //        double negProb = 0;
    //        for (int i=0;i<dataSet.getNumDataPoints();i++){
    //            posProb += gammasT[componentIndex][i] * binaryTargetsDistributions[labelIndex][i][1];
    //            negProb += gammasT[componentIndex][i] * binaryTargetsDistributions[labelIndex][i][0];
    //        }
    //        System.out.println("sum pos prob = "+posProb);
    //        System.out.println("sum neg prob = "+negProb);
    // no parallelism
    ridgeLogisticOptimizer = new RidgeLogisticOptimizer((LogisticRegression) cbm.binaryClassifiers[componentIndex][labelIndex], dataSet, gammasT[componentIndex], binaryTargetsDistributions[labelIndex], priorVarianceBinary, false);
    //TODO maximum iterations
    ridgeLogisticOptimizer.getOptimizer().getTerminator().setMaxIteration(10);
    ridgeLogisticOptimizer.optimize();
//        if (logger.isDebugEnabled()){
//            logger.debug("for cluster "+clusterIndex+" label "+labelIndex+" history= "+ridgeLogisticOptimizer.getOptimizer().getTerminator().getHistory());
//        }
}
Also used : LogisticRegression(edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression) RidgeLogisticOptimizer(edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)

Example 8 with RidgeLogisticOptimizer

use of edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer in project pyramid by cheng-li.

the class NoiseOptimizerLR method updateAlpha.

private void updateAlpha(int classIndex) {
    int numCombination = this.combinations.size();
    // Generate weights for each expanded data point
    double[] weights = new double[dataSet.getNumDataPoints() * numCombination];
    for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
        for (int j = 0; j < numCombination; j++) {
            weights[i * numCombination + j] = targets[i][j];
        }
    }
    // Train weighted logistic regression with l2
    RidgeLogisticOptimizer optimizer = new RidgeLogisticOptimizer(this.lrTransforms.get(classIndex), this.lrDataSet.get(classIndex), weights, this.lrTargets[classIndex], 1000.0, true);
    optimizer.getOptimizer().getTerminator().setMaxIteration(10000).setMode(Terminator.Mode.STANDARD);
    //        System.out.println("after initialization");
    //        System.out.println("train acc = " + Accuracy.accuracy(this.lrTransforms.get(classIndex), this.lrDataSet.get(classIndex)));
    optimizer.optimize();
//        System.out.println("after training");
//        System.out.println("train acc = " + Accuracy.accuracy(this.lrTransforms.get(classIndex), this.lrDataSet.get(classIndex)));
//        System.out.println("classIndex: " + classIndex + ", weights:" + this.lrTransforms.get(classIndex));
}
Also used : RidgeLogisticOptimizer(edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)

Example 9 with RidgeLogisticOptimizer

use of edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer in project pyramid by cheng-li.

the class CBMNoiseOptimizerFixed method updateMultiClassLR.

private void updateMultiClassLR() {
    // parallel
    RidgeLogisticOptimizer ridgeLogisticOptimizer = new RidgeLogisticOptimizer((LogisticRegression) cbm.multiClassClassifier, dataSet, gammas, priorVarianceMultiClass, true);
    //TODO maximum iterations
    ridgeLogisticOptimizer.getOptimizer().getTerminator().setMaxIteration(10);
    ridgeLogisticOptimizer.optimize();
}
Also used : RidgeLogisticOptimizer(edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)

Example 10 with RidgeLogisticOptimizer

use of edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer in project pyramid by cheng-li.

the class CBMUtilityOptimizer method updateBinaryLogisticRegression.

private void updateBinaryLogisticRegression(int componentIndex, int labelIndex) {
    RidgeLogisticOptimizer ridgeLogisticOptimizer;
    //        System.out.println("for component "+componentIndex+"  label "+labelIndex);
    //        System.out.println("weights="+Arrays.toString(gammasT[componentIndex]));
    //        System.out.println("binary target distribution="+Arrays.deepToString(binaryTargetsDistributions[labelIndex]));
    //        double posProb = 0;
    //        double negProb = 0;
    //        for (int i=0;i<dataSet.getNumDataPoints();i++){
    //            posProb += gammasT[componentIndex][i] * binaryTargetsDistributions[labelIndex][i][1];
    //            negProb += gammasT[componentIndex][i] * binaryTargetsDistributions[labelIndex][i][0];
    //        }
    //        System.out.println("sum pos prob = "+posProb);
    //        System.out.println("sum neg prob = "+negProb);
    // no parallelism
    ridgeLogisticOptimizer = new RidgeLogisticOptimizer((LogisticRegression) cbm.binaryClassifiers[componentIndex][labelIndex], dataSet, gammasT[componentIndex], binaryTargetsDistributions[labelIndex], priorVarianceBinary, false);
    //TODO maximum iterations
    ridgeLogisticOptimizer.getOptimizer().getTerminator().setMaxIteration(10);
    ridgeLogisticOptimizer.optimize();
//        if (logger.isDebugEnabled()){
//            logger.debug("for cluster "+clusterIndex+" label "+labelIndex+" history= "+ridgeLogisticOptimizer.getOptimizer().getTerminator().getHistory());
//        }
}
Also used : LogisticRegression(edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression) RidgeLogisticOptimizer(edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)

Aggregations

RidgeLogisticOptimizer (edu.neu.ccs.pyramid.classification.logistic_regression.RidgeLogisticOptimizer)12 LogisticRegression (edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression)4 PriorProbClassifier (edu.neu.ccs.pyramid.classification.PriorProbClassifier)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2