Work in progress.
This commit is contained in:
@@ -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 + " ");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user