Skip to content

Add LaTeX repr for distributions #2201

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 13 commits into from
May 24, 2017
Merged

Add LaTeX repr for distributions #2201

merged 13 commits into from
May 24, 2017

Conversation

fonnesbeck
Copy link
Member

@fonnesbeck 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,
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, figured it out.

@fonnesbeck
Copy link
Member Author

Odd failures related to multiprocessing in 2.7.

@ghost
Copy link

ghost 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
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

Copy link
Member

Choose a reason for hiding this comment

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

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

@twiecki
Copy link
Member

twiecki commented May 23, 2017

Looks like the whitespaces are still there.

@fonnesbeck
Copy link
Member Author

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

@fonnesbeck
Copy link
Member Author

Should be good to go now.

@twiecki twiecki merged commit 67de240 into master May 24, 2017
@twiecki twiecki deleted the latex_dists branch May 24, 2017 10:12
@ColCarroll
Copy link
Member

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
Copy link
Member Author

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
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
Copy link
Member Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants