13 #ifndef MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_IMPL_HPP 14 #define MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_IMPL_HPP 22 template<
typename BoundType,
typename MatType,
size_t MaxNumSamples>
28 size_t vantagePointIndex = 0;
31 SelectVantagePoint(bound.Metric(), data, begin, count, vantagePointIndex, mu);
37 splitInfo =
SplitInfo(bound.Metric(), data.col(vantagePointIndex), mu);
42 template<
typename BoundType,
typename MatType,
size_t MaxNumSamples>
45 const size_t begin,
const size_t count,
size_t& vantagePoint,
ElemType& mu)
47 arma::uvec vantagePointCandidates;
48 arma::Col<ElemType> distances(MaxNumSamples);
52 vantagePointCandidates);
58 for (
size_t i = 0; i < vantagePointCandidates.n_elem; ++i)
65 distances.set_size(samples.n_elem);
67 for (
size_t j = 0; j < samples.n_elem; ++j)
68 distances[j] = metric.Evaluate(data.col(vantagePointCandidates[i]),
69 data.col(samples[j]));
71 const ElemType spread = arma::sum(distances % distances) / samples.n_elem;
73 if (spread > bestSpread)
76 vantagePoint = vantagePointCandidates[i];
79 mu = arma::median(distances);
82 assert(bestSpread > 0);
88 #endif // MLPACK_CORE_TREE_BINARY_SPACE_TREE_VANTAGE_POINT_SPLIT_IMPL_HPP void ObtainDistinctSamples(const size_t loInclusive, const size_t hiExclusive, const size_t maxNumSamples, arma::uvec &distinctSamples)
Obtains no more than maxNumSamples distinct samples.
Definition: random.hpp:153
MatType::elem_type ElemType
The matrix element type.
Definition: vantage_point_split.hpp:36
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static bool SplitNode(const BoundType &bound, MatType &data, const size_t begin, const size_t count, SplitInfo &splitInfo)
Split the node according to the distance to a vantage point.
Definition: vantage_point_split_impl.hpp:24
A struct that contains an information about the split.
Definition: vantage_point_split.hpp:40
The class splits a binary space partitioning tree node according to the median distance to the vantag...
Definition: vantage_point_split.hpp:32
BoundType::MetricType MetricType
The bounding shape type.
Definition: vantage_point_split.hpp:38
Bounds that are useful for binary space partitioning trees.