Skip to content

Commit

Permalink
add examples notebook and some docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
macks22 committed Jul 21, 2019
1 parent 530d5d0 commit 5b51f79
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 4 deletions.
11 changes: 7 additions & 4 deletions daft_builder/pgm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""
Core builder interfaces.
"""
import logging
import itertools

import matplotlib; matplotlib.use('Agg')
import daft
from toposort import toposort

Expand Down Expand Up @@ -131,8 +134,8 @@ def add_kwarg_defaults(self, symbol, kwargs):
kwargs['name'] = name

kwargs.setdefault('scale', 2)
if 'fixed' in kwargs:
kwargs['offset'] = (0, 10)
if 'fixed' in kwargs and 'offset' not in kwargs:
kwargs['offset'] = (0, -25) if self.placement.startswith('below') else (0, 10)

return kwargs

Expand Down Expand Up @@ -436,7 +439,7 @@ def place(self):
x_units = x + width
y_units = y + height

# Need to expand further to accomodate plates, if present
# Need to expand further to accommodate plates, if present
# Right now, we just assume plates are present all around.
# TODO: actually figure out if plates are present and only expand if so.
x_units += 0.3
Expand Down
6 changes: 6 additions & 0 deletions daft_builder/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Utility functions.
"""


def name_from_symbol(symbol):
starts_with_modifier = symbol.startswith('$\\')
symbol = symbol.strip('$').replace('\\', '')
Expand Down
242 changes: 242 additions & 0 deletions notebooks/examples.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import matplotlib; matplotlib.use('Agg')
import pytest

from daft_builder import utils


@pytest.mark.parametrize('symbol,expected', [
("test", "test"),
(r"$X$", "X"),
(r"$\theta$", "theta"),
(r"$\Sigma$", "Sigma"),
Expand Down

0 comments on commit 5b51f79

Please sign in to comment.