mlpack 3.4.2
hyperplane.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_CORE_TREE_SPILL_TREE_HYPERPLANE_HPP
13#define MLPACK_CORE_TREE_SPILL_TREE_HYPERPLANE_HPP
14
15#include <mlpack/prereqs.hpp>
16#include "projection_vector.hpp"
17
18namespace mlpack {
19namespace tree {
20
29template<typename BoundT, typename ProjVectorT>
31{
32 public:
34 typedef BoundT BoundType;
36 typedef ProjVectorT ProjVectorType;
37
38 private:
40 ProjVectorType projVect;
41
43 double splitVal;
44
45 public:
50 splitVal(DBL_MAX)
51 {};
52
59 HyperplaneBase(const ProjVectorType& projVect, double splitVal) :
60 projVect(projVect),
61 splitVal(splitVal)
62 {};
63
70 template<typename VecType>
71 double Project(const VecType& point,
72 typename std::enable_if_t<IsVector<VecType>::value>* = 0) const
73 {
74 if (splitVal == DBL_MAX)
75 return 0;
76 return projVect.Project(point) - splitVal;
77 };
78
85 template<typename VecType>
86 bool Left(const VecType& point,
87 typename std::enable_if_t<IsVector<VecType>::value>* = 0) const
88 {
89 return Project(point) <= 0;
90 };
91
98 template<typename VecType>
99 bool Right(const VecType& point,
100 typename std::enable_if_t<IsVector<VecType>::value>* = 0) const
101 {
102 return Project(point) > 0;
103 };
104
110 bool Left(const BoundType& bound) const
111 {
112 if (splitVal == DBL_MAX)
113 return true;
114 return projVect.Project(bound).Hi() <= splitVal;
115 };
116
122 bool Right(const BoundType& bound) const
123 {
124 if (splitVal == DBL_MAX)
125 return false;
126 return projVect.Project(bound).Lo() > splitVal;
127 };
128
132 template<typename Archive>
133 void serialize(Archive& ar, const unsigned int /* version */)
134 {
135 ar & BOOST_SERIALIZATION_NVP(projVect);
136 ar & BOOST_SERIALIZATION_NVP(splitVal);
137 };
138};
139
143template<typename MetricType>
146
150template<typename MetricType>
152
153} // namespace tree
154} // namespace mlpack
155
156#endif
AxisParallelProjVector defines an axis-parallel projection vector.
HyperplaneBase defines a splitting hyperplane based on a projection vector and projection value.
Definition: hyperplane.hpp:31
bool Right(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Determine if the given point is to the right of the hyperplane, this means if the projection over the...
Definition: hyperplane.hpp:99
HyperplaneBase(const ProjVectorType &projVect, double splitVal)
Create the hyperplane with the specified projection vector and split value.
Definition: hyperplane.hpp:59
double Project(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Project the given point on the projection vector and subtract the split value.
Definition: hyperplane.hpp:71
HyperplaneBase()
Empty Constructor.
Definition: hyperplane.hpp:49
bool Right(const BoundType &bound) const
Determine if the given bound is to the right of the hyperplane.
Definition: hyperplane.hpp:122
ProjVectorT ProjVectorType
Useful typedef for the projection vector type.
Definition: hyperplane.hpp:36
bool Left(const BoundType &bound) const
Determine if the given bound is to the left of the hyperplane.
Definition: hyperplane.hpp:110
bool Left(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Determine if the given point is to the left of the hyperplane, this means if the projection over the ...
Definition: hyperplane.hpp:86
BoundT BoundType
Useful typedef for the bound type.
Definition: hyperplane.hpp:34
void serialize(Archive &ar, const unsigned int)
Serialization.
Definition: hyperplane.hpp:133
ProjVector defines a general projection vector (not necessarily axis-parallel).
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
The core includes that mlpack expects; standard C++ includes and Armadillo.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:36