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

preallocating an array of random variables, getting varname As used multiple times in model (subsumes As[1]) #2284

Closed
SimonEnsemble opened this issue Jul 9, 2024 · 1 comment

Comments

@SimonEnsemble
Copy link

I'd like to create a prior distribution on a function A(x) for x \in [0, 1]. to do so, I represent the function via a list of discrete values of the function evaluated at N points on a grid over [0, 1]. I wish for A(0) to have a uniform prior, but then have the rest of the function values sequentially correlated for a smoothness prior. in a previous version of Turing.jl, I was doing:

As ~ filldist(Normal(), N) # cm²
As[1] ~ Uniform(0.0, 1.0)
for i in 2:N
   As[i] ~ As[i - 1] + Normal(0.0, γ) 
end

but now in v0.33.1, I get the error varname As used multiple times in model (subsumes As[1]).

how can I pre-allocate an array of random variables, then specify their distributions later?

@SimonEnsemble SimonEnsemble changed the title preallocating an array of variables, getting varname As used multiple times in model (subsumes As[1]) preallocating an array of random variables, getting varname As used multiple times in model (subsumes As[1]) Jul 9, 2024
@SimonEnsemble
Copy link
Author

ah, this seems to work. the key was to not use ~ twice.

As = Vector{Real}(undef, N)
As[1] ~ Uniform(0.0, 1.0)
for i in 2:N
     As[i] ~ As[i - 1] + Normal(0.0, γ)		
end

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