- old_log_sum_importance = log_sum_importance
- log_sum_importance = log_plus(old_log_sum_importance, log_importance)
- trace("new log_sum_weight", log_sum_weight)
- trace("log_sum_importance", log_sum_importance)
- if old_log_sum_importance is None:
- param_sampled_avg = list(sample_point)
- value_avg = value
- # Other value related quantities stay None.
- continue
- previous_samples_ratio = math.exp(
- old_log_sum_importance - log_sum_importance)
- new_sample_ratio = math.exp(log_importance - log_sum_importance)
- param_shift = [sample_point[first] - param_sampled_avg[first]
- for first in range(dimension)]
- value_shift = value - value_avg
- for first in range(dimension):
- param_sampled_avg[first] += param_shift[first] * new_sample_ratio
- old_value_avg = value_avg
- value_avg += value_shift * new_sample_ratio
- value_absolute_shift = abs(value_shift)
- for second in range(dimension):
- for first in range(dimension):
- param_sampled_cov[first][second] += (
- param_shift[first] * param_shift[second] * new_sample_ratio)
- param_sampled_cov[first][second] *= previous_samples_ratio
- trace("param_sampled_avg", param_sampled_avg)
- trace("param_sampled_cov", param_sampled_cov)
- update_secondary_stats = True
- if log_importance_best is None or log_importance > log_importance_best:
- log_importance_best = log_importance
- log_secondary_sum_importance = old_log_sum_importance
- value_secondary_avg = old_value_avg
- value_log_secondary_variance = value_log_variance
- update_secondary_stats = False
- # TODO: Update all primary quantities before secondary ones.
- # (As opposed to current hybrid code.)
- if value_absolute_shift > 0.0:
- value_log_variance = log_plus(
- value_log_variance, 2 * math.log(value_absolute_shift)
- + log_importance - log_sum_importance)
- if value_log_variance is not None:
- value_log_variance -= log_sum_importance - old_log_sum_importance
- if not update_secondary_stats:
- continue
- # TODO: Pylint says the following variable name is bad.
- # Make sure the refactor uses shorter names.
- old_log_secondary_sum_importance = log_secondary_sum_importance
- log_secondary_sum_importance = log_plus(
- old_log_secondary_sum_importance, log_importance)
- if old_log_secondary_sum_importance is None:
- value_secondary_avg = value
- continue
- new_sample_secondary_ratio = math.exp(
- log_importance - log_secondary_sum_importance)
- # TODO: No would-be variable named old_value_secondary_avg
- # appears in subsequent computations. Probably means there is a bug.
- value_secondary_shift = value - value_secondary_avg
- value_secondary_absolute_shift = abs(value_secondary_shift)
- value_secondary_avg += (
- value_secondary_shift * new_sample_secondary_ratio)
- if value_secondary_absolute_shift > 0.0:
- value_log_secondary_variance = log_plus(
- value_log_secondary_variance, (
- 2 * math.log(value_secondary_absolute_shift)
- + log_importance - log_secondary_sum_importance))
- if value_log_secondary_variance is not None:
- value_log_secondary_variance -= (
- log_secondary_sum_importance - old_log_secondary_sum_importance)
- debug_list.append("integrator used " + str(samples) + " samples")