24 double init_avg,
double regress_weight,
25 double persistence_factor) {
26 stats->init_avg = init_avg;
27 stats->regress_weight = regress_weight;
28 stats->persistence_factor = persistence_factor;
29 stats->batch_total_value = 0;
30 stats->batch_num_samples = 0;
31 stats->aggregate_total_weight = 0;
32 stats->aggregate_weighted_avg = init_avg;
38 ++
stats->batch_num_samples;
44 double weighted_sum =
stats->batch_total_value;
45 double total_weight =
stats->batch_num_samples;
46 if (
stats->regress_weight > 0) {
48 weighted_sum +=
stats->regress_weight *
stats->init_avg;
49 total_weight +=
stats->regress_weight;
51 if (
stats->persistence_factor > 0) {
53 const double prev_sample_weight =
54 stats->persistence_factor *
stats->aggregate_total_weight;
55 weighted_sum += prev_sample_weight *
stats->aggregate_weighted_avg;
56 total_weight += prev_sample_weight;
58 stats->aggregate_weighted_avg =
59 (total_weight > 0) ? (weighted_sum / total_weight) :
stats->init_avg;
60 stats->aggregate_total_weight = total_weight;
61 stats->batch_num_samples = 0;
62 stats->batch_total_value = 0;
63 return stats->aggregate_weighted_avg;