greta-dev / greta-dev/greta

error in calculate call when using mixture distribution

Open
#728 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
607
Forks
67
Avg merge
3d 8h
Merged PRs (30d)
1

Description

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`

---

``` r
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](https://reprex.tidyverse.org)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.