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

Refactoring VarName: new indexing scheme #484

Closed
yebai opened this issue Sep 1, 2018 · 3 comments
Closed

Refactoring VarName: new indexing scheme #484

yebai opened this issue Sep 1, 2018 · 3 comments

Comments

@yebai
Copy link
Member

yebai commented Sep 1, 2018

At the moment, Turing internally stores and index parameters using two different naming schemes

{model_id, original_varname}:counter # VarInfo
original_varname  # Chain

This causes a lot of issues, e.g.

These issues can be resolved together with a consistent naming scheme used by all data structures such as Chain, VarInfo and inference algorithms. One possible naming scheme is

@model mdemo(y) = begin
 #  {model_id, unique_scope_id, original_varname, indexing}:counter 
 #       counter increases everytime mdemo is called
   x ~ Normal   
   z ~ Discrete  
   for i = 1:z
       # counter increases for each loop iteration
       #      {model_id, unique_scope_id, original_varname, indexing}:counter 
       w ~ Normal  
   end
end

Both VarInfo and Chain can internally use unique_compiletime_id:counter as their index. At the same time, we can also support the following

c = sample(mdemo(y), alg)

# return all vars with the same unique_compiletime_id
c[:unique_var_id][counter]

# return all vars with the same name: x
#  note unique_compiletime_id may be different for different entries
c[:x]  

This indexing scheme supports stochastic control flows (e.g. conditional, loops). It can also support compositional modelling #139 since var names don't clash with each other even when mdemo is called by another model.

Related issues: #456

@trappmartin @xukai92 @emilemathieu

@yebai
Copy link
Member Author

yebai commented Sep 1, 2018

Ps. I have attempted to enumerate all clashing name cases. However, there might be cases that I'm not aware. Please suggest any special cases that can potentially break the proposed naming scheme.

@yebai
Copy link
Member Author

yebai commented Sep 1, 2018

For sanity checks, we might want to store the domain constraints of each parameter and verify them during replaying.

@yebai
Copy link
Member Author

yebai commented Dec 17, 2019

Closed by #965

@yebai yebai closed this as completed Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant