-
Notifications
You must be signed in to change notification settings - Fork 4
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
dimensions of data seem to be swapped in v6.4.0 #51
Comments
Hi Chris, will take a look tonight! Two things have changed (switch to JSON and future dropping of R notation, data section definitions are changing).
…Sent from my iPhone
On May 2, 2022, at 14:29, dfish ***@***.***> wrote:
Hi Rob,
It seems like the rows and columns are not imported to Stan correctly... or I am doing something stupid. I recieve an error in 6.4.0 but not in 5.6.
Would you be able to look into this please? Thanks!
temp_model.stan
data {
int n_rows;
int<lower=1> n_cols;
int<lower=0> x[n_rows,n_cols];
}
parameters {
real mu;
}
model {
mu ~ normal(0, 1);
}
run_temp_model
using StanSample, Random
tempdir = pwd() * "/tmp"
stan_path = "/home/dfish/cmdstan"
seed = 65445
Random.seed!(seed)
n_rows = 50
n_cols = 2
x = fill(0, n_rows, n_cols)
stan_data = Dict("x" => x, "n_rows"=>n_rows, "n_cols"=>n_cols)
println(size(stan_data["x"]))
# load the Stan model file
stream = open("temp_model.stan", "r")
model = read(stream, String)
close(stream)
stan_model = SampleModel("temp_model", model, tempdir)
stan_sample(
stan_model;
data = stan_data,
seed,
num_chains = 4,
num_samples = 1000,
num_warmups = 1000,
save_warmup = false
)
Error
Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=x; position=0; dims declared=(50,2); dims found=(2,50) (in '/home/dfish/.julia/dev/InterferenceEffectModelComparison/critical_tests/jrm/tmp/temp_model.stan', line 4, column 4 to column 34)Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=x; position=0; dims declared=(50,2); dims found=(2,50) (in '/home/dfish/.julia/dev/InterferenceEffectModelComparison/critical_tests/jrm/tmp/temp_model.stan', line 4, column 4 to column 34)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
Hi Chris, yes, you are correct. By switching to JSON, R's row-first and Julia's column first becomes visible. To get around it you can call Note: I could hide this in the call to JSON (update_json_files.jl) but want to think about that a bit. |
Rob, thanks for explaining. I wonder whether StanSample should make an adjustment to the JSON so that it is consistent with Julia's indexing system. In the present case, the error was caught be the dimensions were incorrect. However, the code would run and return invalid output if I used non-symmetrical n X n array. |
Ok, I think I have a solution for Dicts and NamedTuples. Will do some more tests with an Array of these and merge later today. One issue was I didn't want to go into JSON.jl and NamedTuples are immutable. |
Thanks for looking into this issue. I think it will be good to have consistency in the indexing scheme so people do not perform the wrong analysis. |
Looks like it has been merged. It didn’t update the tag, but will update. |
Thanks, Rob! The update has fixed the problem. |
Hi Rob, Thanks for putting work into getting stan and julia playing nice together and for the fix to the above issue. Sorry for raising this but the fix implemented does not seem to generalize to multidimensional arrays. I am using the master branch of StanSample:
Returns the following error: |
c7a425a Allow JSON data as a string (#60) 50fe2ec Update README examples section e380e82 Reword docstrings fb513e3 Reorganize and update documentation (#57) 96805fd Compile methods: split stanc args from make args, add default include path (#58) f62bf46 Fix broken link 676db6b Bump actions/setup-python from 2 to 4 (#55) 34f10dd Remove CmdStan Dependency (#51) 821883f Prefix any C-exposed symbols with `bs_` (#54) 81129b0 Add the option for autodiff Hessian calculations (#52) git-subtree-dir: deps/data/bridgestan git-subtree-split: c7a425aac54120bafa643b722ed24b2a32111782
Hi Rob,
It seems like the rows and columns are not imported to Stan correctly... or I am doing something stupid. I recieve an error in 6.4.0 but not in 5.6.
Would you be able to look into this please? Thanks!
temp_model.stan
run_temp_model
Error
The text was updated successfully, but these errors were encountered: