Work in progress.

This commit is contained in:
Woody Folsom
2012-03-11 16:49:20 -04:00
parent 571d0a1922
commit d5d73003d2
13 changed files with 833 additions and 67 deletions

View File

@@ -34,9 +34,9 @@ public class FoodExampleTest {
+ table.getAssignments().get(assignment).getProbability());
}
System.out.println("MEET: ");
System.out.println("MEAT: ");
table = (ProbabilityTable) net.getNodes().get(
FoodExampleBuilder.CONTAINS_MEET);
FoodExampleBuilder.CONTAINS_MEAT);
for (String name : table.getNames()) {
System.out.print(name + " ");
}

View File

@@ -19,7 +19,7 @@ public class FoodExampleBuilder {
public static final String TASTE = "Taste";
public static final String SOMEONE_VEGETARIAN = "Vegetarian";
public static final String CONTAINS_MEET = "Meet";
public static final String CONTAINS_MEAT = "Meat";
public static final String CONTAINS_VEGETABLE = "Vegetable";
public static final String CONTAINS_BEEF = "Beef";
public static final String CONTAINS_PORK = "Pork";
@@ -35,7 +35,7 @@ public class FoodExampleBuilder {
"6", "7", "8", "9", "10" };
private static final String[] VARIABLES = { SOMEONE_VEGETARIAN,
CONTAINS_BEEF, CONTAINS_MEET, CONTAINS_PORK, CONTAINS_POTATOS,
CONTAINS_BEEF, CONTAINS_MEAT, CONTAINS_PORK, CONTAINS_POTATOS,
CONTAINS_TOMATOS, CONTAINS_VEGETABLE, TASTE };
private static final String[] OBSERVED = { CONTAINS_BEEF, CONTAINS_PORK,
@@ -59,13 +59,13 @@ public class FoodExampleBuilder {
return new LinkedList<Assignment>(assignment);
}
public static Ontology onto() {
public static Ontology createOntology() {
HashSet<String> classes = new HashSet<String>();
classes.add(CONTAINS_MEET);
classes.add(CONTAINS_MEAT);
classes.add(CONTAINS_VEGETABLE);
Ontology onthology = new Ontology(classes);
onthology.define(CONTAINS_PORK, CONTAINS_MEET);
onthology.define(CONTAINS_BEEF, CONTAINS_MEET);
onthology.define(CONTAINS_PORK, CONTAINS_MEAT);
onthology.define(CONTAINS_BEEF, CONTAINS_MEAT);
onthology.define(CONTAINS_TOMATOS, CONTAINS_VEGETABLE);
onthology.define(CONTAINS_POTATOS, CONTAINS_VEGETABLE);
@@ -146,7 +146,7 @@ public class FoodExampleBuilder {
public static DataSet examples() {
DataSet data = new DataSet();
Ontology onto = onto();
Ontology onto = createOntology();
// user one ratings
data.add(normalize(porkTomatoDish(10), onto));
data.add(normalize(porkPotatoDish(9), onto));
@@ -184,19 +184,19 @@ public class FoodExampleBuilder {
}
public static ProbabilityDistribution beef() {
String names[] = { CONTAINS_MEET, CONTAINS_BEEF };
String names[] = { CONTAINS_MEAT, CONTAINS_BEEF };
ProbabilityTable table = new ProbabilityTable(names);
return table;
}
public static ProbabilityDistribution pork() {
String names[] = { CONTAINS_MEET, CONTAINS_PORK };
String names[] = { CONTAINS_MEAT, CONTAINS_PORK };
ProbabilityTable table = new ProbabilityTable(names);
return table;
}
public static ProbabilityDistribution meet() {
String names[] = { SOMEONE_VEGETARIAN, CONTAINS_MEET };
String names[] = { SOMEONE_VEGETARIAN, CONTAINS_MEAT };
ProbabilityTable table = new ProbabilityTable(names);
return table;
}
@@ -229,7 +229,7 @@ public class FoodExampleBuilder {
public static BayesNet dishNet() {
BayesNet net = new BayesNet(VARIABLES);
net.setDistribution(new Variable(SOMEONE_VEGETARIAN, DOMAIN), vegi());
net.setDistribution(new Variable(CONTAINS_MEET, DOMAIN), meet());
net.setDistribution(new Variable(CONTAINS_MEAT, DOMAIN), meet());
net.setDistribution(new Variable(CONTAINS_VEGETABLE, DOMAIN),
vegetables());
net.setDistribution(new Variable(CONTAINS_BEEF, DOMAIN), beef());
@@ -238,19 +238,19 @@ public class FoodExampleBuilder {
net.setDistribution(new Variable(CONTAINS_TOMATOS, DOMAIN), tomatos());
net.setDistribution(new Variable(TASTE, RATING_DOMAIN), taste());
Ontology onthology = onto();
for (String category : onthology.getClasses()) {
Ontology ontology = createOntology();
for (String category : ontology.getClasses()) {
net.connect(category, SOMEONE_VEGETARIAN);
}
for (String thing : OBSERVED) {
net.connect(thing, onthology.getInheritance().get(thing));
net.connect(thing, ontology.getInheritance().get(thing));
net.connect(TASTE, thing);
}
for (String category : onthology.getClasses()) {
for (String category : ontology.getClasses()) {
MaximumLikelihoodEstimation.estimate(examples(), net, category);
for (String thing : onthology.getClasses2thing().get(category)) {
for (String thing : ontology.getClasses2thing().get(category)) {
MaximumLikelihoodEstimation.estimate(examples(), net, thing);
}
}