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).
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 |
Returns Part of Speech
| Returns: | str – The part of speech for this BeliefState. BeliefStates are initialized with a default pos of ‘S’ |
|---|
Pushes a (pos, effect) tuple onto a stack to later be executed if the state reaches the ‘pos’.
| Parameters: |
|
|---|---|
| Raises: | Exception, Contradiction |
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. |
Sets a variable if that variable has not already been set
| Parameters: |
|
|---|---|
| Raises: | Contradiction – raised if key has already been set to a value other than val |
Returns the value associated with key.
| Parameters: |
|
|---|---|
| Returns: | The value associated with key |
Returns True if the BeliefState has a context set defined – meaning a set of external referents.
| Returns: | bool – Whether a contextset is defined |
|---|
Traverses the belief state’s structure breadth-first
| Parameters: | root – Optional starting point for the search |
|---|---|
| Returns: | Generator |
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: |
|
|---|---|
| Returns: | Generator – represents the path |
Returns the `n-1`th unique value, or raises a contradiction if that is out of bounds
| Parameters: |
|
|---|---|
| Returns: | The ‘n-1’th unique value |
| Raises: | Contradiction |
Retrieves the referents’s values sorted by their distance from the min, max, or mid value.
| Parameters: |
|
|---|---|
| Returns: | OrderedDict – Dictionary of sorted values |
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 |
Returns a path list to all attributes that have a particular name.
| Parameters: | attribute_name – |
|---|---|
| Returns: | Generator |
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: |
|
|---|---|
| Returns: | The result of calling the op method of the Cell at the end of keypath on value |
| Rasise: | CellConstructionFailure |
Adds a new cell to the end of keypath of type cell
| Parameters: |
|
|---|---|
| Returns: | The cell object that was passed in as a parameter |
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 |
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 |
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 |
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 |
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 |
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 |
|---|
Generates target sets that are compatible with the current beliefstate.
| Returns: | Generator |
|---|
Generates target sets (as tuples of indicies) that are compatible with the current beliefstate.
| Returns: | Generator |
|---|
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 |
Iterator of all of the singleton members of the context set.
| Returns: | Generator |
|---|---|
| Raises: | Exception |