CPDtypes

There are currently three real types of CPD nodes in this directory, but there could be infinitely many more. The crazy type listed last is meant to show that classes can exist for any computational way to sample a node based on its parent values. The flexibility provided allows for random sampling to exist in hybrid networks.

discrete

This module contains tools for representing discrete nodes – those with a finite number of outcomes and a finite number of possible parent values – as class instances with their own choose method to choose an outcome for themselves based on parent outcomes.

class libpgm.CPDtypes.discrete.Discrete(Vdataentry)[source]

This class represents a discrete node, as described above. It contains the Vdataentry attribute and the choose method.

This class is constructed with the argument Vdataentry which must be a dict containing a dictionary entry for this particular node. The dict must contain an entry of the following form:

"cprob": {
    "['<parent 1, value 1>',...,'<parent n, value 1>']": [<probability of vals[0]>, ... , <probability of vals[n-1]>],
    ...
    "['<parent 1, value j>',...,'<parent n, value k>']": [<probability of vals[0]>, ... , <probability of vals[n-1]>],
}

Where the keys are each possible combination of parent values and the values are the probability of each of the n possible node outcomes, given those parent outcomes. The Vdataentry attribute is set equal to this Vdataentry input upon instantiation.

Vdataentry = None

A dict containing CPD data for the node.

choose(pvalues)[source]

Randomly choose state of node from a probability distribution conditioned on parent values pvalues.

This method has two parts: (1) determining the proper probability distribution, and (2) using that probability distribution to determine an outcome.

Arguments:
  1. pvalues – An array containing the assigned states of the node’s parents. This must be in the same order as the parents appear in self.Vdataentry["parents"].

The function goes to the proper entry in Vdataentry, as specified by pvalues, and samples the node based on the distribution found there.

linear gaussian

This module contains tools for representing linear Gaussian nodes – those with a continuous linear Gaussian distribution of outcomes and a finite number of linear Gaussian parents – as class instances with their own choose method to choose an outcome for themselves based on parent outcomes.

class libpgm.CPDtypes.lg.Lg(Vdataentry)[source]

This class represents a linear Gaussian node, as described above. It contains the Vdataentry attribute and the choose method.

This class is constructed with the argument Vdataentry which must be a dict containing a dictionary entry for this particular node. The dict must contain entries of the following form:

"mean_base": <float used for mean starting point
              (\mu_0)>,
"mean_scal": <array of scalars by which to
              multiply respectively ordered 
              continuous parent outcomes>,
"variance": <float for variance>

See lgbayesiannetwork for an explanation of linear Gaussian sampling.

The Vdataentry attribute is set equal to this Vdataentry input upon instantiation.

Vdataentry = None

A dict containing CPD data for the node.

choose(pvalues)[source]

Randomly choose state of node from probability distribution conditioned on pvalues.

This method has two parts: (1) determining the proper probability distribution, and (2) using that probability distribution to determine an outcome.

Arguments:
  1. pvalues – An array containing the assigned states of the node’s parents. This must be in the same order as the parents appear in self.Vdataentry['parents'].

The function creates a Gaussian distribution in the manner described in lgbayesiannetwork, and samples from that distribution, returning its outcome.

linear gaussian + discrete

This module contains tools for representing “LG + D” (linear Gaussian and discrete) nodes – those with a Gaussian distribution, one or more Gaussian parents, and one or more discrete parents – as class instances with their own choose method to choose an outcome for themselves based on parent outcomes.

class libpgm.CPDtypes.lgandd.Lgandd(Vdataentry)[source]

This class represents a LG + D node, as described above. It contains the Vdataentry attribute and the choose method

This class is constructed with the argument Vdataentry which must be a dict containing a dictionary entry for this particualr node. The dict must contain an entry of the following form:

"cprob": {
    "['<parent 1, value 1>',...,'<parent n, value 1>']": {
                    "mean_base": <float used for mean starting point
                                  (\mu_0)>,
                    "mean_scal": <array of scalars by which to
                                  multiply respectively ordered 
                                  continuous parent outcomes>,
                    "variance": <float for variance>
                }
    ...
    "['<parent 1, value j>',...,'<parent n, value k>']": {
                    "mean_base": <float used for mean starting point
                                  (\mu_0)>,
                    "mean_scal": <array of scalars by which to
                                  multiply respectively ordered 
                                  continuous parent outcomes>,
                    "variance": <float for variance>
                }
}

This "cprob" entry contains a linear Gaussian distribution (conditioned on the Gaussian parents) for each combination of discrete parents. The Vdataentry attribute is set equal to this Vdataentry input upon instantiation.

Vdataentry = None

A dict containing CPD data for the node.

choose(pvalues)[source]

Randomly choose state of node from probability distribution conditioned on pvalues.

This method has two parts: (1) determining the proper probability distribution, and (2) using that probability distribution to determine an outcome.

Arguments:
  1. pvalues – An array containing the assigned states of the node’s parents. This must be in the same order as the parents appear in self.Vdataentry['parents'].

The function goes to the entry of "cprob" that matches the outcomes of its discrete parents. Then, it constructs a Gaussian distribution based on its Gaussian parents and the parameters found at that entry. Last, it samples from that distribution and returns its outcome.

crazy (test type)

This module contains tools for representing “crazy” nodes – nodes where the method for sampling is to multiply the crazyinput by -10 or 10 and add \(\pi\) – as class instances with their own choose method to choose an outcome for themselves based on parent outcomes.

The existence of this ‘crazy’ type is meant to indicate the true universality of the universal sampling method found in hybayesiannetwork. While no CPD would actually be this crazy, the libary has the setup to support any type of CPD.

class libpgm.CPDtypes.crazy.Crazy(Vdataentry)[source]

This class represents a crazy node, as described above. It contains the Vdataentry attribute and the choose method.

This class is constructed with the argument Vdataentry which must be a dict containing a dictionary entry for this particualr node. The dict must contain an entry of the following form:

"crazyinput": <number that is the crazy input>

This "crazyinput" entry contains the number that will be used in the crazy sampling function. The Vdataentry attribute is set equal to this Vdataentry input upon instantiation.

Vdataentry = None

A dict containing CPD data for the node.

choose(pvalues)[source]

Randomly choose state of node from probability distribution conditioned on pvalues.

This method has two parts: (1) determining the proper probability distribution, and (2) using that probability distribution to determine an outcome.

Arguments:
  1. pvalues – An array containing the assigned states of the node’s parents. This must be in the same order as the parents appear in self.Vdataentry[‘parents’].

The function takes the crazyinput, multiplies it by either 10 or -10 randomly, adds \(\pi\), converts it to a string, and appends the word “bluberries!”. It returns this value.

Table Of Contents

Previous topic

pgmlearner

Next topic

discrete bayesian network

This Page