Work in progress.

Able to read short survey, recipe book but crashing in Bayes Net code.
This commit is contained in:
Woody Folsom
2012-03-11 21:25:04 -04:00
parent 3046f68681
commit bb94356ec1
11 changed files with 999 additions and 37 deletions

View File

@@ -4,7 +4,7 @@ import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
@@ -22,7 +22,7 @@ public class AlarmExampleTest {
BayesNet sprinkler = AlarmNetBuilderTable.alarm();
sprinkler = AlarmNetBuilderTree.sprinkler();
// P(B | j, m)
LinkedList<ProbabilityAssignment> probs = EnumerateAll.enumerateAsk(
List<ProbabilityAssignment> probs = EnumerateAll.enumerateAsk(
new Variable(AlarmNetBuilderTable.BURGLARY,
AlarmNetBuilderTable.DOMAIN), sprinkler,
AlarmNetBuilderTable.completeQueryBulgary());

View File

@@ -1,11 +1,11 @@
package dkohl.bayes.example;
import java.util.LinkedList;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Test;
import dkohl.bayes.bayesnet.BayesNet;
@@ -119,7 +119,7 @@ public class FoodExampleTest {
+ dist.getAssignments().get(assignment));
}
LinkedList<ProbabilityAssignment> probs = EnumerateAll.enumerateAsk(
List<ProbabilityAssignment> probs = EnumerateAll.enumerateAsk(
new Variable(FoodExampleBuilder.TASTE,
FoodExampleBuilder.RATING_DOMAIN), net,
FoodExampleBuilder.completeQueryTasteBeef());
@@ -145,7 +145,7 @@ public class FoodExampleTest {
}
}
System.out.println("TASE PORK: " + max_arg + " " + max_val);
System.out.println("TASTE PORK: " + max_arg + " " + max_val);
assertThat(max_arg, equalTo("10"));
assertTrue("Error: max_val for TASTE_PORK should be > 2.6%", max_val > 0.026);
}

View File

@@ -3,6 +3,8 @@ package dkohl.bayes.example.builders;
import java.util.HashSet;
import java.util.LinkedList;
import net.woodyfolsom.cs6601.p2.Ingredient.TYPE;
import dkohl.bayes.bayesnet.BayesNet;
import dkohl.bayes.estimation.MaximumLikelihoodEstimation;
import dkohl.bayes.probability.Assignment;
@@ -21,13 +23,13 @@ public class FoodExampleBuilder {
public static final String SOMEONE_VEGETARIAN = "Vegetarian";
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";
public static final String CONTAINS_TOMATOS = "Tomatos";
public static final String CONTAINS_POTATOS = "Potatos";
public static final String CONTAINS_BEEF = TYPE.BEEF.toString();
public static final String CONTAINS_PORK = TYPE.PORK.toString();
public static final String CONTAINS_TOMATOS = TYPE.TOMATO.toString();
public static final String CONTAINS_POTATOS = TYPE.POTATO.toString();
public static final String TRUE_VALUE = "true";
public static final String FALSE_VALUE = "false";
public static final String TRUE_VALUE = Boolean.TRUE.toString();
public static final String FALSE_VALUE = Boolean.FALSE.toString();
public static final String DOMAIN[] = { TRUE_VALUE, FALSE_VALUE };

View File

@@ -29,7 +29,7 @@ public class RecipeBookReaderTest {
assertTrue(recipe.getIngredients().contains(TYPE.EGGS));
assertTrue(recipe.getIngredients().contains(TYPE.GLUTEN));
assertTrue(recipe.getIngredients().contains(TYPE.SPICE));
assertFalse(recipe.getIngredients().contains(TYPE.RED_MEAT));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POULTRY));
assertFalse(recipe.getIngredients().contains(TYPE.SHELLFISH));
@@ -37,4 +37,44 @@ public class RecipeBookReaderTest {
System.out.println(recipeBook.getRecipe(rIndex).getHead().getTitle());
}
}
@Test
public void testReadShortSurveyDataset() {
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/short_recipebook.xml"));
assertNotNull(recipeBook);
assertThat(recipeBook.getSize(), is(equalTo(4)));
for (int i = 0; i < 4; i++) {
Recipe recipe = recipeBook.getRecipe(i);
System.out.println(i + ": " +recipe.getHead().getTitle());
}
Recipe recipe = recipeBook.getRecipe(0);
assertThat(recipe.getHead().getTitle(), is(equalTo("Catalan Rice")));
assertTrue(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(1);
assertThat(recipe.getHead().getTitle(), is(equalTo("Hamburger Steak")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertTrue(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertFalse(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(2);
assertThat(recipe.getHead().getTitle(), is(equalTo("Potatoes in a Thick Sauce")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertTrue(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(3);
assertThat(recipe.getHead().getTitle(), is(equalTo("Tomato-Zucchini Casserole")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
}
}