cws/main_cw02.text-old
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 17 Dec 2022 12:42:49 +0000
changeset 455 557d18cce0f0
parent 428 cdfa6a293453
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
420
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
     1
268
e43f7e92ba26 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}
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 420
diff changeset
     4
\usepackage{../styles/style}
166
780c40aaad27 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     5
\usepackage{disclaimer}
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 420
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
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    11
%% should ask to lower case the words.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    12
396
3ffe978a5664 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
420
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    15
\mbox{}\hfill\textit{``C makes it easy to shoot yourself in the foot; C++ makes it harder,}\\
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    16
\mbox{}\hfill\textit{ but when you do, it blows your whole leg off.''}\smallskip\\
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    17
\mbox{}\hfill\textit{ --- Bjarne Stroustrup (creator of the C++ language)}\bigskip\bigskip
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    18
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    19
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    20
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    21
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    22
\noindent
349
682611a0fb89 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
415
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
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    26
\IMPORTANTNONE{}
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    27
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    28
\noindent
144
716042628398 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
f7bcb27d1940 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
780c40aaad27 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
f7bcb27d1940 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
682611a0fb89 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
682611a0fb89 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
682611a0fb89 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
682611a0fb89 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
e43f7e92ba26 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
f7bcb27d1940 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
682611a0fb89 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
f7bcb27d1940 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
682611a0fb89 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
3ffe978a5664 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
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    50
these functions produce for the list \texttt{List("a", "b", "b")},
f7bcb27d1940 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
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    53
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    54
$ scala -cp danube.jar
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    55
scala> val ratings_url =
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    56
     | """https://nms.kcl.ac.uk/christian.urban/ratings.csv"""
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    57
396
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    58
scala> M2.get_csv_url(ratings_url)
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    59
val res0: List[String] = List(1,1,4 ...)
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    60
\end{lstlisting}%$
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    61
f7bcb27d1940 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    64
\noindent
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    65
Use \texttt{.split(",").toList} for splitting
682611a0fb89 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
c3b33c709696 updated
Christian Urban <urbanc@in.tum.de>
parents: 284
diff changeset
    67
\texttt{.getOrElse(..,..)} allows to query a Map, but also gives a
203
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    69
using \texttt{+}, \texttt{.contains} and \texttt{.filter} can test whether
eb188f9ac038 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,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    71
\texttt{.sortBy(\_.\_2)} sorts a list of pairs according to the second
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    72
elements in the pairs---the sorting is done from smallest to highest,
eb188f9ac038 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
eb188f9ac038 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
f7bcb27d1940 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
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    80
\subsection*{Main Part 2 (6 Marks, file danube.scala)}
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    81
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    83
in online movie renting. You know that you can save money by
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    84
anticipating what movies people will rent; you will pass these savings
eb188f9ac038 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
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    88
Your task is to generate \emph{two} movie recommendations for every
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    89
movie a user rents. To do this, you calculate what other
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    90
renters, who also watched this movie, suggest by giving positive ratings.
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    92
the two most-frequently suggested movies. Return fewer recommendations,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    93
if there are fewer movies suggested.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    94
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    96
GroupLens provides for education and development purposes.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    97
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    98
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    99
\url{https://grouplens.org/datasets/movielens/}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   100
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   101
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   102
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   103
The slightly adapted CSV-files should be downloaded in your Scala
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   104
file from the URLs:
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   105
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   106
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   107
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   108
\begin{tabular}{ll}  
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   109
  \url{https://nms.kcl.ac.uk/christian.urban/ratings.csv} & (940 KByte)\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   110
  \url{https://nms.kcl.ac.uk/christian.urban/movies.csv}  & (280 KByte)\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   111
\end{tabular}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   112
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   113
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   114
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   115
The ratings.csv file is organised as userID, 
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   117
being 4 and 5). The file movie.csv is organised as
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   118
movieID and full movie name. Both files still contain the usual
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   119
CSV-file header (first line). In this part you are asked
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   120
to implement functions that process these files. If bandwidth
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   122
version use \texttt{Source.fromURL} instead of \texttt{Source.fromFile}.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   123
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   126
\begin{itemize}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   127
\item[(1)] Implement the function \pcode{get_csv_url} which takes an
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   128
  URL-string as argument and requests the corresponding file. The two
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   129
  URLs of interest are \pcode{ratings_url} and \pcode{movies_url},
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   130
  which correspond to CSV-files mentioned above.  The function should
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   131
  return the CSV-file appropriately broken up into lines, and the
eb188f9ac038 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).
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   134
  the url does not produce a file, return the empty list.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   135
  \mbox{}\hfill [1 Mark]
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   136
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   137
\item[(2)] Implement two functions that process the (broken up)
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   138
  CSV-files from (1). The \pcode{process_ratings} function filters out all
eb188f9ac038 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
24bc76d97db2 updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   140
  \pcode{process_movies} function returns a list of (movieID, title) pairs.
24bc76d97db2 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
24bc76d97db2 updated
Christian Urban <urbanc@in.tum.de>
parents: 329
diff changeset
   142
  \pcode{get_csv_url}.\\
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   143
  \mbox{}\hfill [1 Mark]
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   144
%\end{itemize}  
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   145
%  
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   146
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   147
%\subsection*{Part 3 (4 Marks, file danube.scala)}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   148
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   149
%\subsection*{Tasks}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   150
%
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   151
%\begin{itemize}
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   152
\item[(3)] Implement a kind of grouping function that calculates a Map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   153
  containing the userIDs and all the corresponding recommendations for
259
43995ea34fe7 updated
Christian Urban <urbanc@in.tum.de>
parents: 251
diff changeset
   154
  this user (list of movieIDs). This should be implemented in a
43995ea34fe7 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   156
  \pcode{Map()} at the beginning of the calculation. For example
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   157
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   158
\begin{lstlisting}[numbers=none]
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   159
val lst = List(("1", "a"), ("1", "b"),
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   160
               ("2", "x"), ("3", "a"),
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   161
               ("2", "y"), ("3", "c"))
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   162
groupById(lst, Map())
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   163
\end{lstlisting}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   164
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   165
returns the ratings map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   166
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   167
\begin{center}
eb188f9ac038 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))}.
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   169
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   170
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   171
\noindent
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   172
In which order the elements of the list are given is unimportant.\\
eb188f9ac038 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
eb188f9ac038 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
63a1376cbebd updated
Christian Urban <urbanc@in.tum.de>
parents: 203
diff changeset
   176
  as arguments.  The function calculates all suggestions containing the
63a1376cbebd 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
eb188f9ac038 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
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   179
  movie deleted, otherwise it might happen we recommend the same movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   180
  ``back''). For example for the Map from above and the movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   181
  \pcode{"y"} we obtain \pcode{List(List("x"))}, and for the movie
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   182
  \pcode{"a"} we get \pcode{List(List("b"), List("c"))}.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   183
  \mbox{}\hfill [1 Mark]
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   184
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   185
\item[(5)] Implement a suggestions function which takes a ratings map
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   186
  and a movieID as arguments. It calculates all the recommended movies
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   187
  sorted according to the most frequently suggested movie(s) sorted
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   188
  first. This function returns \emph{all} suggested movieIDs as a list of
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   189
  strings.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   190
  \mbox{}\hfill [1 Mark]
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   191
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   192
\item[(6)]  
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   193
  Implement then a recommendation function which generates a maximum
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   194
  of two most-suggested movies (as calculated above). But it returns
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   195
  the actual movie name, not the movieID. If fewer movies are recommended,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   196
  then return fewer than two movie names.\\
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   197
  \mbox{}\hfill [1 Mark]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   198
396
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   199
%\item[(7)] Calculate the recommendations for all movies according to
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   200
% what the recommendations function in (6) produces (this
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   201
% can take a few seconds). Put all recommendations into a list 
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   202
% (of strings) and count how often the strings occur in
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   203
% this list. This produces a list of string-int pairs,
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   204
% where the first component is the movie name and the second
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   205
% is the number of how many times the movie was recommended. 
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   206
% Sort all the pairs according to the number
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   207
% of times they were recommended (most recommended movie name 
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   208
% first).\\
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
   209
% \mbox{}\hfill [1 Mark]
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   210
  
203
eb188f9ac038 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
e43f7e92ba26 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
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   219
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   220
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   221