12 #ifndef MLPACK_CORE_TREE_COSINE_TREE_COSINE_TREE_HPP 13 #define MLPACK_CORE_TREE_COSINE_TREE_COSINE_TREE_HPP 16 #include <boost/heap/priority_queue.hpp> 22 class CompareCosineNode;
26 typedef boost::heap::priority_queue<CosineTree*,
27 boost::heap::compare<CompareCosineNode> > CosineNodeQueue;
51 CosineTree(CosineTree& parentNode,
const std::vector<size_t>& subIndices);
91 CosineTree&
operator=(
const CosineTree& other);
98 CosineTree&
operator=(CosineTree&& other);
116 arma::vec& newBasisVector,
117 arma::vec* addBasisVector = NULL);
132 CosineNodeQueue& treeQueue,
133 arma::vec* addBasisVector1 = NULL,
134 arma::vec* addBasisVector2 = NULL);
157 arma::vec& probabilities,
size_t numSamples);
179 size_t BinarySearch(arma::vec& cDistribution,
double value,
size_t start,
207 void L2Error(
const double error) { this->l2Error = error; }
215 void BasisVector(arma::vec& bVector) { this->basisVector = bVector; }
221 CosineTree*
Parent()
const {
return parent; }
226 CosineTree*
Left()
const {
return left; }
228 CosineTree*&
Left() {
return left; }
231 CosineTree*
Right()
const {
return right; }
233 CosineTree*&
Right() {
return right; }
246 const arma::mat* dataset;
258 std::vector<size_t> indices;
260 arma::vec l2NormsSquared;
264 arma::vec basisVector;
266 size_t splitPointIndex;
272 double frobNormSquared;
281 bool operator() (
const CosineTree* a,
const CosineTree* b)
const void CalculateCosines(arma::vec &cosines)
Calculate cosines of the columns present in the node, with respect to the sampled splitting point...
Definition: cosine_tree.cpp:631
double FrobNormSquared() const
Get the Frobenius norm squared of columns in the node.
Definition: cosine_tree.hpp:239
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
size_t SplitPointIndex() const
Get the column index of split point of the node.
Definition: cosine_tree.hpp:242
The core includes that mlpack expects; standard C++ includes and Armadillo.
void CosineNodeSplit()
This function splits the cosine node into two children based on the cosines of the columns contained ...
Definition: cosine_tree.cpp:507
double MonteCarloError(CosineTree *node, CosineNodeQueue &treeQueue, arma::vec *addBasisVector1=NULL, arma::vec *addBasisVector2=NULL)
Estimates the squared error of the projection of the input node's matrix onto the current vector subs...
Definition: cosine_tree.cpp:404
void GetFinalBasis(arma::mat &finalBasis)
Returns the basis of the constructed subspace.
Definition: cosine_tree.hpp:198
CosineTree * Right() const
Get pointer to the right child of the node.
Definition: cosine_tree.hpp:231
CosineTree * Left() const
Get pointer to the left child of the node.
Definition: cosine_tree.hpp:226
CosineTree *& Parent()
Modify the pointer to the parent node.
Definition: cosine_tree.hpp:223
size_t ColumnSampleLS()
Sample a point from the Length-Squared distribution of the cosine node.
Definition: cosine_tree.cpp:576
arma::vec & Centroid()
Get pointer to the centroid vector.
Definition: cosine_tree.hpp:212
void ConstructBasis(CosineNodeQueue &treeQueue)
Constructs the final basis matrix, after the cosine tree construction.
Definition: cosine_tree.cpp:489
~CosineTree()
Clean up the CosineTree: release allocated memory (including children).
Definition: cosine_tree.cpp:360
Definition: cosine_tree.hpp:277
CosineTree(const arma::mat &dataset)
CosineTree constructor for the root node of the tree.
Definition: cosine_tree.cpp:20
void BasisVector(arma::vec &bVector)
Set the basis vector of the node.
Definition: cosine_tree.hpp:215
size_t BinarySearch(arma::vec &cDistribution, double value, size_t start, size_t end)
Sample a column based on the cumulative Length-Squared distribution of the cosine node...
Definition: cosine_tree.cpp:603
arma::vec & BasisVector()
Get the basis vector of the node.
Definition: cosine_tree.hpp:218
void CalculateCentroid()
Calculate centroid of the columns present in the node.
Definition: cosine_tree.cpp:653
size_t NumColumns() const
Get number of columns of input matrix in the node.
Definition: cosine_tree.hpp:236
CosineTree *& Right()
Modify the pointer to the left child of the node.
Definition: cosine_tree.hpp:233
const arma::mat & GetDataset() const
Get pointer to the dataset matrix.
Definition: cosine_tree.hpp:201
CosineTree & operator=(const CosineTree &other)
Copy the given Cosine Tree.
Definition: cosine_tree.cpp:210
void ModifiedGramSchmidt(CosineNodeQueue &treeQueue, arma::vec ¢roid, arma::vec &newBasisVector, arma::vec *addBasisVector=NULL)
Calculates the orthonormalization of the passed centroid, with respect to the current vector subspace...
Definition: cosine_tree.cpp:370
CosineTree *& Left()
Modify the pointer to the left child of the node.
Definition: cosine_tree.hpp:228
void ColumnSamplesLS(std::vector< size_t > &sampledIndices, arma::vec &probabilities, size_t numSamples)
Sample 'numSamples' points from the Length-Squared distribution of the cosine node.
Definition: cosine_tree.cpp:544
void L2Error(const double error)
Set the Monte Carlo error.
Definition: cosine_tree.hpp:207
double L2Error() const
Get the Monte Carlo error.
Definition: cosine_tree.hpp:209
CosineTree * Parent() const
Get pointer to the parent node.
Definition: cosine_tree.hpp:221
std::vector< size_t > & VectorIndices()
Get the indices of columns in the node.
Definition: cosine_tree.hpp:204