Skip to content

Commit 0c0156f

Browse files
author
William de Vazelhes
committed
Merge branch 'master' into fix/remove_num_labeled_parameter
# Conflicts: # metric_learn/itml.py # metric_learn/lsml.py # metric_learn/mmc.py # metric_learn/sdml.py
2 parents ab4e1a6 + 22f60dd commit 0c0156f

16 files changed

+66
-11
lines changed

doc/index.rst

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,45 @@ metrics.
1313
This package contains efficient Python implementations of several popular
1414
metric learning algorithms.
1515

16+
Supervised Algorithms
17+
---------------------
18+
Supervised metric learning algorithms take as inputs points `X` and target
19+
labels `y`, and learn a distance matrix that make points from the same class
20+
(for classification) or with close target value (for regression) close to
21+
each other, and points from different classes or with distant target values
22+
far away from each other.
23+
1624
.. toctree::
17-
:caption: Algorithms
1825
:maxdepth: 1
1926

2027
metric_learn.covariance
2128
metric_learn.lmnn
22-
metric_learn.itml
23-
metric_learn.sdml
24-
metric_learn.lsml
2529
metric_learn.nca
2630
metric_learn.lfda
31+
metric_learn.mlkr
32+
33+
Weakly-Supervised Algorithms
34+
--------------------------
35+
Weakly supervised algorithms work on weaker information about the data points
36+
than supervised algorithms. Rather than labeled points, they take as input
37+
similarity judgments on tuples of data points, for instance pairs of similar
38+
and dissimilar points. Refer to the documentation of each algorithm for its
39+
particular form of input data.
40+
41+
.. toctree::
42+
:maxdepth: 1
43+
44+
metric_learn.itml
45+
metric_learn.lsml
46+
metric_learn.sdml
2747
metric_learn.rca
2848
metric_learn.mmc
29-
metric_learn.mlkr
3049

31-
Each metric supports the following methods:
50+
Note that each weakly-supervised algorithm has a supervised version of the form
51+
`*_Supervised` where similarity constraints are generated from
52+
the labels information and passed to the underlying algorithm.
53+
54+
Each metric learning algorithm supports the following methods:
3255

3356
- ``fit(...)``, which learns the model.
3457
- ``transformer()``, which returns a transformation matrix

doc/metric_learn.covariance.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Covariance metric (baseline method)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.itml.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Information Theoretic Metric Learning (ITML)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.lfda.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Local Fisher Discriminant Analysis (LFDA)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.lmnn.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Large Margin Nearest Neighbor (LMNN)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.lsml.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Least Squares Metric Learning (LSML)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.mlkr.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Metric Learning for Kernel Regression (MLKR)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.mmc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Mahalanobis Metric Learning for Clustering (MMC)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.nca.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Neighborhood Components Analysis (NCA)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.rca.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Relative Components Analysis (RCA)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

doc/metric_learn.sdml.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Sparse Determinant Metric Learning (SDML)
66
:undoc-members:
77
:inherited-members:
88
:show-inheritance:
9+
:special-members: __init__
910

1011
Example Code
1112
------------

metric_learn/itml.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ class ITML_Supervised(ITML):
144144
"""Information Theoretic Metric Learning (ITML)"""
145145
def __init__(self, gamma=1., max_iter=1000, convergence_threshold=1e-3,
146146
num_constraints=None, bounds=None, A0=None, verbose=False):
147-
"""Initialize the learner.
147+
"""Initialize the supervised version of `ITML`.
148+
149+
`ITML_Supervised` creates pairs of similar sample by taking same class
150+
samples, and pairs of dissimilar samples by taking different class
151+
samples. It then passes these pairs to `ITML` for training.
148152
149153
Parameters
150154
----------

metric_learn/lsml.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ def _gradient(self, metric):
134134
class LSML_Supervised(LSML):
135135
def __init__(self, tol=1e-3, max_iter=1000, prior=None,
136136
num_constraints=None, weights=None, verbose=False):
137-
"""Initialize the learner.
137+
"""Initialize the supervised version of `LSML`.
138+
139+
`LSML_Supervised` creates quadruplets from labeled samples by taking two
140+
samples from the same class, and two samples from different classes.
141+
This way it builds quadruplets where the two first points must be more
142+
similar than the two last points.
138143
139144
Parameters
140145
----------

metric_learn/mmc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,11 @@ class MMC_Supervised(MMC):
386386
def __init__(self, max_iter=100, max_proj=10000, convergence_threshold=1e-6,
387387
num_constraints=None, A0=None, diagonal=False,
388388
diagonal_c=1.0, verbose=False):
389-
"""Initialize the learner.
389+
"""Initialize the supervised version of `MMC`.
390+
391+
`MMC_Supervised` creates pairs of similar sample by taking same class
392+
samples, and pairs of dissimilar samples by taking different class
393+
samples. It then passes these pairs to `MMC` for training.
390394
391395
Parameters
392396
----------

metric_learn/rca.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def _inv_sqrtm(x):
138138
class RCA_Supervised(RCA):
139139
def __init__(self, num_dims=None, pca_comps=None, num_chunks=100,
140140
chunk_size=2):
141-
"""Initialize the learner.
141+
"""Initialize the supervised version of `RCA`.
142+
143+
`RCA_Supervised` creates chunks of similar points by first sampling a
144+
class, taking `chunk_size` elements in it, and repeating the process
145+
`num_chunks` times.
142146
143147
Parameters
144148
----------

metric_learn/sdml.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ def fit(self, X, W):
8383
class SDML_Supervised(SDML):
8484
def __init__(self, balance_param=0.5, sparsity_param=0.01, use_cov=True,
8585
num_constraints=None, verbose=False):
86-
"""
86+
"""Initialize the supervised version of `SDML`.
87+
88+
`SDML_Supervised` creates pairs of similar sample by taking same class
89+
samples, and pairs of dissimilar samples by taking different class
90+
samples. It then passes these pairs to `SDML` for training.
91+
8792
Parameters
8893
----------
8994
balance_param : float, optional

0 commit comments

Comments
 (0)