@@ -139,7 +139,7 @@ class CumDistribution : public Distribution {
139
139
var_param = VARIANCE; \
140
140
description = DESC; \
141
141
param_names_vec.push_back (" mean" ); \
142
- if (var_param)param_names_vec.push_back (" var" ); \
142
+ if (var_param)param_names_vec.push_back (" var" ); \
143
143
dist_umap.emplace ( #NAME, this ); \
144
144
} \
145
145
}; \
@@ -216,22 +216,27 @@ class absDistribution : public Distribution {
216
216
int after_i = n_candidates-1 -before_i;
217
217
candidate_split_ptr->set_end_dist
218
218
(first_data, first_candidate+before_i, last_data);
219
- candidate_split_ptr->before .center =
220
- before_median_vec[before_i];
221
- candidate_split_ptr->after .center =
222
- after_median_vec[after_i];
223
- candidate_split_ptr->before .spread =
224
- before_loss_vec[before_i]/before_weight_vec[before_i];
225
- candidate_split_ptr->after .spread =
226
- after_loss_vec[after_i]/after_weight_vec[after_i];
227
- candidate_split_ptr->before .loss = adjust
228
- (before_loss_vec[before_i],
229
- before_weight_vec[before_i],
230
- candidate_split_ptr->before .spread );
231
- candidate_split_ptr->after .loss = adjust
232
- (after_loss_vec[after_i],
233
- after_weight_vec[after_i],
234
- candidate_split_ptr->after .spread );
219
+ std::vector<double > *loss_ptr, *median_ptr, *weight_ptr;
220
+ ParamsLoss *pl_ptr;
221
+ int i;
222
+ for (int direction=0 ; direction<2 ; direction++){
223
+ if (direction==0 ){
224
+ loss_ptr = &before_loss_vec;
225
+ median_ptr = &before_median_vec;
226
+ weight_ptr = &before_weight_vec;
227
+ pl_ptr = &candidate_split_ptr->before ;
228
+ i = before_i;
229
+ }else {
230
+ loss_ptr = &after_loss_vec;
231
+ median_ptr = &after_median_vec;
232
+ weight_ptr = &after_weight_vec;
233
+ pl_ptr = &candidate_split_ptr->after ;
234
+ i = after_i;
235
+ }
236
+ pl_ptr->center = (*median_ptr)[i];
237
+ pl_ptr->spread = (*loss_ptr)[i]/(*weight_ptr)[i];
238
+ pl_ptr->loss = adjust ((*loss_ptr)[i], (*weight_ptr)[i], pl_ptr->spread );
239
+ }
235
240
best_split_ptr->maybe_update (candidate_split_ptr);
236
241
}
237
242
}
@@ -270,17 +275,17 @@ class absDistribution : public Distribution {
270
275
}
271
276
};
272
277
273
- #define ABS_DIST (NAME, DESC, VARIANCE ) \
274
- class CONCAT (NAME, Distribution) : public absDistribution { \
275
- public: \
276
- CONCAT (NAME, Distribution) (){ \
277
- var_param = VARIANCE; \
278
- description = DESC; \
279
- param_names_vec.push_back (" median" ); \
280
- if (var_param)param_names_vec.push_back (" scale" ); \
278
+ #define ABS_DIST (NAME, DESC, VARIANCE ) \
279
+ class CONCAT (NAME, Distribution) : public absDistribution { \
280
+ public: \
281
+ CONCAT (NAME, Distribution) (){ \
282
+ var_param = VARIANCE; \
283
+ description = DESC; \
284
+ param_names_vec.push_back (" median" ); \
285
+ if (var_param)param_names_vec.push_back (" scale" ); \
281
286
dist_umap.emplace ( #NAME, this ); \
282
- } \
283
- }; \
287
+ } \
288
+ }; \
284
289
static CONCAT (NAME, Distribution) NAME;
285
290
286
291
ABS_DIST (l1, " change in median (loss is total absolute deviation)" , false )
0 commit comments