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*,
87 arma::vec& newBasisVector,
88 arma::vec* addBasisVector = NULL);
104 arma::vec* addBasisVector1 = NULL,
105 arma::vec* addBasisVector2 = NULL);
128 arma::vec& probabilities,
size_t numSamples);
150 size_t BinarySearch(arma::vec& cDistribution,
double value,
size_t start,
178 void L2Error(
const double error) { this->l2Error = error; }
186 void BasisVector(arma::vec& bVector) { this->basisVector = bVector; }
217 const arma::mat& dataset;
229 std::vector<size_t> indices;
231 arma::vec l2NormsSquared;
235 arma::vec basisVector;
237 size_t splitPointIndex;
243 double frobNormSquared;
bool operator()(const CosineTree *a, const CosineTree *b) const
double FrobNormSquared() const
Get the Frobenius norm squared of columns in the node.
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...
arma::vec & Centroid()
Get pointer to the centroid vector.
void GetFinalBasis(arma::mat &finalBasis)
Returns the basis of the constructed subspace.
CosineTree *& Left()
Modify the pointer to the left child of the node.
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...
void ConstructBasis(CosineNodeQueue &treeQueue)
Constructs the final basis matrix, after the cosine tree construction.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void L2Error(const double error)
Set the Monte Carlo error.
const arma::mat & GetDataset() const
Get pointer to the dataset matrix.
CosineTree * Left() const
Get pointer to the left child of the node.
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.
size_t SplitPointIndex() const
Get the column index of split point of the node.
size_t ColumnSampleLS()
Sample a point from the Length-Squared distribution of the cosine node.
CosineTree(const arma::mat &dataset)
CosineTree constructor for the root node of the tree.
void CosineNodeSplit()
This function splits the cosine node into two children based on the cosines of the columns contained ...
double L2Error() const
Get the Monte Carlo error.
CosineTree *& Right()
Modify the pointer to the left child of the node.
CosineTree *& Parent()
Modify the pointer to the parent node.
std::vector< size_t > & VectorIndices()
Get the indices of columns in the node.
CosineTree * Parent() const
Get pointer to the parent node.
~CosineTree()
Clean up the CosineTree: release allocated memory (including children).
CosineTree * Right() const
Get pointer to the right child of the node.
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...
void BasisVector(arma::vec &bVector)
Set the basis vector of the node.
void CalculateCentroid()
Calculate centroid of the columns present in the node.
size_t NumColumns() const
Get number of columns of input matrix in the node.
arma::vec & BasisVector()
Get the basis vector of the node.
void CalculateCosines(arma::vec &cosines)
Calculate cosines of the columns present in the node, with respect to the sampled splitting point...
boost::heap::priority_queue< CosineTree *, boost::heap::compare< CompareCosineNode > > CosineNodeQueue