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

Class Domain

source code


A domain is a set of random variables, implicitly representing all functions from joint instantiations of the variables

Instance Methods [hide private]
 
__init__(self, domain=None, new_domain_variables=None, must_be_new=False)
Construct a domain
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
add_domain_variable(self, variable, values, must_be_new=False)
Add a variable and its associated values
source code
 
add_domain_variables(self, new_domain_variables, must_be_new=False)
Add variables from new_domain_variables
source code
 
add_domain_variables_from_rawdata(self, rawdata, must_be_new=False)
Add variables from rawdata
source code
 
change_domain_variable(self, variable, values)
Change the values associated with a domain variable
source code
 
change_domain_variables(self, new_values)
Change the values associated with a domain variables
source code
 
common_domain(self, other)
Make the domain for other identical to that of self
source code
Domain
copy(self)
Return a (deep) copy of a domain
source code
 
known_variable(self, variable)
Whether self knows variable (and thus its vales)
source code
Int
numvals(self, variable)
Return the number of values associated with a variable
source code
Frozenset
values(self, variable)
Return the values associated with a variable
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

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

Instance Variables [hide private]
Dictionary _domain
A dictionary mapping each variable to its set of possible values.
Set _instd
Set of instantiated variables
Dictionary _numvals
A dictionary mapping each variable to the number of values it can have.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

Construct a domain

Parameters:
  • domain (Domain or None) - An existing domain to use. If None the object will be independent of any existing domains. Otherwise self and domain will have identical attributes.
  • new_domain_variables (Dict or None) - A dictionary containing a mapping from any new variables to their values.
  • must_be_new (Boolean) - Whether domain variables in new_domain_variables have to be new
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.
Overrides: object.__init__

__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)

add_domain_variable(self, variable, values, must_be_new=False)

source code 

Add a variable and its associated values

If variable already exists then a check is done to ensure that values is correct.

Parameters:
  • variable (Immutable) - The new variable
  • values (Iterable) - The values of the new variable
  • must_be_new (Boolean) - If the variable should be a new variable
Raises:
  • VariableError - If variable already exists with values different from values; Or if must_be_new is set and the variable already exists.

add_domain_variables(self, new_domain_variables, must_be_new=False)

source code 

Add variables from new_domain_variables

Parameters:
  • new_domain_variables (Dictionary) - A dictionary mapping variables to values
  • must_be_new (Boolean) - Whether domain variables in new_domain_variables have to be new
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.

add_domain_variables_from_rawdata(self, rawdata, must_be_new=False)

source code 

Add variables from rawdata

Parameters:
  • rawdata (Tuple) - A tuple like that returned by IO.read_csv.
  • must_be_new (Boolean) - Whether domain variables from rawdata have to be new
Raises:
  • VariableError - If a variable in rawdata already exists with values different from its values in rawdata; Or if must_be_new is set and the variable already exists.

change_domain_variable(self, variable, values)

source code 

Change the values associated with a domain variable

Parameters:
  • variable (Immutable) - The variable
  • values (Iterable) - The new values of the variable
Raises:
  • KeyError - If variable is not in the domain

change_domain_variables(self, new_values)

source code 

Change the values associated with a domain variables

Parameters:
  • new_values (Iterable) - The new values of the variable
Raises:
  • KeyError - If new_values contains a variable not in the domain

common_domain(self, other)

source code 

Make the domain for other identical to that of self

The domain for self is updated to include any extra variables in other

Parameters:
  • other (Domain or subclass) - Domain
Raises:
  • VariableError - If self and other use a variable with different values in each one's domain.

copy(self)

source code 

Return a (deep) copy of a domain

Returns: Domain
The copy

known_variable(self, variable)

source code 

Whether self knows variable (and thus its vales)

If, as is common, self uses the internal default domain to keep track of variables, this amounts to checking whether the variable is in the internal default domain.

Parameters:
  • variable (Immutable (usually string)) - A variable

numvals(self, variable)

source code 

Return the number of values associated with a variable

Parameters:
  • variable (String) - Variable whose number of values is sought.
Returns: Int
The number of values associated with a variable
Raises:
  • KeyError - If variable is not in the domain

values(self, variable)

source code 

Return the values associated with a variable

Parameters:
  • variable (String) - Variable whose number of values is sought.
Returns: Frozenset
The values associated with a variable
Raises:
  • KeyError - If variable is not in the domain

variables(self)

source code 

Return the object's variables

Returns: Frozenset
The object's variables

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

Instance Variable Details [hide private]

_domain

A dictionary mapping each variable to its set of possible values. Each key is a variable name. Each value is a frozenset.
Type:
Dictionary

_numvals

A dictionary mapping each variable to the number of values it can have. Each key is a variable name. Each value is a positive integer
Type:
Dictionary