-
-
Notifications
You must be signed in to change notification settings - Fork 66
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I like to initialise a new fit with the results from a previous run which fails for models with nested array structures. The issue is that the nested array structure is not carried forward to the initials correctly.
To Reproduce
Example model (referred to as bernoulli-array.stan):
data {
int<lower=0> N;
array[N] int<lower=0,upper=1> y;
}
parameters {
array[1,1] real<lower=0,upper=1> theta;
}
model {
theta[1,1] ~ beta(1,1); // uniform prior on interval 0,1
y ~ bernoulli(theta[1,1]);
}ba <- cmdstanr::cmdstan_model("bernoulli-array.stan")
post <- ba$sample(list(N=20, y=rbinom(20, 1, 0.2)), refresh=250, init=0.2, seed = 4679453)
post2 <- ba$sample(list(N=20, y=rbinom(20, 1, 0.2)), refresh=250, init=post, seed = 4679453)
The second fit fails for me with:
post2 <- ba$sample(list(N=20, y=rbinom(20, 1, 0.2)), refresh=250, init=post, seed = 4679453)
> Merging chains in order to subset via 'draw'.
Running MCMC with 4 sequential chains...
Chain 1 Unrecoverable error evaluating the log probability at the initial value.
Chain 1 Exception: mismatch in number dimensions declared and found in context; processing stage=parameter initialization; variable name=theta; dims declared=(1,1); dims found=() (in '/scratch/weberse2/tmp/RtmpZLNHUy/model-33207a2e2840a8.stan', line 6, column 2 to column 41)
Warning: Chain 1 finished unexpectedly!
Chain 2 Unrecoverable error evaluating the log probability at the initial value.
Chain 2 Exception: mismatch in number dimensions declared and found in context; processing stage=parameter initialization; variable name=theta; dims declared=(1,1); dims found=() (in '/scratch/weberse2/tmp/RtmpZLNHUy/model-33207a2e2840a8.stan', line 6, column 2 to column 41)
Warning: Chain 2 finished unexpectedly!
Chain 3 Unrecoverable error evaluating the log probability at the initial value.
Chain 3 Exception: mismatch in number dimensions declared and found in context; processing stage=parameter initialization; variable name=theta; dims declared=(1,1); dims found=() (in '/scratch/weberse2/tmp/RtmpZLNHUy/model-33207a2e2840a8.stan', line 6, column 2 to column 41)
Warning: Chain 3 finished unexpectedly!
Chain 4 Unrecoverable error evaluating the log probability at the initial value.
Chain 4 Exception: mismatch in number dimensions declared and found in context; processing stage=parameter initialization; variable name=theta; dims declared=(1,1); dims found=() (in '/scratch/weberse2/tmp/RtmpZLNHUy/model-33207a2e2840a8.stan', line 6, column 2 to column 41)
Warning: Chain 4 finished unexpectedly!
Warning: Use read_cmdstan_csv() to read the results of the failed chains.
Warning messages:
1: All chains finished unexpectedly! Use the $output(chain_id) method for more information.
2: No chains finished successfully. Unable to retrieve the fit.
Expected behavior
This should simply work.
Operating system
macOS Sequoia
CmdStanR version number
0.8.1
CmdStan: 2.34.1
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working