\documentclass[times, 08pt,twocolumn]{article}
\usepackage{latex8}

\usepackage{titlesec}
\usepackage[margin=0.88in]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}

\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}

\begin{document}
\pagestyle{empty}

\title{A Baysian Approach to Collaborative Dish Selection}
\author{Team 10}
\date{February 23, 2012}

\maketitle

\section*{Introduction}
As anyone who has ever planned a catered event can attest, attempting
to satisfy the various palates, dietary requirements and tastes of a
group of diners can be a daunting task.  This is particularly true
given the exponential number of dishes which can be created from a
small number of ingredients, as well has hard constraints such as
allergies and religious beliefs.  Many professional catering services
handle this problem by allowing guests to select from a very limited
menu. We introduce a dish recommendation system
based on Bayesian Networks modeling user preferences.
We predict the meals from a data base of recepices that most likely match the varied tastes
of the customers, using a limited set of ingredients.  This type of expert system
would be of great use to a catering service or restaurant which needs to rapdily decide on
a small number of dishes which would be acceptable for a large dinner party,
given diverse requirements and preferences. 

\paragraph*{Baysian Catering: A use case.}
Imagine, you run a catering service and have to 
plan an event with a customer. You can 
create a variaty of dishes and now you
want to discuss with your clients which one to 
serve. In order to get a better idea of which preferences
and needs you clients will have, you let them fill
out a survey in advance, where they rate a small amount of 
your dishes on a scale from $1 - 10$ and inform you about
hard constraints like allergies, religous constraints
or vegetarians. You then use those results in order to predict
the ratings for the rest of your dishes and present the clients
the top $k$ results. If such a system works this will save time and will lead
to a better cutomer satisfaction since you can present them dishes
they will most probably like but still suprise them (since you have
not presented them what the already rated). After the dinner
participants could rate the dishes served at the party which would
improve your work for that client in the future.

\section*{Related Work}
Boekel and Corney propose using Bayesian Networks to model 
consumer needs in food production chains \cite{vanboekel} \cite{corney}. 
Janzen and Xiang propose an intelligent refrigerator capable of 
generating meal plans based on inventory 
and past food choices \cite{janzenxiang}.  
We suggest that these approaches are limited in that they
only consider the preferences of a single (or supposed 'typical') 
user rather than a group. Baysian networks have also been
applied to recommendation systems before in on-line social
networks \cite{truyen} making predictions of the form
``if you bought those items what is the probability you would like to
buy that''.  This method also uses baysian networks
for prediction and our approach is similar or inspired by
some of Truyens \cite{truyen}.

\section*{Approach}

The approached problem is to pick a single meal which best meets the requirements
and tastes of different people dining together. We learn a predictive
baysian net from a survey distributed to participants of the meal as
training data in order to capture their preferences. The dishes
in the questionaire are selected such that all ingrediants
are covered. The participants rate each dish on a scale from
one to ten and give additional information like vegetarians.
For new dishes we then predict the maximum likelihood 
rating given our model. 
In the following we will describe our approach in detail.
First we will discuss the data selection, then the
modeling of the user preference and in the
end how we trained the modeled net from
gathered data and predicted the 
value for different recipes.

\paragraph*{Data accuisition}
We first accumulated a diverse collection of license-free sample recipes from web sites such as \emph{Darkstar's Meal-Master Recipes} (http://home.earthlink.net/~darkstar105/).  Next, we converted these recipes from flat text files to well-formed XML using the Krecipes application for Debian Linux.  Finally, we created a representative data set representing several diners' preference for
24 of these recipes, using a simple survey of the type 'rate on a
scale of 1 to 10,  10 being favorite and 1 being least favorite'. 
Furthermore, users were allowed to specify a vegetarian 
or nut-free meal preference.

\paragraph*{Knowledge Engineering}
We model the diners' various taste preferences using
a Bayes net. The net consists of three node types.
We call them ``control nodes'', ``taste nodes''
and ``rating nodes''. A ``preference node'' 
models the probability of a diners' preference towards an
ingredient ($P(likes tomato)$, $P(likes potato)$)  or a category
($P(likes meat)$). These variables are discrete. The ingredients
are conditional independent from each other but conditioned
by the food category they belong to (see Figure \ref{img:bayes_net}
the two top layers). A control node can definitely reject a dish,
by evaluating to $0$ in certain conditions. For 
example if someone is vegetarian and the presented dish contains
meet, the control variable for vegetarian will evaluate to $0$ and
so the probability for the whole dish will become $0$.
So the vegetarian variable is conditioned by meat. 
The third type in the net is a preference node, it is continuos
and models the dish rating given a set of ingredients.
The overall net is shown in Figure \ref{img:bayes_net}.

\begin{figure}[ht]
\centering
\includegraphics[width=0.9\linewidth]{bayes}
\caption{Our Baysian net modeling user preferences. The top layer
  describes the categories Meat and Vegetable. We have a control
  variable vegetarian for Meat, such that it will always evaluate to
  $0$ when there is meat involved in a dish and we have a vegetarian
  diner. The mid layer describes the preference for different
  ingredients. The last layer is a gaussian predicting the users preferences.}
\label{img:bayes_net}
\end{figure}

%\subsection*{implementation}
\paragraph*{Learning user preferences}
In order to estimate the model parameters, the
system will be trained with statistics about taste 
and preferences given a set of dishes with ratings
from multiple users. The training set is generated from
the questionnaires we distributed.
An example  for a survey output could look like this (Ingredients, Rating): ``Pork,
Potatoes, 8''. In order to perform normal Maximum Likelihood Learning
\cite{murphy} we have to have information about all variables
(``Pork, Potatoes, Tomatoes, Beef, Meat, Vegetables, Rating'').
We perform several steps in order to transform from the survey input
to a training instance.
First we discretize the values such that all given variables (in our
case Pork and Potatoes) are set to ``true'' if the value is above
a certain threshold (in our experiments $5$) and ``false'' otherwise.
In that way ``liking things rated $>$ 5'' appear more often in the 
training set and will be assigned with a higher probability.
We add categories by including the category of each ingredient 
from the survey. If the ingredient is liked, the category is too
and if it is not, the category is not liked too. The last step 
is to add all values that are not in the recipe as ``false''
to the training instance.

From a set of those preprocessed assignments, we can directly calculate 
the probabilities for the ingredients using Maximum Likelihood
Learning \cite{murphy}. For example for an assignment of a
conditional variable $P(X = x \mid Y_1 = y_1, ... Y_2 = y2)$,
we count how often we observe the configuration $X = x, Y_1 = y_1,
... Y_2 = y2$ and how often we count $Y_1 = y_1, ... Y_2 = y2$
in our data set. The maximum likelihood is then defined as 
\begin{align}
P(X = x| Y_1 = y_1, ... Y_2 = y2) =\\
N(X = x| Y_1 = y_1, ... Y_2 = y2) \over N(Y_1 = y_1, ... Y_2 = y2)
\end{align}
where $N(A)$ is the number of times event $A$occurs in the data set.
For a continuos variable like rating, we estimate a gaussian for
each combination of it's parents. For example if the rating variable
is dependent on beef and tomatos, we would estimate 4 gaussians,
one for each possible combination of beef and tomatos. So during
training we would estimate mean and variance for all cases where
$(tomato = true, potato = true)$, $(tomato = false, potato = true)$
and so on.

\paragraph*{Inferring maximum likelihood rating}
Having estimated the probabilities of such a net, we can infer 
the maximum likelihood rating of a unseen dish while observing only
a set of ingredients. Therefore we will iterate over all possible
ratings ($1 - 10$) and compute the probability of this rating.
The maximum probability is the maximum likelihood rating 
for that dish. We use the enumerateAll algorithm \cite{russelnorvig}, 
for the probability calculations.

\paragraph*{Implementation}
In order to model food preferences, we implemented
a custom Baysian net library in java with 
minimal use of third party libraries (e.g. for XML input).
We chose to implement our own Library,
for maximum flexibility and to ensure that the learning algorithm
functions precisely as follows:
The library uses the sum-product algorithm for
inference and maximum likelihood learning
for parameter estimation. In our implementation
we support discrete as well as continous 
probability distributions. Discrete distributions
can be modeled as tables or as trees. 
In our implementation only continous distributions with discrete parents
are supported. A continous distribution is then modeled as a mapping
of all possible combination of it' s parents to a gaussian set.

\section*{Evaluation}
In an experiment we collected $XXX$ ratings from $XXX$ persons.
We trained the Bayes net using a sparse subset (50\% of the rated
recipes) of the survey data. Then we evaluated the rest of the 
recipes (which are all unseen) and calculated
the maximum likelihood rating.
As shown below, the calculated preferences for recipes
which were not used to train the Bayes net are quite close to the
actual survey data,  which essentially reflects the following
preferences 
(Sample ratings are on a 1-10 scale):

%\begin{description}
%\item[Diner 1] No allergies, prefers all dishes equally (5)

%\item[Diner 2] Vegetarian, meat dishes are (1), remainder are (9)

%\item[Diner 3] Nut Alleregy, prefers meat (6) to vegetarian (4) to desert (3)

%\item[Diner 4] No allergies, prefers Pork and Desserts (9), remainder are (3)

%\end{description}

Next, we calculate the error between the application's ranking of all
dishes and the actual ranking as determined by the user surveys.  We
suggest that a low error indicates that the system has the potential
to accurately appraise constrained group food preferences for dishes
which are not part of the survey, given sufficiently detailed recipe
information.  As the Table and Figure \ref{result} show, the estimated food preferences are quite close to the actual mean ratings over all diners for the dishes which were not used to train the Bayes net.  The root mean-square-error for calculated vs. surveyed meal preferences is approximately 1.92.

\begin{table}[ht]
\begin{tabular}{ | l | l | l | }
\hline
Southwest Smoothie: & &\\
DAIRY & 5 & 5.5 \\ \hline
Bayou Shrimp Creole:  & &\\
TOMATO & 9 & 3.75 \\ \hline
Crab Burgers:  & &\\
EGGS & 5 & 3.75 \\ \hline
Broiled Flounder:  & &\\
GENERIC NUTS, EGGS & 5 & 3.75 \\ \hline
Baked Steak And Lima Beans:  & &\\
TOMATO, SUGAR & 2 & 3.75 \\ \hline
Eggplant Lasagna:  & &\\
GLUTEN & 5 & 5.25 \\ \hline
Salisbury Steak with Mushroom Sauce:  & &\\
GLUTEN, DAIRY, BEEF & 6 & 3.75 \\ \hline
Meatless Loaf:  & &\\
SPICE & 5 & 5.25 \\ \hline
Lemon Pork Chops:  & &\\
PORK, SUGAR & 5 & 5.25 \\ \hline
Fava Bean Burgers:  & &\\
EGGS, POTATO & 3 & 5.25 \\ \hline
Angel Hair Pesto Primavera:  & &\\
GENERIC NUTS, SPICE & 5 & 5.25 \\ \hline
%\hline
\end{tabular}
\end{table}

\begin{figure}[ht]
\centering
\includegraphics[width=0.5 \textwidth]{BayesChefChart.png}
\caption{Estimated vs. surveyed dish ratings}
\label{result}
\end{figure}

\section*{Conclusion}
We proposed, implemented and evaluated a food preference prediction system that
is capable of predicting how much a user would like a new, unseen recipes.
We discussed how to encode user preference towards ingredients and
categories in a Bayes Net and how to add control variables in order 
to exclude dishes that users have to avoid like no meat for
vegetarians. Furthermore, we presented our learning 
scheme for such a Bayes net using data from a small survey 
and how to predict the user rating for unseen dishes.
In an evaluation we showed that the net can predict 
preferences when learned from a sparse data set.
So in a real life setting, where people plan 
a dinner with a catering service, 
a few participants could rate a small amount of recipes 
in an online service
and the system could actually predict the scores 
on the rest of the caterers data base.
The top $k$ with the answers highest predicted
rating of the system could be used to assemble the final
dinner.
\bibliographystyle{plain}
\bibliography{p2refs}

\end{document}