Skip to content

Turing v0.45#697

Merged
penelopeysm merged 29 commits intomainfrom
py/up
May 5, 2026
Merged

Turing v0.45#697
penelopeysm merged 29 commits intomainfrom
py/up

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented May 2, 2026

These are all just interface changes for MCMCChains -> FlexiChains, there aren't any other content changes. I also took the liberty to remove the minituring pages as they're several versions outdated (we don't have SamplingContext or assume anymore).

Closes #677
Inadvertently closes #483 since FlexiChains has better docs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Preview the changes: https://turinglang.org/docs/pr-previews/697
Please avoid using the search feature and navigation bar in PR previews!

@penelopeysm penelopeysm requested a review from sunxd3 May 4, 2026 00:15
Copy link
Copy Markdown
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for doing this, Penny

Comment thread usage/sampling-options/index.qmd Outdated
# was rejected -- that is why we seed the sampling in this section).
chn1[:x][end], chn2[:x][1]

chn1[@varname(x)][end], chn1[@varname(y)][end]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused, should this be comparing chn1[y] with chn2[x]?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, somehow I got confused myself.

Comment thread usage/predictive-distributions/index.qmd Outdated
# Extract the number of clusters for each sample of the Markov chain.
k = map(
t -> length(unique(vec(chain[t, MCMCChains.namesingroup(chain, :z), :].value))),
t -> length(unique(chain[@varname(z), iter=t])),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(courtesy of Claude)

chain[@varname(z), iter=t] keeps the chain dimension, so for a single-chain run with N-element z it returns a 1×N DimMatrix. unique on a 2-D array returns unique rows, not unique elements:

unique([1 2 3])  # → [[1 2 3]] — length 1

So k will end up 1 for nearly every iteration and the cluster-count plot won't match the prose right below it about converging to ~3 clusters.

Suggested change
t -> length(unique(chain[@varname(z), iter=t])),
t -> length(unique(chain[@varname(z), iter=t, chain=1])),

sunxd:
https://turinglang.org/docs/pr-previews/697/tutorials/infinite-mixture-models/ near the bottom the plot does look wrong

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no idea that unique did that and must have missed this one, thanks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Claude's not right:

julia> unique([1 2 3])
3-element Vector{Int64}:
 1
 2
 3

But I realised what the issue was, it's that chain[@varname(z)] is an array of vectors, not a 3D matrix. So just passing stack=true makes that right.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! Sorry I should have verified

Comment thread tutorials/hidden-markov-models/index.qmd Outdated
Comment thread usage/sampling-options/index.qmd Outdated
::: {.callout-warning}
## `resume_from`

The `resume_from` argument has been removed in Turing v0.41; please use `initial_state=loadstate(chn)` instead, as described here.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes it's only(loadstate(chn))?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on the exact invocation of sample so it's a bit finicky, but I rephrased to clarify.

@penelopeysm penelopeysm requested a review from sunxd3 May 5, 2026 13:12
@penelopeysm
Copy link
Copy Markdown
Member Author

Thank you! :)

@penelopeysm penelopeysm merged commit 12aefaf into main May 5, 2026
2 checks passed
@penelopeysm penelopeysm deleted the py/up branch May 5, 2026 13:17
github-actions Bot added a commit that referenced this pull request May 5, 2026
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

Successfully merging this pull request may close these issues.

Remove minituring pages Better describe how to get data out of chain elements in tutorials

2 participants