Package gPy :: Module Models :: Class JFR
[hide private]
[frames] | no frames]

Class JFR

source code


Join forest representations of probability distributions

A reduced, decomposable model where the factors are clique potentials and separators, related by a join forest.

Instance Methods [hide private]
 
__init__(self, hm=(), domain=None, new_domain_variables=None, must_be_new=False, check=False, modify=False, elimination_order=None)
Construct a join forest model from an existing hierarchical model (or factors)
source code
String
__str__(self)
Print each factor separately
source code
 
calibrate(self)
Alter a JFR so that the factors associated with both cliques and separators are the appropriate marginal distributions.
source code
Same as self
condition(self, condition)
Alter a JFR by effecting the restriction on variables given by condition
source code
JFR
copy(self, copy_domain=False)
Return a deep copy of a JFR
source code
 
gui_calibrate(self, parent) source code
 
marginal(self, variables, root=None, perfect_sequence=None)
Compute the marginal distribution of variables assuming they are a subset of some hyperedge (ie clique)
source code
 
send_message(self, frm, to)
Send a message from a clique to a neighbouring clique
source code
 
send_messages(self, cliques, banned=None)
Send messages using a fixed ordering of cliques
source code
List
separator_items(self)
Return (separator,separator_factor) pairs for all separators
source code
Iterator
separator_factors(self)
Return an iterator over the factors associated with separators in the model
source code
 
trace(self) source code
 
var_marginal(self, variable)
Compute the marginal distribution for variable, assuming that self is calibrated
source code
 
_clique_disp(self, clique_win, factor_dict) source code

Inherited from RFR: ipf

Inherited from RFR (private): _add_factor

Inherited from SFR: __iter__, factor, factors, factors_containing_variable, is_simple, items, simplify, some_factor

Inherited from SFR (private): _add_factor_to_dict, _put_factor_to_dict

Inherited from _AbsM: __div__, __getitem__, __idiv__, __imul__, __len__, __mul__, __repr__, __setitem__, add_ident, cpt, eliminate_variable, gui_display, hypergraph, inc_from_rawdata, interaction_graph, makeDN, make_decomposable, marginal_factor, marginalise_away, markov_blanket, markov_blanket_cpt, num_factors_containing_variable, red, reduced, remove, sumout, variable_elimination, variable_elimination_trace, z, zero

Inherited from _AbsM (private): _check_condition

Inherited from Variables.SubDomain: __add__, __iadd__, __isub__, __rdiv__, __rmul__, __sub__, drop_variable, drop_variables, inst2index, insts, insts_indices, marginalise_onto, table_size, uses_default_domain, variables, varvalues

Inherited from Variables.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]
Dictionary _factors
A mapping from each distinct hyperedge in the associated hypergraph to a list of factors having the variables of the hyperedge.
Hypergraph object _hypergraph
The hypergraph associated with the model.
Dictionary _separators
Maps each separator (edge of the join_forest) to its associated factor

Inherited from Variables.SubDomain (private): _variables

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, hm=(), domain=None, new_domain_variables=None, must_be_new=False, check=False, modify=False, elimination_order=None)
(Constructor)

source code 

Construct a join forest model from an existing hierarchical model (or factors)

If hm is a hypergraph it will end up with identical attributes to self, so typically a copy of an existing hypergraph is used.

Parameters:
  • hm (FR or sequence) - Hierachical model or sequence of factors
  • domain (Variables.Domain or None) - Only used if hm is not an FR object. A domain for the model. If None the internal default domain is used.
  • new_domain_variables (Dict or None) - Only used if hm is not an FR object. A dictionary containing a mapping from any new variables to their values. domain is updated with these values
  • must_be_new (Boolean) - Only used if hm is not an FR object. Whether domain variables in new_domain_variables have to be new
  • check (Boolean) - Only used if hm is not an FR object. Whether to check that all variables exist in domain
  • modify (Boolean) - Whether to modify hm to make it decomposable.
  • elimination_order (Sequence) - If supplied and modify=True, the elimination order to use to make the hm decomposable. (If not supplied maximum cardinality search is used to generate an order.)
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
  • DecomposabilityError - If modify=False and hm is not decomposable.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Print each factor separately

Use lexicographical ordering on factor variables

Returns: String
Pretty representation of a FR
Overrides: object.__str__
(inherited documentation)

calibrate(self)

source code 

Alter a JFR so that the factors associated with both cliques and separators are the appropriate marginal distributions.

In each tree in the forest, messages are first passed to a root and then out again.

condition(self, condition)

source code 

Alter a JFR by effecting the restriction on variables given by condition

This alters the model's domain. Make a copy with copy_domain=True if the original domain will be needed

Parameters:
  • condition (Dict) - Dictionary of the form {var1:value1,var2:value2..}
Returns: Same as self
The conditioned model
Raises:
  • KeyError - If a variable is used that is not in the model
  • ValueError - If a value is used that is not a possible value of the variable it is attached to
Overrides: _AbsM.condition

copy(self, copy_domain=False)

source code 

Return a deep copy of a JFR

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

marginal(self, variables, root=None, perfect_sequence=None)

source code 

Compute the marginal distribution of variables assuming they are a subset of some hyperedge (ie clique)

Just chooses an appropriate hyperedge as a root and sends messages to it. Typically used just after self has been altered so that, at least, this root clique has the correct marginal.

Used in iterative proportional fitting.

Parameters:
  • variables (Iterable) - The variables for which a marginal is sought.
  • root (Frozenset) - If supplied, a clique which is simply assumed to contain the variables. If not supplied one is computed.
  • perfect_sequence (Sequence) - If supplied an ordering assumed to be a perfect sequence with root as its first element.
Raises:
  • ValueError - If no clique contains variables
Overrides: _AbsM.marginal

send_message(self, frm, to)

source code 

Send a message from a clique to a neighbouring clique

Parameters:
  • frm (Frozenset (hyperedge)) - The clique sending the message
  • to (Frozenset (hyperedge)) - The clique receiving the message
Raises:
  • KeyError - If frm and to are not neighbours in the join forest

send_messages(self, cliques, banned=None)

source code 

Send messages using a fixed ordering of cliques

cliques acts as a stack. The first clique which is allowed to send a message is the last element of the list cliques. Thus the root is the first element. (This is just a little quicker than starting with the first.) A clique can only send a message to a clique 'underneath' it in the stack.

No message to a clique in banned is allowed to be sent.

Parameters:
  • cliques (List) - Stack of cliques
  • banned (set) - Cliques which are banned from receiving messages

separator_items(self)

source code 

Return (separator,separator_factor) pairs for all separators

The order is arbitrary.

Returns: List
(separator,separator_factor) pairs for all separators

separator_factors(self)

source code 

Return an iterator over the factors associated with separators in the model

The order is arbitrary.

Returns: Iterator
An iterator over the factors associated with separators in the model