Skip to content

Commit

Permalink
Remove sum_to_unity
Browse files Browse the repository at this point in the history
  • Loading branch information
hyanwong committed Sep 6, 2022
1 parent 6b523bd commit c1c3861
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
20 changes: 3 additions & 17 deletions tsdate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions tsdate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c1c3861

Please sign in to comment.