All daft scripts will start with the creation of a PGM
object. This
object contains a list of Node
objects and Edge
objects
connecting them. You can also specify rendering parameters and other default
parameters when you initialize your PGM
.
daft.
PGM
(shape=None, origin=None, grid_unit=2.0, node_unit=1.0, observed_style='shaded', alternate_style='inner', line_width=1.0, node_ec='k', directed=True, aspect=1.0, label_params={}, dpi=None)¶The base object for building a graphical model representation.
Parameters: |
|
---|
add_edge
(name1, name2, directed=None, xoffset=0.0, yoffset=0.1, label=None, plot_params={}, label_params={}, **kwargs)¶Construct an Edge
between two named Node
objects.
Parameters: |
|
---|
add_node
(node, content='', x=0, y=0, scale=1.0, aspect=None, observed=False, fixed=False, alternate=False, offset=[0.0, 0.0], fontsize=None, plot_params={}, label_params=None, shape='ellipse')¶Add a Node
to the model.
Parameters: |
|
---|
add_plate
(plate, label=None, label_offset=[5, 5], shift=0, position='bottom left', fontsize=None, rect_params=None, bbox=None)¶Add a Plate
object to the model.
Parameters: |
|
---|
add_text
(x, y, label, fontsize=None)¶A subclass of plate to writing text using grid coordinates. Any
**kwargs
are passed through to PGM.Plate
.
Parameters: |
|
---|
render
(dpi=None)¶Render the Plate
, Edge
and Node
objects in
the model. This will create a new figure with the correct dimensions
and plot the model in this area.
Parameters: | dpi – (optional) The DPI value to use for rendering. |
---|
savefig
(fname, *args, **kwargs)¶Wrapper on matplotlib.Figure.savefig()
that sets default image
padding using bbox_inchaes = tight
.
*args
and **kwargs
are passed to matplotlib.Figure.savefig().
Parameters: |
|
---|
show
(dpi=None, *args, **kwargs)¶Wrapper on PGM.render()
that calls matplotlib.show()
immediately after.
Parameters: | dpi – (optional) The DPI value to use for rendering. |
---|
daft.
Node
(name, content, x, y, scale=1.0, aspect=None, observed=False, fixed=False, alternate=False, offset=[0.0, 0.0], fontsize=None, plot_params={}, label_params=None, shape='ellipse')¶The representation of a random variable in a PGM
.
Parameters: |
|
---|
get_frontier_coord
(target_xy, ctx, edge)¶Get the coordinates of the point of intersection between the
shape of the node and a line starting from the center of the node to an
arbitrary point. Will throw a SameLocationError
if the nodes
contain the same x and y coordinates. See the example of rectangle
below:
_____________
| | ____--X (target_node)
| __--X----
| X-- |(return coordinate of this point)
| |
|____________|
Target_xy: | (x float, y float) A tuple of coordinate of target node |
---|
render
(ctx)¶Render the node.
Parameters: | ctx – The _rendering_context object. |
---|
daft.
Edge
(node1, node2, directed=True, label=None, xoffset=0, yoffset=0.1, plot_params={}, label_params={})¶An edge between two Node
objects.
Parameters: |
|
---|
render
(ctx)¶Render the edge in the given axes.
Parameters: | ctx – The _rendering_context object. |
---|
daft.
Plate
(rect, label=None, label_offset=[5, 5], shift=0, position='bottom left', fontsize=None, rect_params=None, bbox=None)¶A plate to encapsulate repeated independent processes in the model.
Parameters: |
|
---|
render
(ctx)¶Render the plate in the given axes.
Parameters: | ctx – The _rendering_context object. |
---|
daft.
_rendering_context
(**kwargs)¶Parameters: |
|
---|
convert
(*xy)¶Convert from model coordinates to plot coordinates.