14 #ifndef MLPACK_METHODS_DECISION_TREE_MAD_GAIN_HPP 15 #define MLPACK_METHODS_DECISION_TREE_MAD_GAIN_HPP 45 template<
bool UseWeights,
typename VecType,
typename WeightVecType>
47 const WeightVecType& weights,
55 double accWeights = 0.0;
56 double weightedMean = 0.0;
58 WeightedSum(values, weights, begin, end, accWeights, weightedMean);
61 if (accWeights == 0.0)
64 weightedMean /= accWeights;
66 for (
size_t i = begin; i < end; ++i)
68 mad += weights[i] * (std::abs(values[i] - weightedMean));
75 Sum(values, begin, end, mean);
76 mean /= (double) (end - begin);
78 mad = arma::accu(arma::abs(values.subvec(begin, end - 1) - mean));
79 mad /= (double) (end - begin);
91 template<
bool UseWeights,
typename VecType,
typename WeightVecType>
93 const WeightVecType& weights)
96 if (values.n_elem == 0)
99 return Evaluate<UseWeights>(values, weights, 0, values.n_elem);
static double Evaluate(const VecType &values, const WeightVecType &weights)
Evaluate the MAD gain on the complete vector.
Definition: mad_gain.hpp:92
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
void WeightedSum(const VecType &values, const WeightVecType &weights, const size_t begin, const size_t end, double &accWeights, double &weightedMean)
Calculates the weighted sum and total weight of labels.
Definition: utils.hpp:19
The MAD (Mean absolute deviation) gain, is a measure of set purity based on the deviation of dependen...
Definition: mad_gain.hpp:30
static double Evaluate(const VecType &values, const WeightVecType &weights, const size_t begin, const size_t end)
Evaluate the mean absolute deviation gain from begin to end index.
Definition: mad_gain.hpp:46
void Sum(const VecType &values, const size_t begin, const size_t end, double &mean)
Sums up the labels vector.
Definition: utils.hpp:96