Skip to content

fixed_ get_variable_name #2225

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 5 commits into from
May 26, 2017
Merged

fixed_ get_variable_name #2225

merged 5 commits into from
May 26, 2017

Conversation

junpenglao
Copy link
Member

bug fixed for issue #2224

bug fixed for issue #2224
@junpenglao junpenglao requested a review from fonnesbeck May 26, 2017 14:40
@fonnesbeck
Copy link
Member

Yes, that should do it. Should probably insert a repr test somewhere.

@junpenglao
Copy link
Member Author

@fonnesbeck I agree, I can't think of a good way to do it though.
Also, it would be great to also add this feature to gp.

@fonnesbeck
Copy link
Member

Yes, we should add it to GP and all the covariances, but that can wait until post-3.1.

We can test them by calling _repr_latex_ explicitly, I suppose.

@junpenglao
Copy link
Member Author

But that would mean we need to test them case by case? It would increase the code size quite a lot.

@fonnesbeck
Copy link
Member

fonnesbeck commented May 26, 2017

I wouldnt test all of them, maybe just one per module to ensure that its imported and it works. Could even piggyback it on an existing test(s).

@fonnesbeck
Copy link
Member

@junpenglao do you want me to merge this and add a test separately?

@junpenglao
Copy link
Member Author

junpenglao commented May 26, 2017

I am working on a test, something like:

with pm.Model() as model:
    x0 = pm.Binomial('Discrete', p=.5, n=10)
    x1 = pm.Normal('Continuous', mu=0., sd=1.)
    x2 = pm.GaussianRandomWalk('timeseries', mu=x1, sd=5., shape=10)
assert x0._repr_latex_(), '$Discrete \\sim \\text{Binomial}(\\mathit{n}=10, \\mathit{p}=0.5)$'
assert x1._repr_latex_(), '$Continuous \\sim \\text{Normal}(\\mathit{mu}=0.0, \\mathit{sd}=1.0)$'

However while doing so i seems to find another bug:

x2._repr_latex_()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-3a78dd7af59c> in <module>()
      3     x1 = pm.Normal('Continuous', mu=0., sd=1.)
      4     x2 = pm.GaussianRandomWalk('timeseries', mu=x1, sd=5., shape=10)
----> 5 x2._repr_latex_()

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymc3/model.py in _repr_latex_(self, name, dist)
    830         if dist is None:
    831             dist = self.distribution
--> 832         return self.distribution._repr_latex_(name=name, dist=dist)
    833 
    834     @property

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymc3/distributions/timeseries.py in _repr_latex_(self, name, dist)
    100         sd = dist.sd
    101         return r'${} \sim \text{{GaussianRandomWalk}}(\mathit{{mu}}={}, \mathit{{sd}}={})$'.format(name,
--> 102                                                 get_variable_name(mu),
    103                                                 get_variable_name(sd))
    104 

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymc3/util.py in get_variable_name(variable)
     81     returns the argument name.
     82     """
---> 83     name = variable.name
     84     if name is None:
     85         if hasattr(variable, 'get_parents'):

AttributeError: 'float' object has no attribute 'name'

@fonnesbeck
Copy link
Member

Good to know. We typically cast all constants passed to distributions into tensors, so apparently that's not happening in the GRW.

@junpenglao
Copy link
Member Author

@fonnesbeck OK, fixing that as well.

@fonnesbeck
Copy link
Member

Yes, it should be, for example:

self.mu = mu = tt.as_tensor_variable(mu)

cast constants to tensors
@fonnesbeck
Copy link
Member

Good to merge once tests pass.

@fonnesbeck
Copy link
Member

Looks like a casting issue

tidy up  pm.timeseries and fixed *arg for `tau`
fixed _repr_latex for Normalmixture
@junpenglao
Copy link
Member Author

@fonnesbeck it's the int in LKJCorr, fixing now.

@twiecki
Copy link
Member

twiecki commented May 26, 2017

Is this good to merge?

@junpenglao
Copy link
Member Author

@twiecki not yet, i am working on a test for _repr_latex_

with small bug fix in MvStudentT
@fonnesbeck fonnesbeck merged commit 255e8fc into pymc-devs:master May 26, 2017
@junpenglao junpenglao deleted the bugfixed_get_variable_name branch May 26, 2017 22:06
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