Package gPy :: Module Samplers :: Class DNSampler
[hide private]
[frames] | no frames]

Class DNSampler

source code


For sampling from dependency networks

Instance Methods [hide private]
 
__init__(self, dnm, variables=None)
Construct a sampler from a dependency network
source code
 
condition(self, condition)
Make a sampler conditional on some evidence
source code
 
gibbs_sample(self, initial=None, burnin=100, iterations=1000)
Run Gibbs sampling
source code
 
uncondition(self)
Remove all evidence
source code
Integer
variable_index(self, variable)
Return the index for a variable in joint instantiations
source code
Tuple
variables(self)
Return the ordering of variables in joint instantiations
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Instance Variables [hide private]
List _condition_index
Instantiated variables have their values, others have None
Tuple _dists
For each variable, a dictionary mapping parent instantiations to a MultinomialSampler object
Tuple _indextuple
The tuple (0,1, ...n) where n is the number of variables
Tuple _indices
For each variable, a tuple of the indices corresponding to its parents
List _instskel
A list of Nones of the right length to hold a full joint instantiation.
Dictionary _var2index
Maps a variable to its index in _variables
Tuple _variables
An ordering of the DN's variables used for example, for Gibbs sampling
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, dnm, variables=None)
(Constructor)

source code 

Construct a sampler from a dependency network

Parameters:
  • dnm (Models.DN) - Dependency network
  • variables (Tuple) - An order in which to sample values for the variable in eg Gibbs sampling. If not supplied an arbitrary ordering is used.
Overrides: object.__init__

condition(self, condition)

source code 

Make a sampler conditional on some evidence

Any previous conditioning will be erased.

Parameters:
  • condition (Dictionary) - Mapping from variables to their values

variable_index(self, variable)

source code 

Return the index for a variable in joint instantiations

Returns: Integer
The index for a variable in joint instantiations

variables(self)

source code 

Return the ordering of variables in joint instantiations

This will be a topological ordering for a BNSampler.

Returns: Tuple
The ordering of variables in joint instantiations