12 #ifndef MLPACK_METHODS_HOEFFDING_TREES_HOEFFDING_CATEGORICAL_SPLIT_IMPL_HPP 13 #define MLPACK_METHODS_HOEFFDING_TREES_HOEFFDING_CATEGORICAL_SPLIT_IMPL_HPP 21 template<
typename FitnessFunction>
23 const size_t numCategories,
24 const size_t numClasses) :
25 sufficientStatistics(numClasses, numCategories)
27 sufficientStatistics.zeros();
30 template<
typename FitnessFunction>
32 const size_t numCategories,
33 const size_t numClasses,
35 sufficientStatistics(numClasses, numCategories)
37 sufficientStatistics.zeros();
40 template<
typename FitnessFunction>
47 sufficientStatistics(label,
size_t(value))++;
50 template<
typename FitnessFunction>
53 double& secondBestFitness)
const 55 bestFitness = FitnessFunction::Evaluate(sufficientStatistics);
56 secondBestFitness = 0.0;
59 template<
typename FitnessFunction>
61 arma::Col<size_t>& childMajorities,
65 childMajorities.set_size(sufficientStatistics.n_cols);
66 for (
size_t i = 0; i < sufficientStatistics.n_cols; ++i)
68 arma::uword maxIndex = 0;
69 sufficientStatistics.unsafe_col(i).max(maxIndex);
70 childMajorities[i] = size_t(maxIndex);
74 splitInfo =
SplitInfo(sufficientStatistics.n_cols);
77 template<
typename FitnessFunction>
81 arma::Col<size_t> classCounts = arma::sum(sufficientStatistics, 1);
83 arma::uword maxIndex = 0;
84 classCounts.max(maxIndex);
86 return size_t(maxIndex);
89 template<
typename FitnessFunction>
92 arma::Col<size_t> classCounts = arma::sum(sufficientStatistics, 1);
94 return double(classCounts.max()) /
double(arma::accu(classCounts));
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void EvaluateFitnessFunction(double &bestFitness, double &secondBestFitness) const
Given the points seen so far, evaluate the fitness function, returning the gain for the best possible...
Definition: hoeffding_categorical_split_impl.hpp:51
size_t MajorityClass() const
Get the majority class seen so far.
Definition: hoeffding_categorical_split_impl.hpp:78
Definition: categorical_split_info.hpp:20
void Split(arma::Col< size_t > &childMajorities, SplitInfo &splitInfo)
Gather the information for a split: get the labels of the child majorities, and initialize the SplitI...
Definition: hoeffding_categorical_split_impl.hpp:60
CategoricalSplitInfo SplitInfo
The type of split information required by the HoeffdingCategoricalSplit.
Definition: hoeffding_categorical_split.hpp:48
HoeffdingCategoricalSplit(const size_t numCategories=0, const size_t numClasses=0)
Create the HoeffdingCategoricalSplit given a number of categories for this dimension and a number of ...
Definition: hoeffding_categorical_split_impl.hpp:22
double MajorityProbability() const
Get the probability of the majority class given the points seen so far.
Definition: hoeffding_categorical_split_impl.hpp:90
This is the standard Hoeffding-bound categorical feature proposed in the paper below: ...
Definition: hoeffding_categorical_split.hpp:44
void Train(eT value, const size_t label)
Train on the given value with the given label.
Definition: hoeffding_categorical_split_impl.hpp:42