Skip to content

Commit

Permalink
added faster version of SB function
Browse files Browse the repository at this point in the history
  • Loading branch information
Fradenti committed Nov 3, 2023
1 parent 4967ff7 commit 6845cc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ out
#> Model estimated on 290 total observations and 2 groups
#> Total MCMC iterations: 3000
#> maxL: 50 - maxK: 50
#> Elapsed time: 1.548 secs
#> Elapsed time: 1.573 secs
clusters <- estimate_clusters(out, burnin = 2000)
clusters
#>
Expand Down
2 changes: 1 addition & 1 deletion man/SANple-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/common_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ arma::vec rdirichlet(arma::vec par)
return(out) ;
}


arma::vec relabel_arma(arma::vec cluster)
{
int n = cluster.n_elem ;
Expand Down
16 changes: 15 additions & 1 deletion src/funs_cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ int compute_trunc(double u_min, double kappa)
// Compute stick-breaking weights starting from the vector of beta r.v. Beta(a_k,b_k)
// Sethuraman (1994) construction
arma::vec stick_breaking(arma::vec beta_var)
{
int len = beta_var.n_elem ;
arma::vec out(len) ;
out(0) = beta_var(0) ;
arma::vec cs_log_one_m_beta = arma::cumsum(log(1.0-beta_var));
for(int k = 1; k < len; k++)
{
out(k) = exp( log(beta_var(k)) + cs_log_one_m_beta(k-1)) ;
}
return(out) ;
}

/* older version - to be removed
arma::vec stick_breaking(arma::vec beta_var)
{
int len = beta_var.n_elem ;
arma::vec out(len) ;
Expand All @@ -37,7 +51,7 @@ arma::vec stick_breaking(arma::vec beta_var)
}
return(out) ;
}

*/


// This function performs steps 1-4 of Algorithm 1 of Denti et al. (2021):
Expand Down

0 comments on commit 6845cc0

Please sign in to comment.