Skip to content

Commit 22f60dd

Browse files
wdevazelhesbellet
authored andcommitted
[MRG] Add documentation for supervised classes and add __init__ docstrings to doc (#115)
* FEAT: Add documentation for supervised classes * Add doc for ITML, and put mlkr to the right place in index * FIX: update doc * FIX: add __init__ docstrings in doc * FIX: Update doc to suit regression too * STY: add points at end of docstrings * MAINT: address #115 (review) * DOC: fix semi to weakly supervised
1 parent c5f3175 commit 22f60dd

16 files changed

+82
-19
lines changed

doc/index.rst

+29-6
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+9-3
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,22 @@ class ITML_Supervised(ITML):
145145
def __init__(self, gamma=1., max_iter=1000, convergence_threshold=1e-3,
146146
num_labeled=np.inf, num_constraints=None, bounds=None, A0=None,
147147
verbose=False):
148-
"""Initialize the learner.
148+
"""Initialize the supervised version of `ITML`.
149+
150+
`ITML_Supervised` creates pairs of similar sample by taking same class
151+
samples, and pairs of dissimilar samples by taking different class
152+
samples. It then passes these pairs to `ITML` for training.
149153
150154
Parameters
151155
----------
152156
gamma : float, optional
153157
value for slack variables
154158
max_iter : int, optional
155159
convergence_threshold : float, optional
156-
num_labeled : int, optional
157-
number of labels to preserve for training
160+
num_labeled : int, optional (default=np.inf)
161+
number of labeled points to keep for building pairs. Extra
162+
labeled points will be considered unlabeled, and ignored as such.
163+
Use np.inf (default) to use all labeled points.
158164
num_constraints: int, optional
159165
number of constraints to generate
160166
bounds : list (pos,neg) pairs, optional

metric_learn/lsml.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,23 @@ def _gradient(self, metric):
134134
class LSML_Supervised(LSML):
135135
def __init__(self, tol=1e-3, max_iter=1000, prior=None, num_labeled=np.inf,
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
----------
141146
tol : float, optional
142147
max_iter : int, optional
143148
prior : (d x d) matrix, optional
144149
guess at a metric [default: covariance(X)]
145-
num_labeled : int, optional
146-
number of labels to preserve for training
150+
num_labeled : int, optional (default=np.inf)
151+
number of labeled points to keep for building quadruplets. Extra
152+
labeled points will be considered unlabeled, and ignored as such.
153+
Use np.inf (default) to use all labeled points.
147154
num_constraints: int, optional
148155
number of constraints to generate
149156
weights : (m,) array of floats, optional

metric_learn/mmc.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,21 @@ class MMC_Supervised(MMC):
386386
def __init__(self, max_iter=100, max_proj=10000, convergence_threshold=1e-6,
387387
num_labeled=np.inf, num_constraints=None,
388388
A0=None, diagonal=False, 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
----------
393397
max_iter : int, optional
394398
max_proj : int, optional
395399
convergence_threshold : float, optional
396-
num_labeled : int, optional
397-
number of labels to preserve for training
400+
num_labeled : int, optional (default=np.inf)
401+
number of labeled points to keep for building pairs. Extra
402+
labeled points will be considered unlabeled, and ignored as such.
403+
Use np.inf (default) to use all labeled points.
398404
num_constraints: int, optional
399405
number of constraints to generate
400406
A0 : (d x d) matrix, optional

metric_learn/rca.py

+5-1
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

+10-3
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_labeled=np.inf, 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
@@ -92,8 +97,10 @@ def __init__(self, balance_param=0.5, sparsity_param=0.01, use_cov=True,
9297
trade off between optimizer and sparseness (see graph_lasso)
9398
use_cov : bool, optional
9499
controls prior matrix, will use the identity if use_cov=False
95-
num_labeled : int, optional
96-
number of labels to preserve for training
100+
num_labeled : int, optional (default=np.inf)
101+
number of labeled points to keep for building pairs. Extra
102+
labeled points will be considered unlabeled, and ignored as such.
103+
Use np.inf (default) to use all labeled points.
97104
num_constraints : int, optional
98105
number of constraints to generate
99106
verbose : bool, optional

0 commit comments

Comments
 (0)