Skip to content

Ensure auto-transformed variables use specified starting values #2046

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

Merged
merged 20 commits into from
Apr 20, 2017

Conversation

fonnesbeck
Copy link
Member

Currently starting values specified for variables that are auto-transformed are ignored by sample. This adds a function _transformed_init which ensures these values are properly transformed and included in the start dict.

Closes #2042

@fonnesbeck
Copy link
Member Author

This turned out to be much harder than I had anticipated. Interval transforms require bound information in order to properly transform values. This update now encodes the bound info into the transformed variable name, if it is a bounded or interval transform. So, for example:

alpha_interval_

now becomes:

alpha_interval_(-10,10)_

for example. I'm not sure I like this, but I don't see any easy way to supply this information so that starting values can be properly transformed. Please review.

cc @twiecki

pymc3/model.py Outdated
except KeyError:
pass
if bound_dict['a'] is not None or bound_dict['b'] is not None:
transformed_name += '({},{})_'.format(bound_dict['a'], bound_dict['b'])
self.transformed = model.Var(
Copy link
Member

Choose a reason for hiding this comment

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

Can't we monkey-patch lower and upper onto self.transformed? While not clean, it would be cleaner than this.

@twiecki
Copy link
Member

twiecki commented Apr 17, 2017

I have no problem adding this to the name, but a problem with reading it out. This is definitely a point where we should take a step back and think how we painted ourselves into this corner.

@fonnesbeck
Copy link
Member Author

I agree. Probably time to overhaul the initialization procedure.

@fonnesbeck
Copy link
Member Author

OK, this should suffice. I have just pushed the model from the context into _soft_update so that transformation can be extracted. The transform instance is now an attribute of TransformedRV so that it can be retrieved as needed.

@@ -91,6 +94,98 @@ def mapf(self, f):
return Compose(f, self.rmap)


class ListArrayOrdering(object):
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't show up.

@fonnesbeck
Copy link
Member Author

Fixed.

@twiecki
Copy link
Member

twiecki commented Apr 20, 2017

Not sure I see how this fixes the issue?

@fonnesbeck
Copy link
Member Author

It transforms initial values specified on the original scale and inserts them into the start dict for the transformed variable.

@fonnesbeck
Copy link
Member Author

There is an example in the test.

@twiecki
Copy link
Member

twiecki commented Apr 20, 2017

I get it now. Much cleaner than before, the only nit-pick is that _soft_update was a general purpose function before and is now tied to the model. Not a big deal though, we can merge.

@fonnesbeck
Copy link
Member Author

I can revert it to a general function and decorate it if you like.

@twiecki
Copy link
Member

twiecki commented Apr 20, 2017

Is the function used anywhere else? Maybe we can just rename it.

@fonnesbeck
Copy link
Member Author

Not used elsewhere. I've renamed it.

@twiecki
Copy link
Member

twiecki commented Apr 20, 2017

Cool, LGTM.

@fonnesbeck fonnesbeck merged commit 6b39941 into master Apr 20, 2017
This was referenced Apr 21, 2017
@junpenglao junpenglao deleted the transformed_init_fix branch June 26, 2017 12:27
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.

2 participants