diff --git a/commons-math3-3.0-bin.tar.gz b/commons-math3-3.0-bin.tar.gz new file mode 100644 index 0000000..4c642b2 Binary files /dev/null and b/commons-math3-3.0-bin.tar.gz differ diff --git a/lib/commons-math3-3.0.jar b/lib/commons-math3-3.0.jar new file mode 100644 index 0000000..ff84bd2 Binary files /dev/null and b/lib/commons-math3-3.0.jar differ diff --git a/src/net/woodyfolsom/cs6601/p2/BayesChef.java b/src/net/woodyfolsom/cs6601/p2/BayesChef.java index 80c0d8a..466106a 100644 --- a/src/net/woodyfolsom/cs6601/p2/BayesChef.java +++ b/src/net/woodyfolsom/cs6601/p2/BayesChef.java @@ -2,6 +2,8 @@ package net.woodyfolsom.cs6601.p2; import java.io.File; +import org.apache.commons.math3.stat.regression.SimpleRegression; + public class BayesChef { public static void main(String... args) { @@ -19,10 +21,41 @@ public class BayesChef { System.out.println("Evaluating preference for remaining recipes."); + //read survey prefs from survey.xml + double[][] surveyPrefs = new double[5][]; + for (int i = 0; i < 5; i++) { + surveyPrefs[i] = new double[11]; + for (int j = 0; j < 11; j++) { + surveyPrefs[i][j] = survey.getDiner(i).getRating(j); + } + } + + //generating stub evaluated preferences to test RMSE calculation + double[][] calculatedPrefs = new double[5][]; + calculatedPrefs[0] = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + calculatedPrefs[1] = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + calculatedPrefs[2] = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + calculatedPrefs[3] = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + calculatedPrefs[4] = new double[] { 10.0, 10.0, 0.0, 10.0, 10.0, 4.0, 10.0, 10.0, 10.0, 10.0, 10.0 }; + System.out.println("RMSE for recipes #12-22 (calculated vs. surveyed preference):"); for (int dinerIndex = 0; dinerIndex < survey.getDinerCount(); dinerIndex++) { - System.out.println("Diner # " + (dinerIndex + 1) + "..."); + SimpleRegression simpleRegression = new SimpleRegression(); + + for (int i = 0; i < 11; i++) { + simpleRegression.addData(i,calculatedPrefs[dinerIndex][i]); + } + double calculatedMSE = simpleRegression.getMeanSquareError(); + simpleRegression.clear(); + + for (int i = 0; i < 11; i++) { + simpleRegression.addData(i,surveyPrefs[dinerIndex][i]); + } + + double surveyMSE = simpleRegression.getMeanSquareError(); + + System.out.println("Diner # " + (dinerIndex + 1) + ": " + calculatedMSE + " vs. "+ surveyMSE); } } }