/usr/include/mlpack/methods/nca/nca.hpp is in libmlpack-dev 2.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | /**
* @file nca.hpp
* @author Ryan Curtin
*
* Declaration of NCA class (Neighborhood Components Analysis).
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_METHODS_NCA_NCA_HPP
#define MLPACK_METHODS_NCA_NCA_HPP
#include <mlpack/core.hpp>
#include <mlpack/core/metrics/lmetric.hpp>
#include <mlpack/core/optimizers/sgd/sgd.hpp>
#include "nca_softmax_error_function.hpp"
namespace mlpack {
namespace nca /** Neighborhood Components Analysis. */ {
/**
* An implementation of Neighborhood Components Analysis, both a linear
* dimensionality reduction technique and a distance learning technique. The
* method seeks to improve k-nearest-neighbor classification on a dataset by
* scaling the dimensions. The method is nonparametric, and does not require a
* value of k. It works by using stochastic ("soft") neighbor assignments and
* using optimization techniques over the gradient of the accuracy of the
* neighbor assignments.
*
* For more details, see the following published paper:
*
* @code
* @inproceedings{Goldberger2004,
* author = {Goldberger, Jacob and Roweis, Sam and Hinton, Geoff and
* Salakhutdinov, Ruslan},
* booktitle = {Advances in Neural Information Processing Systems 17},
* pages = {513--520},
* publisher = {MIT Press},
* title = {{Neighbourhood Components Analysis}},
* year = {2004}
* }
* @endcode
*/
template<typename MetricType = metric::SquaredEuclideanDistance,
template<typename> class OptimizerType = optimization::SGD>
class NCA
{
public:
/**
* Construct the Neighborhood Components Analysis object. This simply stores
* the reference to the dataset and labels as well as the parameters for
* optimization before the actual optimization is performed.
*
* @param dataset Input dataset.
* @param labels Input dataset labels.
* @param stepSize Step size for stochastic gradient descent.
* @param maxIterations Maximum iterations for stochastic gradient descent.
* @param tolerance Tolerance for termination of stochastic gradient descent.
* @param shuffle Whether or not to shuffle the dataset during SGD.
* @param metric Instantiated metric to use.
*/
NCA(const arma::mat& dataset,
const arma::Row<size_t>& labels,
MetricType metric = MetricType());
/**
* Perform Neighborhood Components Analysis. The output distance learning
* matrix is written into the passed reference. If LearnDistance() is called
* with an outputMatrix which has the correct size (dataset.n_rows x
* dataset.n_rows), that matrix will be used as the starting point for
* optimization.
*
* @param output_matrix Covariance matrix of Mahalanobis distance.
*/
void LearnDistance(arma::mat& outputMatrix);
//! Get the dataset reference.
const arma::mat& Dataset() const { return dataset; }
//! Get the labels reference.
const arma::Row<size_t>& Labels() const { return labels; }
//! Get the optimizer.
const OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer() const
{ return optimizer; }
OptimizerType<SoftmaxErrorFunction<MetricType> >& Optimizer()
{ return optimizer; }
private:
//! Dataset reference.
const arma::mat& dataset;
//! Labels reference.
const arma::Row<size_t>& labels;
//! Metric to be used.
MetricType metric;
//! The function to optimize.
SoftmaxErrorFunction<MetricType> errorFunction;
//! The optimizer to use.
OptimizerType<SoftmaxErrorFunction<MetricType> > optimizer;
};
} // namespace nca
} // namespace mlpack
// Include the implementation.
#include "nca_impl.hpp"
#endif
|