From 82f36d908b61ca5ae1192485f81c1d59c88a25b9 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Wed, 11 Jan 2023 10:55:12 +0000 Subject: [PATCH] Re-introduce normalize --- src/Control/Monad/Bayes/Population.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Control/Monad/Bayes/Population.hs b/src/Control/Monad/Bayes/Population.hs index be670df2..51c47833 100644 --- a/src/Control/Monad/Bayes/Population.hs +++ b/src/Control/Monad/Bayes/Population.hs @@ -22,6 +22,7 @@ module Control.Monad.Bayes.Population fromWeightedList, spawn, multinomial, + normalize, resampleMultinomial, systematic, resampleSystematic, @@ -50,6 +51,7 @@ import Control.Monad.Bayes.Weighted ( Weighted, applyWeight, extractWeight, + unweighted, weighted, withWeight, ) @@ -274,3 +276,7 @@ hoist :: Population m a -> Population n a hoist f = fromWeightedList . f . population + +-- | Normalizes the weights in the population so that their sum is 1. +normalize :: (Monad m) => Population m a -> Population m a +normalize = hoist unweighted . extractEvidence