Package gPy :: Module Variables :: Class SubDomain
[hide private]
[frames] | no frames]

Class SubDomain

source code


A subdomain is a domain together with a specified subset of the domain variables.

A subdomain implicitly represents all functions from joint instantiations of the domain variables whose values depend only on the specified subset of the domain variables. As such they can represent data-less Parameters.Factor object.

Instance Methods [hide private]
 
__init__(self, variables=(), domain=None, new_domain_variables=None, must_be_new=False, check=False)
Construct a SubDomain object
source code
Same as self
__add__(self, other)
Factor addition
source code
Same as self
__div__(self, other)
Division, typically of factors
source code
Same as self
__iadd__(self, other)
Does in-place addition
source code
Same as self
__idiv__(self, other)
Does in-place division
source code
Same as self
__imul__(self, other)
Does in-place multiplication
source code
Same as self
__isub__(self, other)
Does in-place subtraction
source code
Same as self
__mul__(self, other)
Factor multiplication
source code
Same as self
__rdiv__(self, other)
Only called when evaluating other / self, where other is not a Factor, but self is
source code
Same as self
__sub__(self, other)
Factor subtraction
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
Same as self
__rmul__(self, other)
Only called when evaluating other*self, where other is not a Factor, but self is
source code
SubDomain
copy(self, copy_domain=False)
Return a 'copy' of a subdomain
source code
Iterator
insts(self, variables=None)
Return an iterator over joint instantiations of variables
source code
Iterator
insts_indices(self, variables=None)
Return an iterator over the indices of joint instantiations of variables
source code
Int
inst2index(self, inst)
Return the index associated with the instantiation inst.
source code
Class of self
drop_variable(self, variable)
Alter self by dropping variable
source code
Class of self
drop_variables(self, variables)
Alter self by dropping variables
source code
 
marginalise_onto(self, variables)
Alter self by marginalising onto the intersection of variables and self's variables
source code
Integer
table_size(self, variables=None)
Return the number of joint instantiations of variables in self
source code
Parameters.Factor object
sumout(self, vars_togo)
Summing out (marginalising) the variables vars_togo from the factor
source code
Boolean
uses_default_domain(self)
Whether self uses the internal default domain
source code
Frozenset
variables(self)
Return the object's variables
source code
Dictionary
varvalues(self)
Return the dictionary mapping the object's variables to their set of possible values
source code
 
_decode_inst(self, inst) source code
 
_insts(self, variables) source code
 
_insts_indices(self, variables) source code
 
_pointwise_op(self, other, op, swapped=False) source code
 
_get_result_variables(self, other) source code

Inherited from Domain: add_domain_variable, add_domain_variables, add_domain_variables_from_rawdata, change_domain_variable, change_domain_variables, common_domain, known_variable, numvals, values

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

Instance Variables [hide private]
frozenset _variables
The specified subset of domain variables.

Inherited from Domain (private): _domain, _instd, _numvals

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, variables=(), domain=None, new_domain_variables=None, must_be_new=False, check=False)
(Constructor)

source code 

Construct a SubDomain object

Parameters:
  • variables (Iterable) - The subset of domain variables for the object.
  • domain (Domain or None) - A domain for the model. If None the internal default domain is used. If the string 'new', a new empty domain is used.
  • new_domain_variables (Dict or None) - A dictionary containing a mapping from any new variables to their values. domain is updated with these values
  • must_be_new (Boolean) - Whether domain variables in new_domain_variables have to be new
  • check (Boolean) - Whether to check that all variables exist in domain
Raises:
  • VariableError - If a variable in new_domain_variables already exists with values different from its values in new_domain_variables; Or if must_be_new is set and the variable already exists. Or if check is set and a variable in variables is not in the domain
Overrides: object.__init__

__add__(self, other)
(Addition operator)

source code 

Factor addition

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the addition
Returns: Same as self
Result of factor addition
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__div__(self, other)

source code 

Division, typically of factors

0/0 is defined to equal 1 ('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor object or float object) - Factor or scalar on the RHS of the division
Returns: Same as self
Result of factor division
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__iadd__(self, other)

source code 

Does in-place addition

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the addition
Returns: Same as self
self after being added
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__idiv__(self, other)

source code 

Does in-place division

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the division
Returns: Same as self
self after being divided
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__imul__(self, other)

source code 

Does in-place multiplication

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the multiplication
Returns: Same as self
self after being multiplied
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__isub__(self, other)

source code 

Does in-place subtraction

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the subtraction
Returns: Same as self
self after being subtracted
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__mul__(self, other)

source code 

Factor multiplication

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the multiplication
Returns: Same as self
Result of factor multiplication
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__rdiv__(self, other)

source code 

Only called when evaluating other / self, where other is not a Factor, but self is

('Factors' can be SubDomain objects.)

Parameters:
  • other (Numeric) - Number
Returns: Same as self
other / self
Raises:
  • TypeError - If other is not a number

__sub__(self, other)
(Subtraction operator)

source code 

Factor subtraction

('Factors' can be SubDomain objects.)

Parameters:
  • other (Typically Parameters.Factor or float object) - Factor or scalar on the RHS of the subtraction
Returns: Same as self
Result of factor subtraction
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__rmul__(self, other)

source code 

Only called when evaluating other*self, where other is not a Factor, but self is

('Factors' can be SubDomain objects.)

Parameters:
  • other (Numeric) - Number
Returns: Same as self
other * self
Raises:
  • TypeError - If other is not a number

copy(self, copy_domain=False)

source code 

Return a 'copy' of a subdomain

Parameters:
  • copy_domain (Boolean) - If true self's domain is copied, otherwise the copy shares self's domain
Returns: SubDomain
The copy
Overrides: Domain.copy

insts(self, variables=None)

source code 

Return an iterator over joint instantiations of variables

Each instantiation is a tuple of values, the order of the values corresponding to the ordering of variables in variables. The instantiations themselves follow the standard ordering.

Parameters:
  • variables (Sequence or None) - Which variables to include. If None, all the table/factor's variables are included in order.
Returns: Iterator
An iterator over joint instantiations
Raises:
  • KeyError - If a variable in variables is not defined.

insts_indices(self, variables=None)

source code 

Return an iterator over the indices of joint instantiations of variables

Each instantiation is a tuple of integers, the order of the values corresponding to the ordering of variables in variables. The instantiations themselves follow the standard ordering.

Parameters:
  • variables (Sequence or None) - Which variables to include. If None, all the table/factor's variables are included in order.
Returns: Iterator
An iterator over joint instantiations
Raises:
  • KeyError - If a variable in variables is not defined.

inst2index(self, inst)

source code 

Return the index associated with the instantiation inst.

The first time this is called a lookup table (dictionary) is created to enable subsequent calls to be returned by lookup.

Parameters:
  • inst (Tuple) - A tuple of ordered values, one for each variable
Returns: Int
The index associated with the instantiation inst
Raises:
  • KeyError - If there is no joint instantiation inst.

drop_variable(self, variable)

source code 

Alter self by dropping variable

Parameters:
  • variable (Immutable) - Variable to drop
Returns: Class of self
The altered self

drop_variables(self, variables)

source code 

Alter self by dropping variables

variables is not altered. Variables in variables which are not in self's variables are ignored.

Parameters:
  • variables (Sequence) - Variables to drop
Returns: Class of self
The altered self

marginalise_onto(self, variables)

source code 

Alter self by marginalising onto the intersection of variables and self's variables

Parameters:
  • variables (Sequence) - Variables to keep

table_size(self, variables=None)

source code 

Return the number of joint instantiations of variables in self

Parameters:
  • variables (Iterable or None) - Variables for which we want number of joint instantiations. If None, all variables are considered.
Returns: Integer
The number of joint instantiations of variables in self

sumout(self, vars_togo)

source code 

Summing out (marginalising) the variables vars_togo from the factor

Does not alter self

Parameters:
  • vars_togo (Iterable, e.g. list, tuple, set) - Variables to sum out
Returns: Parameters.Factor object
New factor with vars_togo summed out

uses_default_domain(self)

source code 

Whether self uses the internal default domain

Returns: Boolean
Whether self uses the internal default domain

variables(self)

source code 

Return the object's variables

Returns: Frozenset
The object's variables
Overrides: Domain.variables
(inherited documentation)

varvalues(self)

source code 

Return the dictionary mapping the object's variables to their set of possible values

Returns: Dictionary
Map from variables to values
Overrides: Domain.varvalues
(inherited documentation)

_pointwise_op(self, other, op, swapped=False)

source code 
Raises:
  • VariableError - If self and other use a variable with different values in each one's values dictionary.

_get_result_variables(self, other)

source code 
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.