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

Add LaTeX repr for distributions #2201

Merged
merged 13 commits into from May 24, 2017

Conversation

Projects
None yet
5 participants
@fonnesbeck
Copy link
Member

fonnesbeck commented May 19, 2017

This PR adds LaTeX output when distributions are shown in Jupyter notebooks. The initial commit has this implemented for all continuous variables. Discrete, MV to come.

if dist is None:
dist = self
sd = dist.sd
return r'$%s \sim \text{HalfNormal}(\mathit{sd}=%s)$' % (name,

This comment has been minimized.

@twiecki

twiecki May 19, 2017

Member

how about new-style r'{}'.format(...)? https://pyformat.info/

This comment has been minimized.

@fonnesbeck

fonnesbeck May 19, 2017

Member

The new style does not like strings with curly braces in them. This was easier.

This comment has been minimized.

@fonnesbeck

fonnesbeck May 19, 2017

Member

OK, figured it out.

@fonnesbeck

This comment has been minimized.

Copy link
Member

fonnesbeck commented May 19, 2017

Odd failures related to multiprocessing in 2.7.

@a-rodin

This comment has been minimized.

Copy link
Contributor

a-rodin commented May 21, 2017

The failures occur because of usage functools.partial with bound method as an argument.

Multiprocessing tries to pickle resulting function objects, but fails because bound methods are not pickleable in Python 2, although they are pickleable in Python 3. For example, this code works with Python 3, but not Python 2:

import pickle
class Foo:
    def bar(self):
        return 3
pickle.dumps(Foo().bar)

I tried to replace invocations of functools.partial by direct implementations of _repr_latex_ method in my fork and the tests seem to work there.

@twiecki

This comment has been minimized.

Copy link
Member

twiecki commented May 22, 2017

Thanks @a-rodin. The best approach is to do a PR onto this PR (specifically, the latex_dists branch) with your fixes.

@fonnesbeck fonnesbeck changed the title WIP: Add LaTeX repr for distributions Add LaTeX repr for distributions May 23, 2017



class GARCH11(distribution.Continuous):
"""
GARCH(1,1) with Normal innovations. The model is specified by

This comment has been minimized.

@twiecki

twiecki May 23, 2017

Member

I think these should not be here, not quite sure.

@twiecki

This comment has been minimized.

Copy link
Member

twiecki commented May 23, 2017

Looks like the whitespaces are still there.

@fonnesbeck

This comment has been minimized.

Copy link
Member

fonnesbeck commented May 23, 2017

It appears that My Favorite Text Editor sucks at whitespace removal, even inserting it in some places it did not exist.

@fonnesbeck

This comment has been minimized.

Copy link
Member

fonnesbeck commented May 23, 2017

Should be good to go now.

@twiecki twiecki merged commit 67de240 into master May 24, 2017

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-1.8%) to 88.35%
Details

@twiecki twiecki deleted the latex_dists branch May 24, 2017

@ColCarroll

This comment has been minimized.

Copy link
Member

ColCarroll commented Jun 8, 2017

would this be reasonable to propagate to models and maybe even the traces? It looks like it is more work than '\n'.join([repr(v) for v in self.vars]).

@fonnesbeck

This comment has been minimized.

Copy link
Member

fonnesbeck commented Jun 13, 2017

I think having a _repr_latex_ for a model would be a great idea. Would be a nice way to get an overview of the model, particularly if it is built up over a number of cells.

@ferrine

This comment has been minimized.

Copy link
Member

ferrine commented Jul 28, 2017

vote for renaming _repr_latex_ to __latex__. The reason is that single leading underscore denotes private attributes and methods. But _latex_repr_ is not private at all. As for __latex__ it is our magic.

@fonnesbeck

This comment has been minimized.

Copy link
Member

fonnesbeck commented Jul 28, 2017

We aren’t at liberty to change it because they are hooks used by IPython. If you change the name they won’t work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment