constraints.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_LMNN_CONSTRAINTS_HPP
13 #define MLPACK_METHODS_LMNN_CONSTRAINTS_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace lmnn {
30 template<typename MetricType = metric::SquaredEuclideanDistance>
32 {
33  public:
36  KNN;
37 
45  Constraints(const arma::mat& dataset,
46  const arma::Row<size_t>& labels,
47  const size_t k);
48 
58  void TargetNeighbors(arma::Mat<size_t>& outputMatrix,
59  const arma::mat& dataset,
60  const arma::Row<size_t>& labels,
61  const arma::vec& norms);
62 
74  void TargetNeighbors(arma::Mat<size_t>& outputMatrix,
75  const arma::mat& dataset,
76  const arma::Row<size_t>& labels,
77  const arma::vec& norms,
78  const size_t begin,
79  const size_t batchSize);
80 
90  void Impostors(arma::Mat<size_t>& outputMatrix,
91  const arma::mat& dataset,
92  const arma::Row<size_t>& labels,
93  const arma::vec& norms);
94 
105  void Impostors(arma::Mat<size_t>& outputNeighbors,
106  arma::mat& outputDistance,
107  const arma::mat& dataset,
108  const arma::Row<size_t>& labels,
109  const arma::vec& norms);
110 
122  void Impostors(arma::Mat<size_t>& outputMatrix,
123  const arma::mat& dataset,
124  const arma::Row<size_t>& labels,
125  const arma::vec& norms,
126  const size_t begin,
127  const size_t batchSize);
128 
141  void Impostors(arma::Mat<size_t>& outputNeighbors,
142  arma::mat& outputDistance,
143  const arma::mat& dataset,
144  const arma::Row<size_t>& labels,
145  const arma::vec& norms,
146  const size_t begin,
147  const size_t batchSize);
148 
162  void Impostors(arma::Mat<size_t>& outputNeighbors,
163  arma::mat& outputDistance,
164  const arma::mat& dataset,
165  const arma::Row<size_t>& labels,
166  const arma::vec& norms,
167  const arma::uvec& points,
168  const size_t numPoints);
169 
179  void Triplets(arma::Mat<size_t>& outputMatrix,
180  const arma::mat& dataset,
181  const arma::Row<size_t>& labels,
182  const arma::vec& norms);
183 
185  const size_t& K() const { return k; }
187  size_t& K() { return k; }
188 
190  const bool& PreCalulated() const { return precalculated; }
192  bool& PreCalulated() { return precalculated; }
193 
194  private:
196  size_t k;
197 
199  arma::Row<size_t> uniqueLabels;
200 
202  std::vector<arma::uvec> indexSame;
203 
205  std::vector<arma::uvec> indexDiff;
206 
208  bool precalculated;
209 
214  inline void Precalculate(const arma::Row<size_t>& labels);
215 
220  inline void ReorderResults(const arma::mat& distances,
221  arma::Mat<size_t>& neighbors,
222  const arma::vec& norms);
223 };
224 
225 } // namespace lmnn
226 } // namespace mlpack
227 
228 // Include implementation.
229 #include "constraints_impl.hpp"
230 
231 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
const size_t & K() const
Get the number of target neighbors (k).
void Impostors(arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
Calculates k differently labeled nearest neighbors for each datapoint and writes them back to passed ...
Interface for generating distance based constraints on a given dataset, provided corresponding true l...
Definition: constraints.hpp:31
neighbor::NeighborSearch< neighbor::NearestNeighborSort, MetricType > KNN
Convenience typedef.
Definition: constraints.hpp:36
bool & PreCalulated()
Modify the value of precalculated.
void Triplets(arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
Generate triplets {i, j, l} for each datapoint i and writes back generated triplets to matrix passed...
void TargetNeighbors(arma::Mat< size_t > &outputMatrix, const arma::mat &dataset, const arma::Row< size_t > &labels, const arma::vec &norms)
Calculates k similar labeled nearest neighbors and stores them into the passed matrix.
Constraints(const arma::mat &dataset, const arma::Row< size_t > &labels, const size_t k)
Constructor for creating a Constraints instance.
size_t & K()
Modify the number of target neighbors (k).
const bool & PreCalulated() const
Access the boolean value of precalculated.