Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -61,15 +66,18 @@ private ImmutableLabelInfo(ImmutableLabelInfo info) {

ImmutableLabelInfo(LabelInfo info) {
super(info);
idLabelMap = new HashMap<>();
labelIDMap = new HashMap<>();
idLabelMap = new LinkedHashMap<>();
labelIDMap = new LinkedHashMap<>();
int counter = 0;
for (Map.Entry<String,MutableLong> e : labelCounts.entrySet()) {
idLabelMap.put(counter,e.getKey());
labelIDMap.put(e.getKey(),counter);
SortedSet<String> keys = new TreeSet<>(labelCounts.keySet());
Set<Label> domainSet = new LinkedHashSet<>();
for (String key : keys) {
idLabelMap.put(counter,key);
labelIDMap.put(key,counter);
domainSet.add(labels.get(key));
counter++;
}
domain = Collections.unmodifiableSet(new HashSet<>(labels.values()));
domain = Collections.unmodifiableSet(domainSet);
}

ImmutableLabelInfo(LabelInfo info, Map<Label,Integer> mapping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.oracle.labs.mlrg.olcut.config.PropertyException;
import com.oracle.labs.mlrg.olcut.util.Pair;
import org.tribuo.Dataset;
import org.tribuo.ImmutableDataset;
import org.tribuo.Example;
import org.tribuo.Model;
import org.tribuo.Prediction;
Expand Down Expand Up @@ -250,7 +251,8 @@ public void load431ProtobufModel() throws IOException, URISyntaxException {
List<Prediction<Label>> deserOutput = deserModel.predict(p.getB());

AdaBoostTrainer trainer = new AdaBoostTrainer(t,10);
WeightedEnsembleModel<Label> model = trainer.train(p.getA());
Dataset<Label> train = new ImmutableDataset<>(p.getA(), p.getA().getProvenance(), p.getA().getOutputFactory(), deserModel.getFeatureIDMap(), deserModel.getOutputIDInfo(), false);
WeightedEnsembleModel<Label> model = trainer.train(train);
List<Prediction<Label>> output = model.predict(p.getB());

assertEquals(deserOutput.size(), p.getB().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tribuo.Dataset;
import org.tribuo.ImmutableDataset;
import org.tribuo.Model;
import org.tribuo.Prediction;
import org.tribuo.Trainer;
Expand Down Expand Up @@ -166,7 +167,8 @@ public void loadProtobufModel() throws IOException, URISyntaxException {
List<Prediction<Label>> deserOutput = deserModel.predict(p.getB());

FMClassificationTrainer trainer = new FMClassificationTrainer(new LogMulticlass(), new AdaGrad(0.1,0.1),5,1000, Trainer.DEFAULT_SEED,1,0.1);
Model<Label> model = trainer.train(p.getA());
Dataset<Label> train = new ImmutableDataset<>(p.getA().getData(), p.getA().getProvenance(), p.getA().getOutputFactory(), deserModel.getFeatureIDMap(), deserModel.getOutputIDInfo(), false);
Model<Label> model = trainer.train(train);
List<Prediction<Label>> output = model.predict(p.getB());

assertEquals(deserOutput.size(), p.getB().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testSingleClassTraining() {
assertEquals(0.0,evaluation.accuracy(new Label("Baz")));
assertEquals(0.0,evaluation.accuracy(new Label("Quux")));
assertEquals(1.0,evaluation.recall(new Label("Foo")));
assertEquals(1.0,evaluation.recall(new Label("Bar"))); // This is due to the random init of the classifier.
assertEquals(0.0,evaluation.recall(new Label("Bar")));
}

@Test
Expand Down
Loading