Search in sources :

Example 81 with MultiLabel

use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.

the class MacroMeasuresTest method main.

public static void main(String[] args) {
    MultiLabel[] labels = new MultiLabel[6];
    MultiLabel[] predictions = new MultiLabel[6];
    labels[0] = new MultiLabel();
    labels[1] = new MultiLabel();
    labels[2] = new MultiLabel();
    labels[3] = new MultiLabel();
    labels[4] = new MultiLabel();
    labels[5] = new MultiLabel();
    predictions[0] = new MultiLabel();
    predictions[1] = new MultiLabel();
    predictions[2] = new MultiLabel();
    predictions[3] = new MultiLabel();
    predictions[4] = new MultiLabel();
    predictions[5] = new MultiLabel();
    labels[0].addLabel(0);
    labels[1].addLabel(1);
    labels[2].addLabel(2);
    labels[3].addLabel(0);
    labels[4].addLabel(1);
    labels[5].addLabel(2);
    predictions[0].addLabel(0);
    predictions[1].addLabel(2);
    predictions[2].addLabel(1);
    predictions[3].addLabel(0);
    predictions[4].addLabel(0);
    predictions[5].addLabel(1);
    MacroMeasures macroMeasures = new MacroMeasures(3);
    macroMeasures.update(labels, predictions);
    System.out.println("Expected Macro-Precision: 0.22222222222222221");
    System.out.println("Expected Macro-Recall: 0.33333333333333331");
    System.out.println("Expected Macro-F1: 0.26666666666666666");
    System.out.println(macroMeasures);
    System.out.println("Expected Macro-F-Beta=0.5: 0.23809523809523805");
    System.out.println("Macro-FBeta=0.5: " + macroMeasures.getFScore(0.5));
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel)

Example 82 with MultiLabel

use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.

the class MicroMeasuresTest method main.

public static void main(String[] args) {
    MultiLabel[] labels = new MultiLabel[6];
    MultiLabel[] predictions = new MultiLabel[6];
    labels[0] = new MultiLabel();
    labels[1] = new MultiLabel();
    labels[2] = new MultiLabel();
    labels[3] = new MultiLabel();
    labels[4] = new MultiLabel();
    labels[5] = new MultiLabel();
    predictions[0] = new MultiLabel();
    predictions[1] = new MultiLabel();
    predictions[2] = new MultiLabel();
    predictions[3] = new MultiLabel();
    predictions[4] = new MultiLabel();
    predictions[5] = new MultiLabel();
    labels[0].addLabel(0);
    labels[1].addLabel(1);
    labels[2].addLabel(2);
    labels[3].addLabel(0);
    labels[4].addLabel(1);
    labels[5].addLabel(2);
    predictions[0].addLabel(0);
    predictions[1].addLabel(2);
    predictions[2].addLabel(1);
    predictions[3].addLabel(0);
    predictions[4].addLabel(0);
    predictions[5].addLabel(1);
    MicroMeasures microMeasures = new MicroMeasures(3);
    microMeasures.update(labels, predictions);
    System.out.println("Expected Micro-Precision: 0.33333333333333331");
    System.out.println("Expected Micro-Recall: 0.33333333333333331");
    System.out.println("Expected Micro-F1: .33333333333333331");
    System.out.println(microMeasures);
    System.out.println("Expected Macro-F-Beta=0.5: 0.33333333333333331");
    System.out.println("Micro-FBeta=0.5: " + microMeasures.getFScore(0.5));
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel)

Example 83 with MultiLabel

use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.

the class AccuracyMLTest method main.

public static void main(String[] args) {
    MultiLabel[] labels = new MultiLabel[1];
    MultiLabel[] predictions = new MultiLabel[1];
    labels[0] = new MultiLabel();
    labels[0].addLabel(0);
    labels[0].addLabel(1);
    predictions[0] = new MultiLabel();
    predictions[0].addLabel(0);
    predictions[0].addLabel(1);
    System.out.println("Expected: (value=1.0) - Output: " + Accuracy.accuracy(labels, predictions));
    predictions[0].addLabel(2);
    System.out.println("Expected: (value=0.0) - Output:" + Accuracy.accuracy(labels, predictions));
    int labelLength = 1000;
    MultiLabel[] labels1 = new MultiLabel[labelLength];
    MultiLabel[] predictions1 = new MultiLabel[labelLength];
    for (int i = 0; i < labelLength; i++) {
        labels1[i] = new MultiLabel();
        predictions1[i] = new MultiLabel();
        labels1[i].addLabel(1);
        labels1[i].addLabel(2);
        predictions1[i].addLabel(1);
        predictions1[i].addLabel(2);
    }
    System.out.println("Expected: (value=1.0) - Output: " + Accuracy.accuracy(labels1, predictions1));
    MultiLabel[] labels2 = new MultiLabel[labelLength];
    MultiLabel[] predictions2 = new MultiLabel[labelLength];
    for (int i = 0; i < labelLength; i++) {
        labels2[i] = new MultiLabel();
        predictions2[i] = new MultiLabel();
        labels2[i].addLabel(0);
        predictions2[i].addLabel(0);
    }
    System.out.println("Expected: (value=1.0) - Output: " + Accuracy.accuracy(labels2, predictions2));
    MultiLabel[] labels3 = new MultiLabel[labelLength];
    MultiLabel[] predictions3 = new MultiLabel[labelLength];
    for (int i = 0; i < labelLength; i++) {
        labels3[i] = new MultiLabel();
        predictions3[i] = new MultiLabel();
    }
    System.out.println("Expected: (value=1.0) - Output: " + Accuracy.accuracy(labels3, predictions3));
    MultiLabel[] labels4 = new MultiLabel[labelLength];
    MultiLabel[] predictions4 = new MultiLabel[labelLength];
    for (int i = 0; i < labelLength; i++) {
        labels4[i] = new MultiLabel();
        predictions4[i] = new MultiLabel();
        if (i < labelLength / 2) {
            labels4[i].addLabel(0);
            labels4[i].addLabel(1);
            predictions4[i].addLabel(1);
            predictions4[i].addLabel(0);
        } else {
            labels4[i].addLabel(0);
            predictions4[i].addLabel(1);
        }
    }
    System.out.println("Expected: (value=0.5) - Output: " + Accuracy.accuracy(labels4, predictions4));
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel)

Example 84 with MultiLabel

use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.

the class PluginF1 method predictBySampling.

private MultiLabel predictBySampling(Vector vector) {
    List<MultiLabel> samples = cbm.samples(vector, numSamples);
    GeneralF1Predictor generalF1Predictor = new GeneralF1Predictor();
    generalF1Predictor.setMaxSize(maxSize);
    return generalF1Predictor.predict(cbm.getNumClasses(), samples);
//      unique the sample set and apply GFM
//        List<MultiLabel> uniqueSamples = new ArrayList(new HashSet(samples));
//        List<Double> probs = cbm.predictAssignmentProbs(vector, uniqueSamples);
//        return GeneralF1Predictor.predict(cbm.getNumClasses(), uniqueSamples, probs);
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel) GeneralF1Predictor(edu.neu.ccs.pyramid.multilabel_classification.plugin_rule.GeneralF1Predictor)

Example 85 with MultiLabel

use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.

the class PluginF1 method showPredictBySupport.

//    public MultiLabel showPredictBySampling(Vector vector){
//        System.out.println("sampling procedure");
////        List<MultiLabel> samples = cbm.samples(vector, numSamples);
//        Pair<List<MultiLabel>, List<Double>> pair = cbm.samples(vector, probMassThreshold);
//        List<Pair<MultiLabel, Double>> list = new ArrayList<>();
//        List<MultiLabel> labels = pair.getFirst();
//        List<Double> probs = pair.getSecond();
//        for (int i=0;i<labels.size();i++){
//            list.add(new Pair<>(labels.get(i),probs.get(i)));
//        }
//        Comparator<Pair<MultiLabel, Double>> comparator = Comparator.comparing(a-> a.getSecond());
//
//        System.out.println(list.stream().sorted(comparator.reversed()).collect(Collectors.toList()));
//
//
//
////        for (int i=0;i<labels.size();i++){
////            System.out.println(labels.get(i)+": "+probs.get(i));
////        }
//        return GeneralF1Predictor.predict(cbm.getNumClasses(),pair.getFirst(), pair.getSecond());
//    }
//
//    public void showPredictBySamplingNonEmpty(Vector vector){
//        System.out.println("sampling procedure");
//        Pair<List<MultiLabel>, List<Double>> pair = cbm.sampleNonEmptySets(vector, probMassThreshold);
//        List<Pair<MultiLabel, Double>> list = new ArrayList<>();
//        List<MultiLabel> labels = pair.getFirst();
//        List<Double> probs = pair.getSecond();
//        double[] probsArray = probs.stream().mapToDouble(a->a).toArray();
//
//        for (int i=0;i<labels.size();i++){
//            list.add(new Pair<>(labels.get(i),probs.get(i)));
//        }
//        Comparator<Pair<MultiLabel, Double>> comparator = Comparator.comparing(a-> a.getSecond());
//
//        MultiLabel gfmPred =  GeneralF1Predictor.predict(cbm.getNumClasses(),pair.getFirst(), pair.getSecond());
//        MultiLabel argmaxPre = cbm.predict(vector);
//        System.out.println("expected f1 of argmax predictor= "+GeneralF1Predictor.expectedF1(labels,probsArray, argmaxPre,cbm.getNumClasses()));
//        System.out.println("expected f1 of GFM predictor= "+GeneralF1Predictor.expectedF1(labels,probsArray, gfmPred,cbm.getNumClasses()));
//
//        System.out.println(list.stream().sorted(comparator.reversed()).collect(Collectors.toList()));
//    }
public GeneralF1Predictor.Analysis showPredictBySupport(Vector vector, MultiLabel truth) {
    //        System.out.println("support procedure");
    double[] probArray = cbm.predictAssignmentProbs(vector, support);
    GeneralF1Predictor generalF1Predictor = new GeneralF1Predictor();
    MultiLabel prediction = generalF1Predictor.predict(cbm.getNumClasses(), support, probArray);
    GeneralF1Predictor.Analysis analysis = GeneralF1Predictor.showSupportPrediction(support, probArray, truth, prediction, cbm.getNumClasses());
    return analysis;
}
Also used : MultiLabel(edu.neu.ccs.pyramid.dataset.MultiLabel) GeneralF1Predictor(edu.neu.ccs.pyramid.multilabel_classification.plugin_rule.GeneralF1Predictor)

Aggregations

MultiLabel (edu.neu.ccs.pyramid.dataset.MultiLabel)101 Vector (org.apache.mahout.math.Vector)22 MultiLabelClfDataSet (edu.neu.ccs.pyramid.dataset.MultiLabelClfDataSet)21 File (java.io.File)14 DenseVector (org.apache.mahout.math.DenseVector)13 CMLCRF (edu.neu.ccs.pyramid.multilabel_classification.crf.CMLCRF)12 Pair (edu.neu.ccs.pyramid.util.Pair)8 LBFGS (edu.neu.ccs.pyramid.optimization.LBFGS)7 ArrayList (java.util.ArrayList)7 MLMeasures (edu.neu.ccs.pyramid.eval.MLMeasures)6 CRFLoss (edu.neu.ccs.pyramid.multilabel_classification.crf.CRFLoss)6 MultiLabelClassifier (edu.neu.ccs.pyramid.multilabel_classification.MultiLabelClassifier)5 GeneralF1Predictor (edu.neu.ccs.pyramid.multilabel_classification.plugin_rule.GeneralF1Predictor)5 Collectors (java.util.stream.Collectors)5 EarlyStopper (edu.neu.ccs.pyramid.optimization.EarlyStopper)4 java.util (java.util)4 StopWatch (org.apache.commons.lang3.time.StopWatch)4 Config (edu.neu.ccs.pyramid.configuration.Config)3 DataSetUtil (edu.neu.ccs.pyramid.dataset.DataSetUtil)3 TRECFormat (edu.neu.ccs.pyramid.dataset.TRECFormat)3