Skip to content

Commit

Permalink
Merge pull request #3 from cboettig/main
Browse files Browse the repository at this point in the history
handle case of all new_wt being effectively 0
  • Loading branch information
mdietze authored Nov 1, 2023
2 parents 719e7ce + f10e3c2 commit 5b37080
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ smooth.params <- function(params,h=1){
return(params.star)
}

##` Particile filter
##` Particle filter
##` Updates state and parameter weights based on likelihood of the data
##` Will resample-move if effective sample size drops to <50%
##`
Expand All @@ -113,14 +113,20 @@ ParticleFilter <- function(out,params,dat,wt=1){
}
mult = mult*2
}
wt = like * wt ## update weights
new_wt = like * wt ## update weights

if ( all(new_wt == 0) ){
new_wt = (like/sum(like)) * (wt / sum(wt))
}
wt = new_wt
## hist(wt,main="Ensemble Weights") ## useful diagnostic if you're running line-by-line

## calculate effective sample size
wtn = wt/sum(wt) ## normalized weights
Neff = 1/sum(wtn^2)



## check if effective size has dropped below 50% threshold
if(Neff < ne/2){
## resample ensemble members in proportion to their weight
Expand Down

0 comments on commit 5b37080

Please sign in to comment.