mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
18 namespace mlpack {
19 namespace tree {
20 
29 template<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 boost::enable_if<IsVector<VecType> >::type* = 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 boost::enable_if<IsVector<VecType> >::type* = 0) const
88  {
89  return Project(point) <= 0;
90  };
91 
98  template<typename VecType>
99  bool Right(const VecType& point,
100  typename boost::enable_if<IsVector<VecType> >::type* = 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 & data::CreateNVP(projVect, "projVect");
136  ar & data::CreateNVP(splitVal, "splitVal");
137  };
138 };
139 
143 template<typename MetricType>
144 using AxisOrthogonalHyperplane = HyperplaneBase<bound::HRectBound<MetricType>,
146 
150 template<typename MetricType>
152 
153 } // namespace tree
154 } // namespace mlpack
155 
156 #endif
HyperplaneBase()
Empty Constructor.
Definition: hyperplane.hpp:49
HyperplaneBase< bound::HRectBound< MetricType >, AxisParallelProjVector > AxisOrthogonalHyperplane
AxisOrthogonalHyperplane represents a hyperplane orthogonal to an axis.
Definition: hyperplane.hpp:145
AxisParallelProjVector defines an axis-parallel projection vector.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Project(const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=0) const
Project the given point on the projection vector and subtract the split value.
Definition: hyperplane.hpp:71
HyperplaneBase defines a splitting hyperplane based on a projection vector and projection value...
Definition: hyperplane.hpp:30
void Serialize(Archive &ar, const unsigned int)
Serialization.
Definition: hyperplane.hpp:133
ProjVector defines a general projection vector (not necessarily axis-parallel).
bool Right(const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=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
bool Left(const VecType &point, typename boost::enable_if< IsVector< VecType > >::type *=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
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
BoundT BoundType
Useful typedef for the bound type.
Definition: hyperplane.hpp:34
HyperplaneBase(const ProjVectorType &projVect, double splitVal)
Create the hyperplane with the specified projection vector and split value.
Definition: hyperplane.hpp:59
bool Right(const BoundType &bound) const
Determine if the given bound is to the right of the hyperplane.
Definition: hyperplane.hpp:122
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35