From c1c3861b6763288586c215eff5c42d9b84667fd3 Mon Sep 17 00:00:00 2001 From: Yan Wong Date: Tue, 6 Sep 2022 10:41:41 +0100 Subject: [PATCH] Remove sum_to_unity --- tsdate/base.py | 20 +++----------------- tsdate/core.py | 6 +++--- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/tsdate/base.py b/tsdate/base.py index 656303a8..007277a9 100644 --- a/tsdate/base.py +++ b/tsdate/base.py @@ -134,19 +134,6 @@ def force_probability_space(self, probability_space): else: logging.warning("Cannot force", *descr) - def sum_to_unity(self, arr): - """ - Return an array for a node in which the (untransformed) values - sum to unity - """ - if self.probability_space == LIN: - return arr / np.sum(arr) - elif self.probability_space == LOG: - with np.errstate(divide="ignore"): - return np.log(np.exp(arr) / np.sum(np.exp(arr))) - else: - raise RuntimeError("Probability space is not", LIN, "or", LOG) - def normalize(self): """ normalize grid and fixed data so the max is one @@ -229,8 +216,7 @@ def fill_fixed(orig, fixed_data): new_obj.fixed_data = fill_fixed( self, grid_data if fixed_data is None else fixed_data ) - if probability_space is None: - new_obj.probability_space = self.probability_space - else: - new_obj.probability_space = probability_space + new_obj.probability_space = self.probability_space + if probability_space is not None: + new_obj.force_probability_space(probability_space) return new_obj diff --git a/tsdate/core.py b/tsdate/core.py index 18f5f653..fb21d82a 100644 --- a/tsdate/core.py +++ b/tsdate/core.py @@ -652,9 +652,9 @@ def inside_pass(self, *, normalize=True, cache_inside=False, progress=None): nonfixed_samples = np.intersect1d(inside.nonfixed_node_ids(), self.ts.samples()) for u in nonfixed_samples: # this is in the same probability space as the prior, so we should be - # OK just to copy the prior values straight in (but we should check they - # are normalised so that they sum to unity) - inside[u][:] = self.priors.sum_to_unity(self.priors[u]) + # OK just to copy the prior values straight in. It's unclear to me (Yan) + # how/if they should be normalised, however + inside[u][:] = self.priors[u] if cache_inside: g_i = np.full(