@@ -0,0 +1,2589 @@
+package edu.neu.ccs.pyramid.feature_extraction;%0A%0Aimport edu.neu.ccs.pyramid.active_learning.TrueVsCompetitor;%0Aimport edu.neu.ccs.pyramid.dataset.ClfDataSet;%0Aimport edu.neu.ccs.pyramid.util.Pair;%0Aimport edu.neu.ccs.pyramid.util.Sampling;%0A%0Aimport javax.swing.text.html.Option;%0Aimport java.util.*;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.IntStream;%0A%0A/**%0A * Created by chengli on 1/25/15.%0A */%0Apublic class UncertainSampler %7B%0A%0A    private Set%3CInteger%3E blackList;%0A%0A    private List%3Cdouble%5B%5D%3E classProbMatrix;%0A%0A    private int numClasses;%0A%0A    private List%3CList%3CInteger%3E%3E dataPerClass;%0A%0A    public UncertainSampler(ClfDataSet clfDataSet) %7B%0A        this.blackList = new HashSet%3C%3E();%0A        this.numClasses = clfDataSet.getNumClasses();%0A        this.dataPerClass = new ArrayList%3C%3E();%0A        for (int k=0;k%3CnumClasses;k++)%7B%0A            dataPerClass.add(new ArrayList%3C%3E());%0A        %7D%0A%0A        int%5B%5D labels = clfDataSet.getLabels();%0A        for (int i=0;i%3Clabels.length;i++)%7B%0A            int label = labels%5Bi%5D;%0A            dataPerClass.get(label).add(i);%0A        %7D%0A%0A    %7D%0A%0A    public void setClassProbMatrix(List%3Cdouble%5B%5D%3E classProbMatrix) %7B%0A        this.classProbMatrix = classProbMatrix;%0A    %7D%0A%0A    public Set%3CInteger%3E getBlackList() %7B%0A        return blackList;%0A    %7D%0A%0A    public Optional%3CInteger%3E getUncertainOne(int classIndex)%7B%0A%0A        Comparator%3CPair%3CInteger,Double%3E%3E comparator = Comparator.comparing(Pair::getSecond);%0A        List%3CInteger%3E sorted = dataPerClass.get(classIndex).stream().map(i -%3E %7B%0A            double difference = new TrueVsCompetitor(classProbMatrix.get(i),classIndex).getDifference();%0A            return new Pair%3C%3E(i,difference);%0A        %7D).sorted(comparator).map(Pair::getFirst)%0A                .collect(Collectors.toList());%0A        return sorted.stream().filter(i-%3E !blackList.contains(i)).findFirst();%0A    %7D%0A%0A    public Optional%3CInteger%3E getRandomOne(int classIndex)%7B%0A        List%3CInteger%3E dataForClass = new ArrayList%3C%3E(dataPerClass.get(classIndex));%0A        Collections.shuffle(dataForClass);%0A        return dataForClass.stream().filter(i-%3E !blackList.contains(i)).findFirst();%0A    %7D%0A%0A    public Optional%3CInteger%3E getHardOne(int classIndex)%7B%0A        Comparator%3CPair%3CInteger,Double%3E%3E comparator = Comparator.comparing(Pair::getSecond);%0A        List%3CInteger%3E sorted = dataPerClass.get(classIndex).stream().map(i -%3E new Pair%3C%3E(i,classProbMatrix.get(i)%5BclassIndex%5D)%0A        ).sorted(comparator).map(Pair::getFirst)%0A                .collect(Collectors.toList());%0A        return sorted.stream().filter(i-%3E !blackList.contains(i)).findFirst();%0A    %7D%0A%0A%7D%0A

add UncertainSampler