@@ -0,0 +1,1970 @@
+package edu.neu.ccs.pyramid.multilabel_classification;%0A%0Aimport edu.neu.ccs.pyramid.dataset.DataSetUtil;%0Aimport edu.neu.ccs.pyramid.dataset.MultiLabel;%0Aimport edu.neu.ccs.pyramid.dataset.MultiLabelClfDataSet;%0Aimport edu.neu.ccs.pyramid.multilabel_classification.imlgb.IMLGradientBoosting;%0Aimport edu.neu.ccs.pyramid.regression.IsotonicRegression;%0Aimport edu.neu.ccs.pyramid.util.Pair;%0Aimport scala.Serializable;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.stream.IntStream;%0Aimport java.util.stream.Stream;%0A%0Apublic class SetCalibrator implements Serializable %7B%0A    private static final long serialVersionUID = 1L;%0A    private IsotonicRegression isotonicRegression;%0A%0A    public SetCalibrator(MultiLabelClassifier.AssignmentProbEstimator multiLabelClassifier, MultiLabelClfDataSet multiLabelClfDataSet) %7B%0A        List%3CMultiLabel%3E support = DataSetUtil.gatherMultiLabels(multiLabelClfDataSet);%0A        Stream%3CPair%3CDouble,Integer%3E%3E stream =  IntStream.range(0, multiLabelClfDataSet.getNumDataPoints()).parallel()%0A                .boxed().flatMap(i-%3E %7B%0A                    double%5B%5D probs = multiLabelClassifier.predictAssignmentProbs(multiLabelClfDataSet.getRow(i),support);%0A                    Stream%3CPair%3CDouble,Integer%3E%3E pairs = IntStream.range(0, probs.length).mapToObj(a -%3E %7B%0A                        Pair%3CDouble, Integer%3E pair = new Pair%3C%3E();%0A                        pair.setFirst(probs%5Ba%5D);%0A                        pair.setSecond(0);%0A                        if (support.get(a).equals(multiLabelClfDataSet.getMultiLabels()%5Bi%5D)) %7B%0A                            pair.setSecond(1);%0A                        %7D%0A                        return pair;%0A                    %7D);%0A                    return pairs;%0A                %7D);%0A        isotonicRegression = new IsotonicRegression(stream);%0A    %7D%0A%0A    public double calibrate(double uncalibrated)%7B%0A        return isotonicRegression.predict(uncalibrated);%0A    %7D%0A%7D%0A

set calibrator