get_moments_cpp | R Documentation |
Get all moments that need update when iterating over a total of p internal and leaf nodes
get_moments_cpp( prob, prob_gamma, mu_gamma, sigma_gamma, mu_alpha, Sigma_alpha, anc, cardanc )
prob |
variational probabilities for |
prob_gamma |
should be fixed: |
mu_gamma |
variational Gaussian means (for |
sigma_gamma |
variational Gaussian variances (for |
mu_alpha |
variational Gaussian mean vectors (for |
Sigma_alpha |
variational Gaussian variances (for
|
anc |
a list of pL vectors, each vector has the node ids of the ancestors; lengths may differ. The ancestors include the node concerned. |
cardanc |
a numeric vector of length pL; integers. The number of ancestors for each leaf node |
a List
return List::create(Named("E_beta")=E_beta, Named("E_beta_sq")=E_beta_sq, Named("E_eta")=E_eta, Named("E_eta_sq")=E_eta_sq);
# illustrates the calculation of the various moments: prob = 0.2 mu1 = 2 mu0 = 0 sigma1 = 3 sigma0 = 1 N = 10000 s = rbinom(N,1,prob) y <- rep(NA,length(s)) for (i in seq_along(s)){ y[i] <- rnorm(1,mu1,sqrt(sigma1))*s[i] + rnorm(1,mu0,sqrt(sigma0))*(1-s[i]) } var(s*y) prob*(sigma1+(1-prob)*mu1^2) mean(y^2) prob*(sigma1+mu1^2) + (1-prob)*sigma0 mean(s*y^2) prob*(sigma1+mu1^2) mean(s*y) prob*mu1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.