annotate toolboxes/distance_learning/mlr/readme.txt @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 Metric Learning to Rank (mlr-1.0)
Daniel@0 2 http://www-cse.ucsd.edu/~bmcfee/code/mlr/
Daniel@0 3
Daniel@0 4 Brian McFee <bmcfee@cs.ucsd.edu>, 2010.
Daniel@0 5
Daniel@0 6 This code is distributed under the GNU GPL license. See LICENSE for details,
Daniel@0 7 or http://www.gnu.org/licenses/gpl-3.0.txt .
Daniel@0 8
Daniel@0 9
Daniel@0 10
Daniel@0 11 INTRODUCTION
Daniel@0 12 ------------
Daniel@0 13 This package contains the MATLAB code for Metric Learning to Rank (MLR).
Daniel@0 14 The latest version of this software can be found at the URL above.
Daniel@0 15
Daniel@0 16 The software included here implements the algorithm described in
Daniel@0 17
Daniel@0 18 [1] Mcfee, Brian and Lanckriet, G.R.G. Metric learning to rank.
Daniel@0 19 Proceedings of the 27th annual International Conference
Daniel@0 20 on Machine Learning (ICML), 2010.
Daniel@0 21
Daniel@0 22 Please cite this paper if you use this code.
Daniel@0 23
Daniel@0 24
Daniel@0 25
Daniel@0 26 INSTALLATION
Daniel@0 27 ------------
Daniel@0 28
Daniel@0 29 1. Requirements
Daniel@0 30
Daniel@0 31 This software requires MATLAB R2007a or later. Because it makes extensive use
Daniel@0 32 of the "bsxfun" function, earlier versions of Matlab will not work.
Daniel@0 33
Daniel@0 34 If you have an older Matlab installation, you can install an alternative bsxfun
Daniel@0 35 implementation by going to
Daniel@0 36
Daniel@0 37 http://www.mathworks.com/matlabcentral/fileexchange/23005 ,
Daniel@0 38
Daniel@0 39 however, this may not work, and it will certainly be slower than the native
Daniel@0 40 bsxfun implementation.
Daniel@0 41
Daniel@0 42
Daniel@0 43 2. Compiling MEX functions
Daniel@0 44
Daniel@0 45 MLR includes two auxiliary functions "cummax" and "binarysearch" to accelerate
Daniel@0 46 certain steps of the optimization procedure. The source code for these
Daniel@0 47 functions is located in the "util" subdirectory.
Daniel@0 48
Daniel@0 49 A makefile is provided, so that (on Unix systems), you can simply type
Daniel@0 50
Daniel@0 51 cd util
Daniel@0 52 make
Daniel@0 53 cd ..
Daniel@0 54
Daniel@0 55
Daniel@0 56 3. Running the demo
Daniel@0 57
Daniel@0 58 To test the installation, run
Daniel@0 59
Daniel@0 60 mlr_demo
Daniel@0 61
Daniel@0 62 from within Matlab. The demo generates a random training/test split of the Wine data set
Daniel@0 63 http://archive.ics.uci.edu/ml/datasets/Wine
Daniel@0 64 and learns a metric with MLR. Both native and learned metrics are displayed in a figure
Daniel@0 65 with a scatter plot.
Daniel@0 66
Daniel@0 67
Daniel@0 68 TRAINING
Daniel@0 69 --------
Daniel@0 70
Daniel@0 71 There are several modes of operation for training metrics with MLR. In the
Daniel@0 72 simplest mode, training data is contained in a matrix X (each column is a
Daniel@0 73 training vector), and Y contains the labels/relevance for the training data
Daniel@0 74 (see below).
Daniel@0 75
Daniel@0 76 [W, Xi, D] = mlr_train(X, Y, C,...)
Daniel@0 77
Daniel@0 78 X = d*n data matrix
Daniel@0 79 Y = either n-by-1 label of vectors
Daniel@0 80 OR
Daniel@0 81 n-by-2 cell array where
Daniel@0 82 Y{q,1} contains relevant indices for q, and
Daniel@0 83 Y{q,2} contains irrelevant indices for q
Daniel@0 84
Daniel@0 85 C >= 0 slack trade-off parameter (default=1)
Daniel@0 86
Daniel@0 87 W = the learned metric, i.e., the inner product matrix of the learned
Daniel@0 88 space can be computed by X' * W * X
Daniel@0 89 Xi = slack value on the learned metric (see [1])
Daniel@0 90 D = diagnostics
Daniel@0 91
Daniel@0 92
Daniel@0 93 By default, MLR optimizes for Area Under the ROC Curve (AUC). This can be
Daniel@0 94 changed by setting the "LOSS" parameter to one of several ranking loss
Daniel@0 95 measures:
Daniel@0 96
Daniel@0 97 [W, Xi, D] = mlr_train(X, Y, C, LOSS)
Daniel@0 98 where LOSS is one of:
Daniel@0 99 'AUC': Area under ROC curve (default)
Daniel@0 100 'KNN': KNN accuracy*
Daniel@0 101 'Prec@k': Precision-at-k
Daniel@0 102 'MAP': Mean Average Precision
Daniel@0 103 'MRR': Mean Reciprocal Rank
Daniel@0 104 'NDCG': Normalized Discounted Cumulative Gain
Daniel@0 105
Daniel@0 106 *Note: KNN is correct only for binary classification problems; in
Daniel@0 107 practice, Prec@k is usually a better alternative.
Daniel@0 108
Daniel@0 109
Daniel@0 110 For KNN/Prec@k/NDCG, a threshold k may be set to determine the truncation of
Daniel@0 111 the ranked list. Thiscan be done by setting the k parameter:
Daniel@0 112
Daniel@0 113 [W, Xi, D] = mlr_train(X, Y, C, LOSS, k)
Daniel@0 114 where k is the number of neighbors for Prec@k or NDCG
Daniel@0 115 (default=3)
Daniel@0 116
Daniel@0 117
Daniel@0 118 By default, MLR regularizes the metric W by the trace, i.e., the 1-norm of the
Daniel@0 119 eigenvalues. This can be changed to one of several alternatives:
Daniel@0 120
Daniel@0 121 [W, Xi, D] = mlr_train(X, Y, C, LOSS, k, REG)
Daniel@0 122 where REG defines the regularization on W, and is one of:
Daniel@0 123 0: no regularization
Daniel@0 124 1: 1-norm: trace(W) (default)
Daniel@0 125 2: 2-norm: trace(W' * W)
Daniel@0 126 3: Kernel: trace(W * X), assumes X is square
Daniel@0 127 and positive-definite
Daniel@0 128
Daniel@0 129 The last setting, "kernel", is appropriate for regularizing metrics learned
Daniel@0 130 from kernel matrices.
Daniel@0 131
Daniel@0 132
Daniel@0 133 W corresponds to a linear projection matrix (rotation and scaling). To learn a
Daniel@0 134 restricted model which may only scale, but not rotate the data, W can be
Daniel@0 135 constrained to diagonal matrices by setting the "Diagonal" parameter to 1:
Daniel@0 136
Daniel@0 137 [W, Xi, D] = mlr_train(X, Y, C, LOSS, k, REG, Diagonal)
Daniel@0 138 Diagonal = 0: learn a full d-by-d W (default)
Daniel@0 139 Diagonal = 1: learn diagonally-constrained W (d-by-1)
Daniel@0 140
Daniel@0 141 Note: the W returned in this case will be the d-by-1 vector corresponding
Daniel@0 142 to the main diagonal of a full metric, not the full d-by-d matrix.
Daniel@0 143
Daniel@0 144
Daniel@0 145
Daniel@0 146 Finally, we provide a stochastic gradient descent implementation to handle
Daniel@0 147 large-scale problems. Rather than estimating gradients from the entire
Daniel@0 148 training set, this variant uses a random subset of size B (see below) at each
Daniel@0 149 call to the cutting plane subroutine. This results in faster, but less
Daniel@0 150 accurate, optimization:
Daniel@0 151
Daniel@0 152 [W, Xi, D] = mlr_train(X, Y, C, LOSS, k, REG, Diagonal, B)
Daniel@0 153 where B > 0 enables stochastic optimization with batch size B
Daniel@0 154
Daniel@0 155
Daniel@0 156
Daniel@0 157 TESTING
Daniel@0 158 -------
Daniel@0 159
Daniel@0 160 Once a metric has been trained by "mlr_train", you can evaluate performance
Daniel@0 161 across all measures by using the "mlr_test" function:
Daniel@0 162
Daniel@0 163 Perf = mlr_test(W, test_k, Xtrain, Ytrain, Xtest, Ytest)
Daniel@0 164
Daniel@0 165 W = d-by-d positive semi-definite matrix
Daniel@0 166 test_k = vector of k-values to use for KNN/Prec@k/NDCG
Daniel@0 167 Xtrain = d-by-n matrix of training data
Daniel@0 168 Ytrain = n-by-1 vector of training labels
Daniel@0 169 OR
Daniel@0 170 n-by-2 cell array where
Daniel@0 171 Y{q,1} contains relevant indices (in 1..n) for point q
Daniel@0 172 Y{q,2} contains irrelevant indices (in 1..n) for point q
Daniel@0 173 Xtest = d-by-m matrix of testing data
Daniel@0 174 Ytest = m-by-1 vector of training labels, or m-by-2 cell array
Daniel@0 175 If using the cell version, indices correspond to
Daniel@0 176 the training set, and must lie in the range (1..n)
Daniel@0 177
Daniel@0 178
Daniel@0 179 The output structure Perf contains the mean score for:
Daniel@0 180 AUC, KNN, Prec@k, MAP, MRR, NDCG,
Daniel@0 181 as well as the effective dimensionality of W, and
Daniel@0 182 the best-performing k-value for KNN, Prec@k, and NDCG.
Daniel@0 183
Daniel@0 184 For information retrieval settings, consider Xtrain/Ytrain as the corpus
Daniel@0 185 and Xtest/Ytest as the queries.
Daniel@0 186
Daniel@0 187 By testing with
Daniel@0 188 Wnative = eye(size(X,1))
Daniel@0 189 you can quickly evaluate the performance of the native (Euclidean) metric.
Daniel@0 190
Daniel@0 191
Daniel@0 192 FEEDBACK
Daniel@0 193 --------
Daniel@0 194
Daniel@0 195 Please send any bug reports, source code contributions, etc. to
Daniel@0 196
Daniel@0 197 Brian McFee <bmcfee@cs.ucsd.edu>
Daniel@0 198