Skip to content

Commit a4cd942

Browse files
author
Burak Bayramli
committed
-
1 parent d948818 commit a4cd942

39 files changed

+5589
-0
lines changed

algs/mstseg/felz/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

algs/mstseg/felz/COPYING

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

algs/mstseg/felz/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
### Felzenszwalb Clustering
2+
3+
Using a distance matrix containing pairwise distances (which could use
4+
any measure) Felzenszwalb Clustering will print cluster membership per
5+
datapoint.
6+
7+
The code is based on Felzenszwalb and Huttenlocher paper and shared
8+
C++ code. I simply took out the clustering code from inside the
9+
segmentation, so this project does not have any references to image
10+
processing, it simply does clustering with any given distance matrix.
11+
12+
http://cs.brown.edu/~pff/segment/
13+
14+
The C++ version reads sparse matrices from mtx (money market
15+
format). Python version can be used as any clustering algorithm found
16+
in `scikit-learn`, through constructor and `fit` function.
17+
18+
The main advantage of the algorithm is its ability to use any distance
19+
metric, its accuracy (as known from Felzenszwalb image segmentation),
20+
its speed, and determining the number of clusters on its own. The
21+
algorithm which is at the root of Felzenszwalb clustering is Minimum
22+
Spanning Tree which is known to have O(E log E) complexity where E is
23+
the number of edges in a graph. In comparison, other clustering
24+
methods presented here,
25+
26+
http://scikit-learn.org/stable/modules/clustering.html
27+
28+
such as Affinity Propagation, or Spectral Clustering do not enjoy the
29+
same level of performance and cannot handle large datasets.
30+
31+
32+
## Building
33+
34+
`cd felzclust`
35+
36+
`make`
37+
38+
For Python version simple import is sufficient.
39+
40+
## Running
41+
42+
See `doc/test.pdf` or `felzclust/test.py` for details. The distance
43+
matrix should be in sparse form, in mtx format. A simple use case
44+
45+
`felzclust/felzclust felzclust/simple.mtx 1.0 1`
46+
47+
You will see output
48+
49+
```
50+
point;cluster
51+
0;2
52+
1;2
53+
2;2
54+
3;4
55+
4;4
56+
```
57+
58+
A bigger example
59+
60+
![](./doc/test_02.png)
61+
62+
![](./doc/test_01.png)
63+
64+
## Pure Python
65+
66+
Pure Python version of the code can be found under `felz.py` and `test_felz.py`
67+
68+
## LICENSE
69+
70+
The software is licensed under GPL v2. See COPYING for details.

algs/mstseg/felz/doc/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.aux
2+
*.log
3+
*.out
4+
_region*

algs/mstseg/felz/doc/common.sty

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
\usepackage{palatino,eulervm}
2+
\usepackage{showkeys}\renewcommand*\showkeyslabelformat[1]{(#1)}
3+
\usepackage{anysize}
4+
\marginsize{3cm}{3cm}{1cm}{3cm}
5+
\setlength{\parindent}{0pt}
6+
\usepackage{graphicx}
7+
\usepackage{cancel}
8+
\usepackage[latin5]{inputenc}
9+
\usepackage{color}
10+
\setlength{\parskip}{8pt}
11+
\setlength{\parsep}{0pt}
12+
\setlength{\headsep}{0pt}
13+
\setlength{\topskip}{0pt}
14+
\setlength{\topmargin}{0pt}
15+
\setlength{\topsep}{0pt}
16+
\setlength{\partopsep}{0pt}
17+
\setlength{\mathindent}{0cm}
18+
\usepackage{latexsym}
19+
\usepackage{amsfonts}
20+
\usepackage{mathrsfs}
21+
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
22+
\usepackage{minted}
23+
\usepackage{marginnote}
24+
\newcommand*\mlabel[1]{\marginnote{(#1)}}
25+
\usepackage[hyphens]{url}
26+
\usepackage{hyperref}
27+
\makeatletter \renewcommand\verbatim@font{\footnotesize\ttfamily} \makeatother
28+
% pseudocode
29+
\usepackage{algorithm}
30+
\newcommand{\code}[1]{\mbox{\texttt{#1}}}
31+
\newcounter{lineno}
32+
\newenvironment{pseudocode}{\begin{small}\begin{tabbing}\textbf{mm}\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=mm\=\kill}{\end{tabbing}\end{small}}
33+
\newcommand{\codename}{\setcounter{lineno}{0}\>}
34+
\newcommand{\codeline}{\>\stepcounter{lineno}\textbf{\arabic{lineno}}\'\>}
35+
\newcommand{\codeskip}{\>\>}

algs/mstseg/felz/doc/doc.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pdflatex -shell-escape test.tex
2+
evince test.pdf

algs/mstseg/felz/doc/simple.tex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Simple data generation
2+
3+
\begin{minted}[fontsize=\footnotesize]{python}
4+
import scipy.sparse as sps
5+
from scipy.io import mmwrite, mmread
6+
A = sps.lil_matrix((5,5))
7+
A[0,1] = 0.5
8+
A[1,0] = 0.5
9+
A[1,2] = 1.0
10+
A[2,1] = 1.0
11+
A[2,3] = 0.33
12+
A[3,2] = 0.33
13+
A[0,4] = 0.5
14+
A[4,0] = 0.5
15+
mmwrite('./felzclust/simple.mtx',A)
16+
\end{minted}
17+
18+

0 commit comments

Comments
 (0)