bayespy.nodes.Add

class bayespy.nodes.Add(*nodes, **kwargs)[source]

Node for computing sums of Gaussian nodes: X+Y+Z.

See also

Dot, SumMultiply

Notes

Shapes of the nodes must be identical. Plates are broadcasted.

This node sums nodes that are independent in the posterior approximation. However, summing variables puts a strong coupling among the variables, which is lost in this construction. Thus, it is usually better to use a single Gaussian node to represent the set of the summed variables and use SumMultiply node to compute the sum. In that way, the correlation between the variables is not lost. However, in some cases it is necessary or useful to use Add node.

Examples

>>> import numpy as np
>>> from bayespy import nodes
>>> X = nodes.Gaussian(np.zeros(2), np.identity(2), plates=(3,))
>>> Y = nodes.Gaussian(np.ones(2), np.identity(2))
>>> Z = nodes.Add(X, Y)
>>> print("Mean:\n", Z.get_moments()[0])
Mean:
 [[1. 1.]]
>>> print("Second moment:\n", Z.get_moments()[1])
Second moment:
 [[[3. 1.]
  [1. 3.]]]
__init__(X1, X2, ...)[source]

Methods

__init__(X1, X2, …)

add_plate_axis(to_plate)

broadcasting_multiplier(plates, *args)

delete()

Delete this node and the children

get_mask()

get_moments()

get_pdf_nodes()

get_shape(ind)

has_plotter()

Return True if the node has a plotter

lower_bound_contribution([gradient])

move_plates(from_plate, to_plate)

plot([fig])

Plot the node distribution using the plotter of the node

random()

set_plotter(plotter)

Attributes

plates

plates_multiplier

Plate multiplier is applied to messages to parents