Skip to content
UoL CS Notes

Home

This website houses notes from my studies at the University of Liverpool. If you see any errors or issues, please do open an issue on this site's GitHub.

Lecture 22-1

COMP105 Lectures

Recursive Types We have seen types which contain other types. In a recursive custom type, some constructors contain the type itself. data IntList = Empty | Cons Int IntList deriving(Show) Some examples using this type: Empty -- [] Cons 1 (Empty) -- [1] Cons 1 (Cons 2 Empty) -- [1,2]...

Read More

Relations - 10

COMP109 Lectures

All the relations we have been looking at so far have been binary relations however this can be generalised for greater numbered relations. $n$-ary Relations The Cartesian product $A_1\times A_2\times \ldots \times A_n$ of sets $A_1,A_2,\ldots,A_n$ is defined by: \[\begin{aligned} A_1\times A_2\times \ldots \times A_n=&\\ \{(a_1,\ldots,a_n)\ \vert\ a_1\in A_1,\ldots,a_n\in A_n\}&...

Read More

Relations - 9

COMP109 Lectures

Partial Orders A binary relation $R$ on set $A$ which is reflexive, transitive and antisymmetric is called a partial order. Partial orders are important in situations where we wish to characterise precedence. Examples The relation $\leq$ on the set of $\Bbb{R}$ of real numbers. The relation $\subseteq$ on $\text{Pow}(A)$. “Is...

Read More

Tutorial 4

COMP107 Tutorials

ER by View Integration You should consider each user perspective separately. Requirements are given for many users groups or applications independently. an ER schema is designed for each user group and application (typically by different developers.) Individual views are merged into a global conceptual schema. Individual views can be reconstructed...

Read More

Relations - 8

COMP109 Lectures

Equivalence Relations A binary relation $R$ on a set $A$ is called an equivalence relation if it is reflective, transitive and symmetric. This is the same as $x=y$ in that $x$ has the same property as $y$. Example 1 The relation $R$ on the non-zero integers given by $xRy$ if...

Read More

Lecture 21-2

COMP105 Lectures

Maybe data Maybe a = Just a | Nothing > :t Just "hello" Maybe [Char] > :t Just False Maybe Bool > :t Nothing Maybe a From here you can see that when you call the Just constructor you force the type variable a to be a particular type and...

Read More

Lecture 21-1

COMP105 Lectures

Parameterised Custom Types Type Variables in Custom Types We can use type variables in custom types: data Point a = Point a a Here we say we are making a new type where the constructor point is made of type a. > :t Point (1::Int) (2::Int) Point Int We can...

Read More

Probabilistic Inference

COMP111 Lectures

Marginalisation Given an joint distribution $\mathbf{P}(F_1,\ldots,F_k)$, one can compute the marginal probabilities of the random variables $F_i$ by summing out the remaining variables. For example: \[\begin{aligned} P(\text{Cavity}=1)&=0.108+0.012+0.072+0.008\\ &=0.2 \end{aligned}\] is the sum of the entries in the first row of:   $\text{Toothache}=1$ $\text{Toothache}=1$ $\text{Toothache}=0$ $\text{Toothache}=0$   $\text{Catch}=1$ $\text{Catch}=0$ $\text{Catch}=1$ $\text{Catch}=0$...

Read More

Joint Probability Distribution

COMP111 Lectures

Examples of Probabilistic Models To model a domain using probability theory, one first introduces the relevant random variable. We have seen two basic examples: The weather domain could be modelled using the single random variable $\text{Weather}$ with values: \[(\text{sunny},\text{rain},\text{cloudy},\text{snow})\] The dentist domain could be modelled using the random variables $\text{Toothache,...

Read More

Relations - 7

COMP109 Lectures

Transitive Closure Given a binary relation $R$ on a set $A$ the transitive closure $R^*$ of $R$ is the (uniquely determined) relation on $A$ with the following properties: $R^*$ is transitive. $R\subseteq R^*$. All links you find in $R$ you should also find in $R^*$. If $S$ is a transitive...

Read More