Work in progress.

This commit is contained in:
Woody Folsom
2012-03-11 17:46:53 -04:00
parent d5d73003d2
commit 3046f68681
3 changed files with 34 additions and 1 deletions

Binary file not shown.

BIN
lib/commons-math3-3.0.jar Normal file

Binary file not shown.

View File

@@ -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);
}
}
}