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);
107 template<
bool UseWeights,
typename ResponsesType,
typename WeightsType>
109 const WeightsType& weights)
113 double accWeights, weightedSum;
114 WeightedSum(responses, weights, 0, responses.n_elem, accWeights,
116 return weightedSum / accWeights;
121 Sum(responses, 0, responses.n_elem, sum);
122 return sum / responses.n_elem;
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.
double OutputLeafValue(const ResponsesType &responses, const WeightsType &weights)
Returns the output value for each leaf node for prediction.
Linear algebra utility functions, generally performed on matrices or vectors.
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.
The MAD (Mean absolute deviation) gain, is a measure of set purity based on the deviation of dependen...
static double Evaluate(const VecType &values, const WeightVecType &weights)
Evaluate the MAD gain on the complete vector.
void Sum(const VecType &values, const size_t begin, const size_t end, double &mean)
Sums up the labels vector.