cws/main_cw02.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 08 Nov 2020 13:09:38 +0000
changeset 355 e4d779587d3f
parent 350 d71c68fd0ca1
child 356 35c75b594459
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
268
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
     1
% !TEX program = xelatex
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\documentclass{article}
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
     3
\usepackage{../style}
166
284a0f869e48 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     4
\usepackage{disclaimer}
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
     5
\usepackage{../langs}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
329
828326d1b3b2 updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    10
%% should ask to lower case the words.
828326d1b3b2 updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    11
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    12
\section*{Part 7 (Scala, 7 Marks)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
264
25f3fbc43251 updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    14
25f3fbc43251 updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    15
\noindent
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    16
You are asked to implement a Scala program for recommending movies
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    17
according to a ratings list. This part is due on \cwSEVENa{} at 5pm.\bigskip
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 48
diff changeset
    18
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    19
\IMPORTANTNONE{}
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    20
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    21
\noindent
144
41a2b4f2c30c updated
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    22
Also note that the running time of each part will be restricted to a
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    23
maximum of 30 seconds on my laptop.
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    24
166
284a0f869e48 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    25
\DISCLAIMER{}
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    26
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    27
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    28
\subsection*{Reference Implementation}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    29
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    30
Like the C++ part, the Scala part works like this: you push your files
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    31
to GitHub and receive (after sometimes a long delay) some automated
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    32
feedback. In the end we will take a snapshot of the submitted files
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    33
and apply an automated marking script to them.\medskip
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    34
268
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    35
\noindent
306
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    36
In addition, the Scala part comes with reference
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    37
implementations in form of \texttt{jar}-files. This allows you to run
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    38
any test cases on your own computer. For example you can call Scala on
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    39
the command line with the option \texttt{-cp danube.jar} and then
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    40
query any function from the template file. Say you want to find out
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    41
what the function \texttt{} produces: for this you just need
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    42
to prefix it with the object name \texttt{CW7b}.  If you want to find out what
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    43
these functions produce for the list \texttt{List("a", "b", "b")},
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    44
you would type something like:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    46
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    47
$ scala -cp danube.jar
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    48
scala> val ratings_url =
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    49
     | """https://nms.kcl.ac.uk/christian.urban/ratings.csv"""
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    50
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    51
scala> CW7b.get_csv_url(ratings_url)
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    52
val res0: List[String] = List(1,1,4 ...)
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    53
\end{lstlisting}%$
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    54
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    55
\subsection*{Hints}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    57
\noindent
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    58
Use \texttt{.split(",").toList} for splitting
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    59
strings according to commas (similarly for the newline character \mbox{$\backslash$\texttt{n}}),
301
aa0e86419773 updated
Christian Urban <urbanc@in.tum.de>
parents: 284
diff changeset
    60
\texttt{.getOrElse(..,..)} allows to query a Map, but also gives a
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    61
default value if the Map is not defined, a Map can be `updated' by
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    62
using \texttt{+}, \texttt{.contains} and \texttt{.filter} can test whether
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    63
an element is included in a list, and respectively filter out elements in a list,
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    64
\texttt{.sortBy(\_.\_2)} sorts a list of pairs according to the second
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    65
elements in the pairs---the sorting is done from smallest to highest,
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    66
\texttt{.take(n)} for taking some elements in a list (takes fewer if the list
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    67
contains less than \texttt{n} elements).
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    68
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    69
202
3b40cc2a938a updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    70
\newpage
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    73
\subsection*{Part (7 Marks, file danube.scala)}
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    74
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    75
You are creating Danube.co.uk which you hope will be the next big thing
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    76
in online movie renting. You know that you can save money by
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    77
anticipating what movies people will rent; you will pass these savings
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    78
on to your users by offering a discount if they rent movies that
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    79
Danube.co.uk recommends.  
48
7a6a75ea9738 updated
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
    80
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    81
Your task is to generate \emph{two} movie recommendations for every
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    82
movie a user rents. To do this, you calculate what other
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    83
renters, who also watched this movie, suggest by giving positive ratings.
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    84
Of course, some suggestions are more popular than others. You need to find
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    85
the two most-frequently suggested movies. Return fewer recommendations,
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    86
if there are fewer movies suggested.
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    87
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    88
The calculations will be based on the small datasets which the research lab
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    89
GroupLens provides for education and development purposes.
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    90
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    91
\begin{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    92
\url{https://grouplens.org/datasets/movielens/}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    93
\end{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    94
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    95
\noindent
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    96
The slightly adapted CSV-files should be downloaded in your Scala
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    97
file from the URLs:
148
fc72f3ab3a57 updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
    98
fc72f3ab3a57 updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
    99
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   100
\begin{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   101
\begin{tabular}{ll}  
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   102
  \url{https://nms.kcl.ac.uk/christian.urban/ratings.csv} & (940 KByte)\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   103
  \url{https://nms.kcl.ac.uk/christian.urban/movies.csv}  & (280 KByte)\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   104
\end{tabular}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   105
\end{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   106
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   107
\noindent
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   108
The ratings.csv file is organised as userID, 
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   109
movieID, and rating (which is between 0 and 5, with \emph{positive} ratings
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   110
being 4 and 5). The file movie.csv is organised as
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   111
movieID and full movie name. Both files still contain the usual
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   112
CSV-file header (first line). In this part you are asked
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   113
to implement functions that process these files. If bandwidth
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   114
is an issue for you, download the files locally, but in the submitted
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   115
version use \texttt{Source.fromURL} instead of \texttt{Source.fromFile}.
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   116
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   117
\subsection*{Tasks}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   118
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   119
\begin{itemize}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   120
\item[(1)] Implement the function \pcode{get_csv_url} which takes an
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   121
  URL-string as argument and requests the corresponding file. The two
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   122
  URLs of interest are \pcode{ratings_url} and \pcode{movies_url},
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   123
  which correspond to CSV-files mentioned above.  The function should
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   124
  return the CSV-file appropriately broken up into lines, and the
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   125
  first line should be dropped (that is omit the header of the CSV-file).
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   126
  The result is a list of strings (the lines in the file). In case
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   127
  the url does not produce a file, return the empty list.\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   128
  \mbox{}\hfill [1 Mark]
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   129
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   130
\item[(2)] Implement two functions that process the (broken up)
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   131
  CSV-files from (1). The \pcode{process_ratings} function filters out all
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   132
  ratings below 4 and returns a list of (userID, movieID) pairs. The
333
0b82e661341a updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   133
  \pcode{process_movies} function returns a list of (movieID, title) pairs.
0b82e661341a updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   134
  Note the input to these functions will be the output of the function
0b82e661341a updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   135
  \pcode{get_csv_url}.\\
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   136
  \mbox{}\hfill [1 Mark]
268
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   137
%\end{itemize}  
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   138
%  
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   139
%
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   140
%\subsection*{Part 3 (4 Marks, file danube.scala)}
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   141
%
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   142
%\subsection*{Tasks}
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   143
%
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   144
%\begin{itemize}
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   145
\item[(3)] Implement a kind of grouping function that calculates a Map
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   146
  containing the userIDs and all the corresponding recommendations for
259
77c3bd7a0670 updated
Christian Urban <urbanc@in.tum.de>
parents: 251
diff changeset
   147
  this user (list of movieIDs). This should be implemented in a
77c3bd7a0670 updated
Christian Urban <urbanc@in.tum.de>
parents: 251
diff changeset
   148
  tail-recursive fashion using a Map as accumulator. This Map is set to
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   149
  \pcode{Map()} at the beginning of the calculation. For example
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   150
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   151
\begin{lstlisting}[numbers=none]
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   152
val lst = List(("1", "a"), ("1", "b"),
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   153
               ("2", "x"), ("3", "a"),
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   154
               ("2", "y"), ("3", "c"))
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   155
groupById(lst, Map())
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   156
\end{lstlisting}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   157
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   158
returns the ratings map
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   159
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   160
\begin{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   161
  \pcode{Map(1 -> List(b, a), 2 -> List(y, x), 3 -> List(c, a))}.
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   162
\end{center}
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   163
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   164
\noindent
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   165
In which order the elements of the list are given is unimportant.\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   166
\mbox{}\hfill [1 Mark]
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   167
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   168
\item[(4)] Implement a function that takes a ratings map and a movieID
210
34f935e13bdd updated
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   169
  as arguments.  The function calculates all suggestions containing the
34f935e13bdd updated
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   170
  given movie in its recommendations. It returns a list of all these
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   171
  recommendations (each of them is a list and needs to have the given
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   172
  movie deleted, otherwise it might happen we recommend the same movie
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   173
  ``back''). For example for the Map from above and the movie
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   174
  \pcode{"y"} we obtain \pcode{List(List("x"))}, and for the movie
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   175
  \pcode{"a"} we get \pcode{List(List("b"), List("c"))}.\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   176
  \mbox{}\hfill [1 Mark]
148
fc72f3ab3a57 updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   177
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   178
\item[(5)] Implement a suggestions function which takes a ratings map
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   179
  and a movieID as arguments. It calculates all the recommended movies
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   180
  sorted according to the most frequently suggested movie(s) sorted
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   181
  first. This function returns \emph{all} suggested movieIDs as a list of
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   182
  strings.\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   183
  \mbox{}\hfill [1 Mark]
148
fc72f3ab3a57 updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   184
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   185
\item[(6)]  
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   186
  Implement then a recommendation function which generates a maximum
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   187
  of two most-suggested movies (as calculated above). But it returns
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   188
  the actual movie name, not the movieID. If fewer movies are recommended,
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   189
  then return fewer than two movie names.\\
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   190
  \mbox{}\hfill [1 Mark]
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   191
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   192
\item[(7)] Calculate the recommendations for all movies according to
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   193
 what the recommendations function in (6) produces (this
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   194
 can take a few seconds). Put all recommendations into a list 
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   195
 (of strings) and count how often the strings occur in
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   196
 this list. This produces a list of string-int pairs,
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   197
 where the first component is the movie name and the second
350
d71c68fd0ca1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   198
 is the number of how many times the movie was recommended. 
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   199
 Sort all the pairs according to the number
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   200
 of times they were recommended (most recommended movie name 
350
d71c68fd0ca1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   201
 first).\\
d71c68fd0ca1 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 349
diff changeset
   202
 \mbox{}\hfill [1 Mark]
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   203
  
203
e0420c7b8a19 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   204
\end{itemize}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
268
d20583497c5b updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   206
\end{document} 
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
%%% End: 
349
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   212
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   213
ef4bb09a01b7 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   214