Skip to content

Commit

Permalink
now using logspace_add for discrete-PMFs...
Browse files Browse the repository at this point in the history
... i.e., zero-inflated Poisson and zero-inflated NegBin
  • Loading branch information
James-Thorson committed Jul 23, 2017
1 parent 3a0d8c8 commit ecfb4c1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions inst/executables/VAST_v2_7_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ Type objective_function<Type>::operator() ()
// Zero-inflated negative binomial (not numerically stable!)
var_i(i) = R2_i(i)*(1.0+SigmaM(c_i(i),0)) + pow(R2_i(i),2.0)*SigmaM(c_i(i),1);
if( b_i(i)==0 ){
LogProb2_i(i) = log( (1-R1_i(i)) + dnbinom2(Type(0.0), R2_i(i), var_i(i), false)*R1_i(i) ); // Pr[X=0] = 1-phi + NB(X=0)*phi
//LogProb2_i(i) = log( (1-R1_i(i)) + dnbinom2(Type(0.0), R2_i(i), var_i(i), false)*R1_i(i) ); // Pr[X=0] = 1-phi + NB(X=0)*phi
LogProb2_i(i) = logspace_add( log(1-R1_i(i)), dnbinom2(Type(0.0),R2_i(i),var_i(i),true)+log(R1_i(i)) ); // Pr[X=0] = 1-phi + NB(X=0)*phi
}else{
LogProb2_i(i) = dnbinom2(b_i(i), R2_i(i), var_i(i), true) + log(R1_i(i)); // Pr[X=x] = NB(X=x)*phi
}
Expand All @@ -546,7 +547,8 @@ Type objective_function<Type>::operator() ()
if(ObsModel(0)==7){
// Zero-inflated Poisson
if( b_i(i)==0 ){
LogProb2_i(i) = log( (1-R1_i(i)) + dpois(Type(0.0), R2_i(i), false)*R1_i(i) ); // Pr[X=0] = 1-phi + Pois(X=0)*phi
//LogProb2_i(i) = log( (1-R1_i(i)) + dpois(Type(0.0), R2_i(i), false)*R1_i(i) ); // Pr[X=0] = 1-phi + Pois(X=0)*phi
LogProb2_i(i) = logspace_add( log(1-R1_i(i)), dpois(Type(0.0),R2_i(i),true)+log(R1_i(i)) ); // Pr[X=0] = 1-phi + Pois(X=0)*phi
}else{
LogProb2_i(i) = dpois(b_i(i), R2_i(i), true) + log(R1_i(i)); // Pr[X=x] = Pois(X=x)*phi
}
Expand Down

0 comments on commit ecfb4c1

Please sign in to comment.