13 #ifndef MLPACK_CORE_TREE_RECTANGLE_TREE_R_STAR_TREE_DESCENT_HEURISTIC_IMPL_HPP 14 #define MLPACK_CORE_TREE_RECTANGLE_TREE_R_STAR_TREE_DESCENT_HEURISTIC_IMPL_HPP 21 template<
typename TreeType>
27 typedef typename TreeType::ElemType ElemType;
30 std::vector<ElemType> originalScores(node->NumChildren());
31 ElemType origMinScore = std::numeric_limits<ElemType>::max();
33 if (node->Child(0).IsLeaf())
38 for (
size_t i = 0; i < node->NumChildren(); ++i)
41 for (
size_t j = 0; j < node->NumChildren(); ++j)
45 ElemType overlap = 1.0;
46 ElemType newOverlap = 1.0;
47 for (
size_t k = 0; k < node->Bound().Dim(); ++k)
49 ElemType newHigh = std::max(node->Dataset().col(point)[k],
50 node->Child(i).Bound()[k].Hi());
51 ElemType newLow = std::min(node->Dataset().col(point)[k],
52 node->Child(i).Bound()[k].Lo());
53 overlap *= node->Child(i).Bound()[k].Hi() <
54 node->Child(j).Bound()[k].Lo() ||
55 node->Child(i).Bound()[k].Lo() >
56 node->Child(j).Bound()[k].Hi() ? 0 :
57 std::min(node->Child(i).Bound()[k].Hi(),
58 node->Child(j).Bound()[k].Hi()) -
59 std::max(node->Child(i).Bound()[k].Lo(),
60 node->Child(j).Bound()[k].Lo());
62 newOverlap *= newHigh < node->Child(j).Bound()[k].Lo() ||
63 newLow > node->Child(j).Bound()[k].Hi() ? 0 :
64 std::min(newHigh, node->Child(j).Bound()[k].Hi()) -
65 std::max(newLow, node->Child(j).Bound()[k].Lo());
67 sc += newOverlap - overlap;
71 originalScores[i] = sc;
72 if (sc < origMinScore)
77 else if (sc == origMinScore)
88 std::vector<ElemType> scores(node->NumChildren());
92 for (
size_t i = 0; i < scores.size(); ++i)
93 scores[i] = std::numeric_limits<ElemType>::max();
96 std::vector<ElemType> vols(node->NumChildren());
97 ElemType minScore = std::numeric_limits<ElemType>::max();
101 for (
size_t i = 0; i < node->NumChildren(); ++i)
103 if (!tiedOne || originalScores[i] == origMinScore)
107 for (
size_t j = 0; j < node->Bound().Dim(); ++j)
109 v1 *= node->Child(i).Bound()[j].Width();
110 v2 *= node->Child(i).Bound()[j].Contains(
111 node->Dataset().col(point)[j]) ?
112 node->Child(i).Bound()[j].Width() :
113 (node->Child(i).Bound()[j].Hi() < node->Dataset().col(point)[j] ?
114 (node->Dataset().col(point)[j] - node->Child(i).Bound()[j].Lo()) :
115 (node->Child(i).Bound()[j].Hi() - node->Dataset().col(point)[j]));
118 assert(v2 - v1 >= 0);
122 if (v2 - v1 < minScore)
127 else if (v2 - v1 == minScore)
137 ElemType minVol = std::numeric_limits<ElemType>::max();
139 for (
size_t i = 0; i < scores.size(); ++i)
141 if (scores[i] == minScore)
143 if (vols[i] < minVol)
162 template<
typename TreeType>
164 const TreeType* node,
165 const TreeType* insertedNode)
168 typedef typename TreeType::ElemType ElemType;
170 std::vector<ElemType> scores(node->NumChildren());
171 std::vector<ElemType> vols(node->NumChildren());
172 ElemType minScore = std::numeric_limits<ElemType>::max();
173 size_t bestIndex = 0;
176 for (
size_t i = 0; i < node->NumChildren(); ++i)
180 for (
size_t j = 0; j < node->Child(i).Bound().Dim(); ++j)
182 v1 *= node->Child(i).Bound()[j].Width();
183 v2 *= node->Child(i).Bound()[j].Contains(insertedNode->Bound()[j]) ?
184 node->Child(i).Bound()[j].Width() :
185 (insertedNode->Bound()[j].Contains(node->Child(i).Bound()[j]) ?
186 insertedNode->Bound()[j].Width() :
187 (insertedNode->Bound()[j].Lo() < node->Child(i).Bound()[j].Lo() ?
188 (node->Child(i).Bound()[j].Hi() - insertedNode->Bound()[j].Lo()) :
189 (insertedNode->Bound()[j].Hi() - node->Child(i).Bound()[j].Lo())));
192 assert(v2 - v1 >= 0);
196 if (v2 - v1 < minScore)
201 else if (v2 - v1 == minScore)
210 ElemType minVol = std::numeric_limits<ElemType>::max();
212 for (
size_t i = 0; i < scores.size(); ++i)
214 if (scores[i] == minScore)
216 if (vols[i] < minVol)
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static size_t ChooseDescentNode(const TreeType *node, const size_t point)
Evaluate the node using a heuristic.
Definition: r_star_tree_descent_heuristic_impl.hpp:22