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 
57  void TargetNeighbors(arma::Mat<size_t>& outputMatrix,
58  const arma::mat& dataset,
59  const arma::Row<size_t>& labels,
60  const arma::vec& norms);
61 
72  void TargetNeighbors(arma::Mat<size_t>& outputMatrix,
73  const arma::mat& dataset,
74  const arma::Row<size_t>& labels,
75  const arma::vec& norms,
76  const size_t begin,
77  const size_t batchSize);
78 
87  void Impostors(arma::Mat<size_t>& outputMatrix,
88  const arma::mat& dataset,
89  const arma::Row<size_t>& labels,
90  const arma::vec& norms);
91 
101  void Impostors(arma::Mat<size_t>& outputNeighbors,
102  arma::mat& outputDistance,
103  const arma::mat& dataset,
104  const arma::Row<size_t>& labels,
105  const arma::vec& norms);
106 
117  void Impostors(arma::Mat<size_t>& outputMatrix,
118  const arma::mat& dataset,
119  const arma::Row<size_t>& labels,
120  const arma::vec& norms,
121  const size_t begin,
122  const size_t batchSize);
123 
135  void Impostors(arma::Mat<size_t>& outputNeighbors,
136  arma::mat& outputDistance,
137  const arma::mat& dataset,
138  const arma::Row<size_t>& labels,
139  const arma::vec& norms,
140  const size_t begin,
141  const size_t batchSize);
142 
155  void Impostors(arma::Mat<size_t>& outputNeighbors,
156  arma::mat& outputDistance,
157  const arma::mat& dataset,
158  const arma::Row<size_t>& labels,
159  const arma::vec& norms,
160  const arma::uvec& points,
161  const size_t numPoints);
162 
171  void Triplets(arma::Mat<size_t>& outputMatrix,
172  const arma::mat& dataset,
173  const arma::Row<size_t>& labels,
174  const arma::vec& norms);
175 
177  const size_t& K() const { return k; }
179  size_t& K() { return k; }
180 
182  const bool& PreCalulated() const { return precalculated; }
184  bool& PreCalulated() { return precalculated; }
185 
186  private:
188  size_t k;
189 
191  arma::Row<size_t> uniqueLabels;
192 
194  std::vector<arma::uvec> indexSame;
195 
197  std::vector<arma::uvec> indexDiff;
198 
200  bool precalculated;
201 
206  inline void Precalculate(const arma::Row<size_t>& labels);
207 
212  inline void ReorderResults(const arma::mat& distances,
213  arma::Mat<size_t>& neighbors,
214  const arma::vec& norms);
215 };
216 
217 } // namespace lmnn
218 } // namespace mlpack
219 
220 // Include implementation.
221 #include "constraints_impl.hpp"
222 
223 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
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.