12 #ifndef MLPACK_METHODS_DECISION_TREE_UTILS_HPP 13 #define MLPACK_METHODS_DECISION_TREE_UTILS_HPP 18 template<
typename VecType,
typename WeightVecType>
20 const WeightVecType& weights,
26 typedef typename VecType::elem_type VType;
27 typedef typename WeightVecType::elem_type WType;
29 WType totalWeights[4] = { 0.0, 0.0, 0.0, 0.0 };
30 VType weightedSum[4] = { 0.0, 0.0, 0.0, 0.0 };
34 for (
size_t i = begin + 3; i < end; i += 4)
36 const WType weight1 = weights[i - 3];
37 const WType weight2 = weights[i - 2];
38 const WType weight3 = weights[i - 1];
39 const WType weight4 = weights[i];
41 weightedSum[0] += weight1 * values[i - 3];
42 weightedSum[1] += weight2 * values[i - 2];
43 weightedSum[2] += weight3 * values[i - 1];
44 weightedSum[3] += weight4 * values[i];
46 totalWeights[0] += weight1;
47 totalWeights[1] += weight2;
48 totalWeights[2] += weight3;
49 totalWeights[3] += weight4;
53 if ((end - begin) % 4 == 1)
55 const WType weight1 = weights[end - 1];
56 weightedSum[0] += weight1 * values[end - 1];
57 totalWeights[0] += weight1;
59 else if ((end - begin) % 4 == 2)
61 const WType weight1 = weights[end - 2];
62 const WType weight2 = weights[end - 1];
64 weightedSum[0] += weight1 * values[end - 2];
65 weightedSum[1] += weight2 * values[end - 1];
67 totalWeights[0] += weight1;
68 totalWeights[1] += weight2;
70 else if ((end - begin) % 4 == 3)
72 const WType weight1 = weights[end - 3];
73 const WType weight2 = weights[end - 2];
74 const WType weight3 = weights[end - 1];
76 weightedSum[0] += weight1 * values[end - 3];
77 weightedSum[1] += weight2 * values[end - 2];
78 weightedSum[2] += weight1 * values[end - 1];
80 totalWeights[0] += weight1;
81 totalWeights[1] += weight2;
82 totalWeights[2] += weight3;
85 totalWeights[0] += totalWeights[1] + totalWeights[2] + totalWeights[3];
86 weightedSum[0] += weightedSum[1] + weightedSum[2] + weightedSum[3];
88 accWeights = totalWeights[0];
89 weightedMean = weightedSum[0];
95 template<
typename VecType>
96 inline void Sum(
const VecType& values,
101 typename VecType::elem_type total[4] = { 0.0, 0.0, 0.0, 0.0 };
105 for (
size_t i = begin + 3; i < end; i += 4)
107 total[0] += values[i - 3];
108 total[1] += values[i - 2];
109 total[2] += values[i - 1];
110 total[3] += values[i];
114 if ((end - begin) % 4 == 1)
116 total[0] += values[end - 1];
118 else if ((end - begin) % 4 == 2)
120 total[0] += values[end - 2];
121 total[1] += values[end - 1];
123 else if ((end - begin) % 4 == 3)
125 total[0] += values[end - 3];
126 total[1] += values[end - 2];
127 total[2] += values[end - 1];
130 total[0] += total[1] + total[2] + total[3];
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.
void Sum(const VecType &values, const size_t begin, const size_t end, double &mean)
Sums up the labels vector.