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