-
Notifications
You must be signed in to change notification settings - Fork 92
/
irm.Rmd
86 lines (69 loc) · 1.96 KB
/
irm.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: "Final Lecture: Infinite Relational Model"
author: "Jesse Mu"
date: "November 2, 2016"
output:
html_document:
highlight: pygments
toc: yes
toc_float: yes
---
<!-- Setup -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "all"
}
}
});
</script>
```{r echo=FALSE, message=FALSE}
knitr::opts_chunk$set(fig.align = 'center', message = FALSE)
library(knitr)
library(ggplot2)
library(cowplot)
library(reshape)
```
<!-- Begin writing -->
# The Infinite Relational Model
What happens when you want to cluster your data, but the number of clusters is
unknown? While some approaches involve fitting several models with a varying
number of clusters to your data and comparing model fit statistics, the Bayesian
approach is to specify a model which is allowed to dynamically grow the number
of clusters as the complexity of the data warrants.
The **Infinite Relational Model** is the prototypical example of such a model.
> [Kemp et al. (2006). Learning Systems of Concepts with an Infinite Relational Model](http://web.mit.edu/cocosci/Papers/Kemp-etal-AAAI06.pdf)
For this last project, I coded up a simple version of Charles Kemp's Infinite
Relational Model (IRM) in `irm.R` to co-cluster rows and columns of a simple
2-dimensional binary relation.
## Demo
```{r}
source('irm.R')
```
### Sanity check
As a sanity check, we use the toy matrix in the original paper:
```{r}
R = rbind(
c(0, 0, 1, 0, 1, 0, 0, 1, 0),
c(0, 0, 0, 0, 0, 0, 1, 0, 1),
c(0, 0, 1, 0, 0, 0, 1, 0, 1),
c(0, 1, 1, 0, 0, 0, 0, 1, 1),
c(0, 0, 0, 0, 0, 0, 1, 0, 1),
c(0, 1, 1, 0, 1, 0, 0, 1, 0),
c(1, 0, 0, 0, 0, 1, 0, 0, 0),
c(0, 0, 0, 0, 0, 1, 1, 0, 1),
c(1, 0, 0, 1, 0, 1, 0, 0, 0)
)
plot.R(R)
```
```{r}
Z = irm(R, sweeps = 1000)
top.n(Z)
plot.R(R, mode.irm(Z))
```
This successfully finds the clusters of rows and columns that correspond to the original paper.
<!--
TODO: add 50 animals data
### 50 animals
-->