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
.
The base object for building a graphical model representation.
shape – (optional) The number of rows and columns in the grid. Will automatically determine is not provided.
origin – (optional) The coordinates of the bottom left corner of the plot. Will automatically determine if not provided.
grid_unit – (optional) The size of the grid spacing measured in centimeters.
node_unit – (optional) The base unit for the node size. This is a number in centimeters that sets the default diameter of the nodes.
observed_style – (optional)
How should the “observed” nodes be indicated? This must be one of:
"shaded"
, "inner"
or "outer"
where inner
and
outer
nodes are shown as double circles with the second circle
plotted inside or outside of the standard one, respectively.
alternate_style – (optional)
How should the “alternate” nodes be indicated? This must be one of:
"shaded"
, "inner"
or "outer"
where inner
and
outer
nodes are shown as double circles with the second circle
plotted inside or outside of the standard one, respectively.
node_ec – (optional) The default edge color for the nodes.
node_fc – (optional) The default face color for the nodes.
plate_fc – (optional) The default face color for plates.
directed – (optional) Should the edges be directed by default?
aspect – (optional) The default aspect ratio for the nodes.
label_params – (optional)
Default node label parameters. See PGM.Node
for details.
dpi – (optional) Set DPI for display and saving files.
Construct an Edge
between two named Node
objects.
name1 – The name identifying the first node.
name2 – The name identifying the second node. If the edge is directed, the arrow will point to this node.
directed – (optional)
Should the edge be directed from node1
to node2
? In other
words: should it have an arrow?
label – (optional) A string to annotate the edge.
xoffset – (optional) The x-offset from the middle of the arrow to plot the label. Only takes effect if label is defined in plot_params.
yoffset – (optional) The y-offset from the middle of the arrow to plot the label. Only takes effect if label is defined in plot_params.
plot_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.FancyArrow
constructor.
label_params – (optional)
A dictionary of parameters to pass to the
matplotlib.axes.Axes.annotate
constructor.
Add a Node
to the model.
node – The plain-text identifier for the nodeself.
Can also be the Node
to retain backward compatibility.
content – The display form of the variable.
x – The x-coordinate of the node in model units.
y – The y-coordinate of the node.
scale – (optional)
The diameter (or height) of the node measured in multiples of
node_unit
as defined by the PGM
object.
aspect – (optional) The aspect ratio width/height for elliptical nodes; default 1.
observed – (optional) Should this be a conditioned variable?
fixed – (optional)
Should this be a fixed (not permitted to vary) variable?
If True, modifies or over-rides diameter
, offset
,
facecolor
, and a few other plot_params
settings.
This setting conflicts with observed
.
alternate – (optional) Should this use the alternate style?
offset – (optional)
The (dx, dy)
offset of the label (in points) from the default
centered position.
fontsize – (optional) The fontsize to use.
plot_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.Ellipse
constructor.
label_params – (optional)
A dictionary of parameters to pass to the
matplotlib.text.Annotation
constructor. Any kwargs not
used by Annontation get passed to matplotlib.text.Text
.
shape – (optional) String in {ellipse (default), rectangle} If rectangle, aspect and scale holds for rectangle
Add a Plate
object to the model.
plate – The rectangle describing the plate bounds in model coordinates.
Can also be the Plate
to retain backward compatibility.
label – (optional) A string to annotate the plate.
label_offset – (optional) The x and y offsets of the label text measured in points.
shift – (optional)
The vertical “shift” of the plate measured in model units. This
will move the bottom of the panel by shift
units.
position – (optional)
One of "{vertical} {horizontal}"
where vertical is "bottom"
or "middle"
or "top"
and horizontal is "left"
or
"center"
or "right"
.
fontsize – (optional) The fontsize to use.
rect_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.Rectangle
constructor.
A subclass of plate to writing text using grid coordinates. Any
**kwargs
are passed through to PGM.Plate
.
x – The x-coordinate of the text in model units.
y – The y-coordinate of the text.
label – A string to write.
fontsize – (optional) The fontsize to use.
Axes as a property.
Figure as a property.
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.
dpi – (optional) The DPI value to use for rendering.
Wrapper on matplotlib.Figure.savefig()
that sets default image
padding using bbox_inchaes = tight
.
*args
and **kwargs
are passed to matplotlib.Figure.savefig().
fname – The filename to save as.
dpi – (optional) The DPI value to use for saving.
Wrapper on PGM.render()
that calls matplotlib.show()
immediately after.
dpi – (optional) The DPI value to use for rendering.
The representation of a random variable in a PGM
.
name – The plain-text identifier for the node.
content – The display form of the variable.
x – The x-coordinate of the node in model units.
y – The y-coordinate of the node.
scale – (optional)
The diameter (or height) of the node measured in multiples of
node_unit
as defined by the PGM
object.
aspect – (optional) The aspect ratio width/height for elliptical nodes; default 1.
observed – (optional) Should this be a conditioned variable?
fixed – (optional)
Should this be a fixed (not permitted to vary) variable?
If True, modifies or over-rides diameter
, offset
,
facecolor
, and a few other plot_params
settings.
This setting conflicts with observed
.
alternate – (optional) Should this use the alternate style?
offset – (optional)
The (dx, dy)
offset of the label (in points) from the default
centered position.
fontsize – (optional) The fontsize to use.
plot_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.Ellipse
constructor.
label_params – (optional)
A dictionary of parameters to pass to the
matplotlib.text.Annotation
constructor. Any kwargs not
used by Annontation get passed to matplotlib.text.Text
.
shape – (optional) String in {ellipse (default), rectangle} If rectangle, aspect and scale holds for rectangle.
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)
| |
|____________|
(x float, y float) A tuple of coordinate of target node
Render the node.
ctx – The _rendering_context
object.
An edge between two Node
objects.
node1 – The first Node
.
node2 – The second Node
. The arrow will point towards this node.
directed – (optional)
Should the edge be directed from node1
to node2
? In other
words: should it have an arrow?
label – (optional) A string to annotate the edge.
xoffset – (optional) The x-offset from the middle of the arrow to plot the label. Only takes effect if label is defined in plot_params.
yoffset – (optional) The y-offset from the middle of the arrow to plot the label. Only takes effect if label is defined in plot_params.
plot_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.FancyArrow
constructor to adjust
edge behavior.
label_params – (optional)
A dictionary of parameters to pass to the
matplotlib.axes.Axes.annotate
constructor to adjust
label behavior.
Render the edge in the given axes.
ctx – The _rendering_context
object.
A plate to encapsulate repeated independent processes in the model.
rect – The rectangle describing the plate bounds in model coordinates. This is [x-start, y-start, x-length, y-length].
label – (optional) A string to annotate the plate.
label_offset – (optional) The x- and y- offsets of the label text measured in points.
shift – (optional)
The vertical “shift” of the plate measured in model units. This will
move the bottom of the panel by shift
units.
position – (optional)
One of "{vertical} {horizontal}"
where vertical is "bottom"
or "middle"
or "top"
and horizontal is "left"
or
"center"
or "right"
.
fontsize – (optional) The fontsize to use.
rect_params – (optional)
A dictionary of parameters to pass to the
matplotlib.patches.Rectangle
constructor, which defines
the properties of the plate.
bbox – (optional)
A dictionary of parameters to pass to the
matplotlib.axes.Axes.annotate
constructor, which defines
the box drawn around the text.
Render the plate in the given axes.
ctx – The _rendering_context
object.
shape – The number of rows and columns in the grid.
origin – The coordinates of the bottom left corner of the plot.
grid_unit – The size of the grid spacing measured in centimeters.
node_unit – The base unit for the node size. This is a number in centimeters that sets the default diameter of the nodes.
observed_style – How should the “observed” nodes be indicated? This must be one of:
"shaded"
, "inner"
or "outer"
where inner
and
outer
nodes are shown as double circles with the second circle
plotted inside or outside of the standard one, respectively.
alternate_style – (optional)
How should the “alternate” nodes be indicated? This must be one of:
"shaded"
, "inner"
or "outer"
where inner
and
outer
nodes are shown as double circles with the second circle
plotted inside or outside of the standard one, respectively.
node_ec – The default edge color for the nodes.
node_fc – The default face color for the nodes.
plate_fc – The default face color for plates.
directed – Should the edges be directed by default?
aspect – The default aspect ratio for the nodes.
label_params – Default node label parameters.
dpi – (optional) The DPI value to use for rendering.
Return the current axes else create a new one.
Close the figure if it is set up.
Convert from model coordinates to plot coordinates.
Return the current figure else create a new one.
Reset the figure.
Reset the origin.
Reset the shape and figure size.