public class LargeMarginDimensionalityReduction extends Object
LargeMarginDimensionalityReduction
is a technique to compress high
dimensional features into a lower-dimension representation using a learned
linear projection. Supervised learning is used to learn the projection such
that the squared Euclidean distance between two low-dimensional vectors is
less than a threshold if they correspond to the same object, or greater
otherwise. In addition, it is imposed that this condition is satisfied with a
margin of at least one.
In essence, the Euclidean distance in the low dimensional space produced by this technique can be seen as a low-rank Mahalanobis metric in the original space; the Mahalanobis matrix would have rank equal to the number of dimensions of the smaller space.
This class implements the technique using stochastic sub-gradient descent. As the objective function is not convex, initialisation is important, and initial conditions are generated by selecting the largest PCA dimensions, and then whitening the dimensions so they have equal magnitude. In addition, the projection matrix is not regularised explicitly; instead the algorithm is just stopped after a fixed number of iterations.
Modifier and Type | Field and Description |
---|---|
protected double |
b |
protected double |
bLearnRate |
protected int |
ndims |
protected Jama.Matrix |
W |
protected double |
wLearnRate |
Constructor and Description |
---|
LargeMarginDimensionalityReduction(int ndims)
Construct with the given target dimensionality and default values for the
other parameters (learning rate of 1.0 for W; learning rate of 0 for
bias).
|
LargeMarginDimensionalityReduction(int ndims,
double wLearnRate,
double bLearnRate)
Construct with the given target dimensionality learning rates.
|
Modifier and Type | Method and Description |
---|---|
boolean |
classify(double[] phii,
double[] phij)
Determine if two features are from the same class or different classes.
|
double |
getBias()
Get the bias, b
|
Jama.Matrix |
getTransform()
Get the transform matrix W
|
void |
initialise(double[][] datai,
double[][] dataj,
boolean[] same)
Initialise the LMDR with the given data in three parallel data arrays.
|
double[] |
project(double[] in)
Compute the low rank estimate of the given vector
|
void |
recomputeBias(double[][] datai,
double[][] dataj,
boolean[] same) |
double |
score(double[] phii,
double[] phij)
Compute the matching score between a pair of (high dimensional) features.
|
void |
setBias(double d) |
void |
setTransform(Jama.Matrix proj) |
boolean |
step(double[] phii,
double[] phij,
boolean same)
Perform a single update step of the SGD optimisation.
|
protected int ndims
protected double wLearnRate
protected double bLearnRate
protected Jama.Matrix W
protected double b
public LargeMarginDimensionalityReduction(int ndims)
ndims
- target number of dimensionspublic LargeMarginDimensionalityReduction(int ndims, double wLearnRate, double bLearnRate)
ndims
- target number of dimensionswLearnRate
- learning rate for the transform matrix, W.bLearnRate
- learning rate for the bias, b.public void initialise(double[][] datai, double[][] dataj, boolean[] same)
Internally, this method gathers together all the vectors and performs
ThinSvdPrincipalComponentAnalysis
to get a starting estimate for
the transform matrix. The distance in the projected space between all
true pairs and false pairs is computed and used to select an optimal
initial threshold.
datai
- array of the first vectors of the pairsdataj
- array of the second vectors of the pairssame
- array indicating where pairs are true (from the same class) or
false (from different classes)public void recomputeBias(double[][] datai, double[][] dataj, boolean[] same)
public boolean step(double[] phii, double[] phij, boolean same)
phii
- first vectorphij
- second vectorsame
- true if the vectors are from the same class; false otherwisepublic Jama.Matrix getTransform()
public double getBias()
public double score(double[] phii, double[] phij)
phii
- first vectorphij
- second vectorpublic boolean classify(double[] phii, double[] phij)
phii
- first vectorphij
- second vectorpublic double[] project(double[] in)
in
- the vectorpublic void setBias(double d)
public void setTransform(Jama.Matrix proj)