Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in calculate call when using mixture distribution #728

Open
AugustHao opened this issue Oct 15, 2024 · 0 comments
Open

error in calculate call when using mixture distribution #728

AugustHao opened this issue Oct 15, 2024 · 0 comments

Comments

@AugustHao
Copy link

If mixture is used to define distribution, and I try to run calculate on a parameter of the model with both posterior samples provided through values arg and number of simulations through nsim arg, then I get hit with error argument is of length zero.

It seems to have something to do with how the mixture distribution node is defined in dag, maybe some attribute is missing.

Note this error does not occur if running calculate without specifying either values or nsim


library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply
weights_raw <- uniform(0, 1, dim = 1)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
weights <- c(weights_raw, 1 - weights_raw)
alpha <- beta <- normal(0,1)
a <- mixture(normal(alpha, 0.5),
             normal(beta, 0.5),
             weights = weights
)
m <- model(a)
fit <- mcmc(m, n_samples = 500)
#> running 4 chains simultaneously on up to 8 CPU cores
#> 
#>     warmup                                           0/1000 | eta:  ?s              warmup ==                                       50/1000 | eta: 24s              warmup ====                                    100/1000 | eta: 13s              warmup ======                                  150/1000 | eta:  9s              

calculate(weights, values = fit, nsim = 10)
#> argument is of length zero

Created on 2024-10-15 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant