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

Added missing values handling. #682

Merged
merged 5 commits into from
Feb 12, 2019
Merged

Added missing values handling. #682

merged 5 commits into from
Feb 12, 2019

Conversation

trappmartin
Copy link
Member

@trappmartin trappmartin commented Feb 11, 2019

This PR adds missing values handling for the internal Turing.Chain object and Sample object. This work is required for BNP related models.

Changes:

  • Removed value2 field which contains redundant information.
  • Changed getindex function to use MCMCChain.names2inds
  • Chain is now immutable (I hope this doesn't break anything!)
  • value field supports missing values.
  • Refactored constructor and flatten functions.
  • Added more tests.

Supported indexing:

@model testmodel() = begin
    x ~ Normal()
    y ~ Dirichlet([0.5, 0.5])
    z ~ Wishart(7, [1 0.5; 0.5 1])
end

...
chain = sample(mf, SMC(100))

chain["x"] # => 100 x 1 x 1 matrix
chain[:x] #  == chain["x"]
chain["y[1]"] #  => 100 x 1 x 1 matrix
chain[["y[1]", "y[2]"]] #  => 100 x 2 x 1 matrix
chain[:y] # == chain[["y[1]", "y[2]"]]
chain["z[1, 1]"] # => 100 x 1 x 1 matrix
chain[:z] # => 100 x 4 x 1 matrix
reshape(mean(chain[:z], dims = [1]), 2, 2) # average z matrix

@trappmartin trappmartin requested a review from cpfiffer February 11, 2019 17:58
@trappmartin
Copy link
Member Author

@cpfiffer This PR is ready to merge from my side. Could you have a look? Thx!

@trappmartin trappmartin self-assigned this Feb 11, 2019
@cpfiffer
Copy link
Member

Looks good to me. I think we can merge, unless anyone else has anything to say on this.

@trappmartin trappmartin merged commit a6bd6b2 into master Feb 12, 2019
@yebai
Copy link
Member

yebai commented Feb 14, 2019

Nice, thanks @trappmartin!

@yebai yebai deleted the tm/chain branch June 7, 2019 14:58
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.

3 participants