-
Notifications
You must be signed in to change notification settings - Fork 222
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
TArray and multinomial #899
Comments
Your instantiation of a It migth also be a good idea to change the code and use a Matrix instead of a Vector of Vectors as you know the size anyways, i.e. @model model_function(y) = begin
N ~ Poisson(5)
θ ~ Normal(0,1)
M = length(y)
s = TArray{Int64}(10,M)
for i in 1:M
s[:,i] ~ Multinomial(N,10)
y[i] ~ somedistribution(s[:,i],θ)
end
end Alternatively, you can also write the following: @model model_function(y, ::Type{Ts}=Matrix{Int}) = begin
N ~ Poisson(5)
θ ~ Normal(0,1)
M = length(y)
s = Ts(10,M)
for i in 1:M
s[:,i] ~ Multinomial(N,10)
y[i] ~ somedistribution(s[:,i],θ)
end
end which automatically transforms |
Thank you so much! I think I found the source of my confusion. It appears that TArray(Int64,2) is an alias for TArray{Int64}(2)
but it does not extend to multidimensional arrays, which prompted me to go down various dead ends. |
Hi all-
I would like to ask a few related questions about the use of TArray in a model that uses particle Giggs sampling. Here is a simplified version of the model that I am developing:
The latent parameter s is a vector of vectors, such that each vector
s[i]
follows a multinomial distribution.somedistribution
basically transformss[i]
into a log probability using a softmax rule (not defined here for simplicity). I receive the following error:ERROR: MethodError: Cannot
convertan object of type Array{Int64,1} to an object of type TArray{Int64,1}
First, I want to verify that the inner vector of s should be a
TArray
. If it is not necessary, I could use[Vector{Int64}(undef,10) for _ in 1:M]
. However, assuming that I need to use aTArray
, how can I allow eachs[i]
to follow a multinomial distribution? My first attempt was to create a new distribution and collect the elements from the multinomial sample in a TArray:Replacing Multinomial with TMultinomial results in the following error:
MethodError: no method matching iterate(::TMultinomial{Int64,Int64})
This happens even though I overloaded broadcastable. My second attempted solution is the following:
This seems to work in the sense that it does not crash and reaches the print statement, but it seems inelegant and I am concerned there might be some unintended consequences.
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: