Work in progress.
This commit is contained in:
BIN
commons-math3-3.0-bin.tar.gz
Normal file
BIN
commons-math3-3.0-bin.tar.gz
Normal file
Binary file not shown.
BIN
lib/commons-math3-3.0.jar
Normal file
BIN
lib/commons-math3-3.0.jar
Normal file
Binary file not shown.
@@ -2,6 +2,8 @@ package net.woodyfolsom.cs6601.p2;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.stat.regression.SimpleRegression;
|
||||||
|
|
||||||
public class BayesChef {
|
public class BayesChef {
|
||||||
|
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
@@ -19,10 +21,41 @@ public class BayesChef {
|
|||||||
|
|
||||||
System.out.println("Evaluating preference for remaining recipes.");
|
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):");
|
System.out.println("RMSE for recipes #12-22 (calculated vs. surveyed preference):");
|
||||||
|
|
||||||
for (int dinerIndex = 0; dinerIndex < survey.getDinerCount(); dinerIndex++) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user