13 #ifndef MLPACK_METHODS_HOEFFDING_TREES_INFORMATION_GAIN_HPP 14 #define MLPACK_METHODS_HOEFFDING_TREES_INFORMATION_GAIN_HPP 31 static double Evaluate(
const arma::Mat<size_t>& counts)
36 arma::vec splitCounts(counts.n_elem);
37 for (
size_t i = 0; i < counts.n_cols; ++i)
39 splitCounts[i] = arma::accu(counts.col(i));
40 numElem += splitCounts[i];
47 arma::Col<size_t> classCounts = arma::sum(counts, 1);
51 for (
size_t i = 0; i < classCounts.n_elem; ++i)
53 const double f = ((double) classCounts[i] / (
double) numElem);
55 gain -= f * std::log2(f);
60 for (
size_t i = 0; i < counts.n_cols; ++i)
62 if (splitCounts[i] > 0)
64 double splitGain = 0.0;
65 for (
size_t j = 0; j < counts.n_rows; ++j)
67 const double f = ((double) counts(j, i) / (double) splitCounts[i]);
69 splitGain += f * std::log2(f);
72 gain += ((double) splitCounts[i] / (
double) numElem) * splitGain;
84 static double Range(
const size_t numClasses)
89 return std::log2(numClasses);
Linear algebra utility functions, generally performed on matrices or vectors.