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

The Infinite Mixture Models tutorial error #1589

Closed
patwa67 opened this issue Apr 16, 2021 · 6 comments
Closed

The Infinite Mixture Models tutorial error #1589

patwa67 opened this issue Apr 16, 2021 · 6 comments

Comments

@patwa67
Copy link

patwa67 commented Apr 16, 2021

It is not possible to use:

k = map(t -> length(unique(chain[:z].value[t,:,:])), 1:iterations);

it throws the error:
ERROR: ArgumentError: index z not found

@devmotion
Copy link
Member

This example uses an old version of MCMCChains. With newer versions you have to use

zvars = namesingroup(chain, :z)
k = map(t -> length(unique(chain[t, zvars, :])), 1:iterations)

(or something similar based on namesingroup, the code is untested). The issue will be fixed by the reorganization and updates in TuringLang/docs#113.

@patwa67
Copy link
Author

patwa67 commented Apr 16, 2021

No it doesn't work. The following works, but it just produces a vector of ones:

k = map(t -> length(unique(get_params(chain[t,zvars,:]))), 1:iterations);

@devmotion
Copy link
Member

I assume the problem is that you use get_params: it returns a NamedTuple of parameters (see https://turinglang.github.io/MCMCChains.jl/dev/chains/#MCMCChains.get_params-Tuple{Chains}). I guess

k = map(t -> length(unique(Array(chain[t, zvars, :]))), 1:iterations)

is better (I assumed, apparently incorrectly since it failed (?), that chain[t, zvars, :] returns already an array).

@patwa67
Copy link
Author

patwa67 commented Apr 16, 2021

That works better, but what is the logic behind this array construction?

@devmotion
Copy link
Member

Array(chain) returns an array of the values in the chain, where as default the different chains are appended (i.e., the output has #iterations * #chains rows and #parameters columns): https://turinglang.github.io/MCMCChains.jl/dev/getting-started/#Exporting-Chains

@patwa67
Copy link
Author

patwa67 commented Apr 19, 2021

OK, fine. I have run this example with some different settings and samplers. One strange thing occurs when I change from the SMC() (which mixes badly) to the PG() sampler. When I use SMC() the output in zvars and consequently the k variable corresponds well with the output in the locations variable muvars = namesingroup(chain, :μ), i.e. there is one location for each cluster. However, when the PG() sampler is used, this is no longer the case, i.e. there are more locations than clusters. However, the number of clusters seems to be correct.

@patwa67 patwa67 closed this as completed Apr 29, 2021
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

2 participants