Beliefstate

class BeliefState(referential_domain=None)[source]

Bases: beliefs.cells.dicts.DictCell

Represents a beliefstate, a partial information object about specific targets. A beliefstate is a continuum between individual entities and types of entities.

Suppose the referential domain has entities: 1,2,3. A beliefstate represents the possible groupings of these entities; a single grouping is called a target. A beliefstate can be about “all targets of size two”, for example, and computing the beliefstate’s extension would yield the targets {1,2}, {2,3}, and {1,3}.

In addition to containing a description of the intended targets, a belief state contains meta-data about combinatoric constraints (such as arity size).

set_pos(pos)[source]

Sets the beliefstates’s part of speech, pos, and then executes any deferred effects that are keyed by that pos tag.

Parameters:pos (str) – The part of speech of the beliefstate
Returns:int,float – The cost of the deferred effects associated with this part of speech
get_pos()[source]

Returns Part of Speech

Returns:str – The part of speech for this BeliefState. BeliefStates are initialized with a default pos of ‘S’
add_deferred_effect(effect, pos)[source]

Pushes a (pos, effect) tuple onto a stack to later be executed if the state reaches the ‘pos’.

Parameters:
  • effect (function) – A function that takes one argument and returns a number representing the cost associated with this pos
  • pos (str) – Part of Speech
Raises:

Exception, Contradiction

execute_deferred_effects(pos)[source]

Evaluates deferred effects that are triggered by the prefix of the pos on the current beliefstate. For instance, if the effect is triggered by the ‘NN’ pos, then the effect will be triggered by ‘NN’ or ‘NNS’.

Parameters:pos (str) – A part of speech
Returns:number – Represents the cost of the deferred effects associated with pos. Can be int or float.
set_environment_variable(key, val)[source]

Sets a variable if that variable has not already been set

Parameters:
  • key – The key for the environment variable
  • val – The value that will be assigned to key
Raises:

Contradiction – raised if key has already been set to a value other than val

get_environment_variable(key, default=None, pop=False)[source]

Returns the value associated with key.

Parameters:
  • key – The lookup key
  • default – This value is returned in the event that no value is associated with key
  • pop (bool) – Determines whether key is removed from the Environment Variables when it is found.
Returns:

The value associated with key

has_referential_domain()[source]

Returns True if the BeliefState has a context set defined – meaning a set of external referents.

Returns:bool – Whether a contextset is defined
iter_breadth_first(root=None)[source]

Traverses the belief state’s structure breadth-first

Parameters:root – Optional starting point for the search
Returns:Generator
find_path(test_function=None, on_targets=False)[source]

This general helper method iterates breadth-first over the elements in the referential domain and yields all paths to the elements where the test_function evaluates to True

Parameters:
  • test_function (function) – A function that takes two arguments and returns a boolean
  • on_targets (bool) –
Returns:

Generator – represents the path

get_nth_unique_value(keypath, n, distance_from, open_interval=True)[source]

Returns the `n-1`th unique value, or raises a contradiction if that is out of bounds

Parameters:
  • keypath (list) –
  • n (int) – An integer representing which unique value to return
  • reverse (bool) – Specifies the ordering of the values
Returns:

The ‘n-1’th unique value

Raises:

Contradiction

get_ordered_values(keypath, distance_from, open_interval=True)[source]

Retrieves the referents’s values sorted by their distance from the min, max, or mid value.

Parameters:
  • keypath
  • reverse (bool) – Specifies the ordering of the values
Returns:

OrderedDict – Dictionary of sorted values

get_paths_for_attribute_set(keys)[source]

Given a list/set of keys (or one key), returns the parts that have all of the keys in the list.

Because on_targets=True, this DOES NOT WORK WITH TOP LEVEL PROPERTIES, only those of targets.

These paths are not pointers to the objects themselves, but tuples of attribute names that allow us to (attempt) to look up that object in any belief state.

Parameters:keys (list,set) – A collection of keys
Returns:Generator
get_parts()[source]

Searches for all DictCells (with nested structure)

Returns:Generator
get_paths_for_attribute(attribute_name)[source]

Returns a path list to all attributes that have a particular name.

Parameters:attribute_name
Returns:Generator
merge(keypath, value, op='set')[source]

First gets the cell at BeliefState’s keypath, or creates a new cell from the first element in the referential domain that has that keypath. Second, this merges that cell with the value.

Warning

If two elements in the referential domain have the same named attributes (i.e. attribute paths) but different Cells for the value, then the belief state will arbitrarily acquire the first element in the referential domain and not entail the other because its cell will be incomparable.

Parameters:
  • keypath (list) –
  • value
  • op
Returns:

The result of calling the op method of the Cell at the end of keypath on value

Rasise:

CellConstructionFailure

add_cell(keypath, cell)[source]

Adds a new cell to the end of keypath of type cell

Parameters:
  • keypath (list) – A sequence of keys that specify a path through nested dictionaries
  • cell – The cell to be added to the end of keypath
Returns:

The cell object that was passed in as a parameter

entails(other)[source]

One beliefstate entails another beliefstate iff the other state’s entities are all equal or more general than the caller’s parts. That means the other state must at least have all of the same keys/components.

Note

this only compares the items in the DictCell, not pos,`environment_variables` or deferred_effects.

Parameters:other (BeliefState) – The BeliefState to compare with
Returns:bool
Raises:Exception
is_entailed_by(other)[source]

Given two beliefstates, returns True iff the calling instance implies the other beliefstate, meaning it contains at least the same structure (for all structures) and all values (for all defined values).

Inverse of entails.

Note

this only compares the items in the DictCell, not pos, environment_variables or deferred_effects.

Parameters:other (BeliefState) – BeliefState to compare with
Returns:bool
Raises:Exception
is_equal(other)[source]

Two beliefstates are equal if all of their part names are equal and all of their cell’s values return True for is_equal().

Note

this only compares the items in the DictCell, not pos, environment_variables or deferred_effects.

Parameters:other (BeliefState) – BeliefState to compare with
Returns:bool
is_contradictory(other)[source]
Two beliefstates are incompatible if the other beliefstates’s entities
are not consistent with or accessible from the caller.

Note

this only compares the items in the DictCell, not pos, environment_variables or deferred_effects.

Parameters:other (BeliefState) – BeliefState to compare with
Returns:bool
size()[source]

Returns the size of the belief state. This is the number of referents it implicitly represents.

Initially if there are \(n\) consistent members, (the result of number_of_singleton_referents()) then there are generally \(2^{n}-1\) valid referents.

Returns:int – Size of the contextset
Raises:Exception
referents()[source]

Returns all target sets that are compatible with the current beliefstate.

Warning

the number of referents can be quadratic in the number of elements in the referential domain. Call size() method instead to compute size only, without enumerating them.

Returns:list – Members of contextset that are compatible with beliefstate
iter_referents()[source]

Generates target sets that are compatible with the current beliefstate.

Returns:Generator
iter_referents_tuples()[source]

Generates target sets (as tuples of indicies) that are compatible with the current beliefstate.

Returns:Generator
number_of_singleton_referents()[source]

Returns the number of singleton elements of the referential domain that are compatible with the current belief state.

This is the size of the union of all referent sets.

Returns:int – The number of singleton members of the contextset
Raises:Exception – Raised when no contextset is defined for the BeliefState
iter_singleton_referents()[source]

Iterator of all of the singleton members of the context set.

Returns:Generator
Raises:Exception
to_latex(number=0)[source]

Returns a raw text string that contains a latex representation of the belief state as an attribute-value matrix. This requires:

usepackage{avm}
copy()[source]

Copies the BeliefState by recursively deep-copying all of its parts. Domains are not copied, as they do not change during the interpretation or generation.

Returns:BeliefState

Previous topic

A Library for Representing Belief States

Next topic

Bools

This Page