zhusuan.framework.stochastic_tensor¶
- class StochasticTensor(bn, name, dist, observation=None, **kwargs)[source]¶
Bases:
objectThe
StochasticTensorclass represents the stochastic nodes in aBayesianNet. We can use any distribution available inzhusuan.distributionsto construct a stochastic node in aBayesianNet. For example:class Net(BayesianNet): def __init__(self): self.stochastic_node('Normal', name='x', mean=0., std=1.)
will build a stochastic node in
Netwith theNormaldistribution. The returnedxwill be a instance ofStochasticTensor.StochasticTensorinstances are Vars, which means that they can be passed into any Jittor operations. This makes it easy to build Bayesian networks by mixing stochastic nodes and Jittor primitives.See also
For more information, please refer to Basic Concepts in ZhuSuan.
- Parameters
bn – A
BayesianNet.name – A string. The name of the
StochasticTensor. Must be unique in aBayesianNet.dist – A
Distributioninstance that determines the distribution used in this stochastic node.observation – A Var, which matches the shape of dist. If specified, then the
StochasticTensoris observed and thetensorproperty will return the observation.n_samples – A 0-D integer. Number of samples generated by this
StochasticTensor.
- property bn¶
The
BayesianNetwhere theStochasticTensorlives.- Returns
A
BayesianNetinstance.
- property dist¶
The distribution followed by the
StochasticTensor.- Returns
A
Distributioninstance.
- property dtype¶
The sample type of the
StochasticTensor.- Returns
A
DTypeinstance.
- is_observed()[source]¶
Whether the
StochasticTensoris observed or not.- Returns
A bool.
- property name¶
The name of the
StochasticTensor.- Returns
A string.
- property shape¶
Return the static shape of this
StochasticTensor.- Returns
A
jittor_core.NanoVectorinstance.
- property tensor¶
The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.- Returns
A Var.