Algorithmadvanced
Possible models approach
Also called Winslett PMA.
Updates each model of the old beliefs to the models of the new formula that differ from it in a minimal set of atoms.
- Solves
- Belief update
- Time
- Θ(k·n·2^n) worstΘ(2^n) best
- Space
- Θ(2^n) extra
- Where
- k = the number of models of the base; n = the number of atoms
- Model
- Word RAM
- Properties
- deterministic
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Marianne Winslett, 1988
The possible models approach (PMA) of Marianne Winslett is the classic operator for belief update, the change of beliefs when the world itself has changed. It treats each model of the old beliefs as a possible state of the world and moves each one separately to the models of the new formula that change as little as possible. "As little as possible" is measured by the set of atoms that change, compared by set inclusion. The result is the union of what each old model becomes. Winslett (1988) defined it to reason about the effects of actions, and Katsuno and Mendelzon (1991) showed that it satisfies their update postulates U1 to U8. On model sets it takes time for old models over atoms. On formulas, deciding whether the result entails a given formula is -complete (Eiter and Gottlob 1992, Theorem 6.4).
In plain words
You do not know exactly how the world is, so you keep a list of the states it could be in. Then an action happens, and afterwards some fact is true. For each state on your list, ask: what is the smallest change to this state that makes the fact true? Keep every answer that changes no more than it must, where "no more" means that no other answer changes only a part of the same things. Do this for each state on its own, and your new list is all the answers together.
Two answers that change different things, such as "the lamp moved" and "the chair and the table moved", are both kept. The method does not count the changes. It only throws out an answer when another answer changes a part of what it changes.
The problem
Fix atoms. A world is a vector , which we also read as the set of its true atoms. For two worlds, is the set of the atoms on which they differ. The input is , the set of the models of the old beliefs and the set of the models of the new formula. The output is
In Winslett's words, is : the models of the postconditions such that no other such model differs from on fewer atoms, "where 'fewer' is defined by set inclusion" (Winslett 1988, p. 90). Winslett also keeps a set of protected formulas that must hold after every action. Here they are part of .
If is empty the result is empty, and if is empty the result is empty.
The algorithm
Worlds and change sets are integers, with bit for atom . For one world , an array of bits records which change sets lead into . Lines L6 and L7 close it upwards, one atom at a time, so that afterwards is true when some model of differs from only on atoms inside . This is the zeta transform of sum over subsets with "or" in place of "+".
PMA(K, P, n)- 1
R ← ∅ - 2
for each w in K do - 3
if w ∈ P then - 4
add w to R; continue ▷ the empty change set is the least - 5
C[x] ← ((w xor x) ∈ P) for each x in 0 .. 2^n - 1 - 6
for i ← 0 to n-1 do - 7
for each x that has bit i do C[x] ← C[x] or C[x xor 2^i] - 8
for each v in P do - 9
x ← w xor v; if C[x xor 2^i] is false for every bit i of x then - 10
add v to R ▷ no change set inside x leads to P - 11
return R
A proper subset of lies inside minus one of its atoms. So line L9 needs only lookups to find out whether a smaller change set exists.
Example
The atoms are , and , and a world is written as the bit string . The old beliefs are , so . The new formula is , so .
| model of | change sets to | minimal ones | |
|---|---|---|---|
| 000 | to 100, to 011 | both | |
| 011 | to 011 | (lines L3 and L4) |
For , line L5 marks and . After lines L6 and L7, is true for , , , and . For , line L9 looks at , which is false, so is kept. For , it looks at and , which are both false, so is kept too. The result is , which is itself: the update has lost the fact .
Two other operators on the same input show what the choices do:
- Forbus's update counts the changed atoms instead of comparing them by inclusion. From it keeps only , one atom away, and drops , two atoms away.
- Dalal's revision compares the distance to the whole set . Since is in both and , the revision is , that is .
Update against revision. In the book and magazine example of Katsuno and Mendelzon (1991, KR), says that the book is on the table and that the magazine is. The agent knows that exactly one of them is there, , and then learns . The PMA moves the world to and keeps the world , so the update is , with nothing known about the magazine. Dalal's revision gives , because is consistent with . The update is right if a robot was told to put the book on the table, and the revision is right if the agent only learned more about a room that did not change.
Correctness
For , the empty change set is a subset of every other change set, so , which lines L3 and L4 return. For , after round of lines L6 and L7 the entry is true exactly when some change set to has and agrees with on the atoms above . After the last round this is "some ". A change set misses some atom of , so , and the test of line L9 finds it. The full proof is in the correctness proof.
Proof: The method returns, for each model of K, the models of p with an inclusion-minimal change setfull
We use the pseudocode of the page. The input is a number of atoms, the set of the models of the belief base and the set of the models of the new formula . A world is a vector in , and we identify it with the set of its true atoms, so that is the set of the atoms on which and differ. For a world , let
be the change sets that lead from into , and let . The possible models approach is
(Winslett 1988, Section 3, with the protected formulas left out).
Lemma 1 (a model of p). If , then .
Proof. is in , and for every nonempty . So every with has in and is not in . The set has no proper subset, so .
Lemma 2 (the upward closure). Fix . After line L5, is true exactly when . After the round of lines L6 and L7, for ,
(I) is true exactly when some has and agrees with on the atoms .
Proof. Before round 0 the claim holds with "agrees on all atoms" in place of (I), since is true exactly for . Suppose it holds after round , that is, is true exactly when some has and agrees with on the atoms . In round , line L7 changes only the entries with atom in , and it reads , where does not contain atom , so that entry is not changed in this round and the order of the updates does not matter. If atom is not in , then any misses atom too and so agrees with on atom , and the old value is already right. If atom is in , the sets that agree with on the atoms are the ones that contain atom , which the old covers, and the ones that miss it, which the old covers. So the new value is right.
After the last round, (I) with says: is true exactly when some has .
Lemma 3 (the test). Fix and , and let . After the loop of lines L6 and L7, some has if and only if is true for some atom in .
Proof. If and , take an atom in but not in . Then , so is true by Lemma 2. Conversely, if is true for an atom in , Lemma 2 gives with .
Theorem. PMA stops and returns .
Proof. Every loop runs over a finite set, so the method stops. We show that for each the worlds that lines L3 to L10 add to are exactly . If , lines L3 and L4 add alone, which is by Lemma 1. If , line L9 adds exactly when no with in is true, which by Lemma 3 means that no change set in is a proper subset of , that is . The array is set up again for each , so one model does not change the work for the next. starts empty at line L1 and only grows, so line L11 returns the union of the sets for .
The empty cases. If is empty, the loop of line L2 does not run and the result is empty: an inconsistent base stays inconsistent. If is empty, no is in , no entry of is set, and line L8 has nothing to run over, so the result is empty.
Cost. For one , line L5 takes time to clear and fill , lines L6 and L7 take , and lines L8 to L10 take . For the work is with stored as a bit array. With , the time is on the word RAM, and the extra space is the bits of and of .
Complexity
For each model of outside , line L5 costs , lines L6 and L7 cost , and lines L8 to L10 cost . With and , and stored as bit arrays on the word RAM, the time is in the worst case. The best case is , where only the arrays are set up, in time. The extra space is bits for , which is reused for each .
The direct method compares all pairs of models of for each , in subset tests. It is faster when is small. The transform wins when holds more than about worlds.
On formulas the model sets can have members, and the question is whether entails a formula . Eiter and Gottlob (1992) show that this is -complete (Theorem 6.4), the same as for Forbus's, Satoh's and Borgida's operators. A counterexample is a model of and a model of such that no model of has a smaller change set from , which is one NP guess followed by one coNP check. When , and are Horn, the problem drops to coNP-complete (Theorem 7.2). Both classes are in the polynomial hierarchy.
Properties
- It satisfies U1 to U8. For each world , define when . This is a partial order in which is below every other world, so the assignment is faithful in the sense of Katsuno and Mendelzon, and is the set of the -least models of . By their representation theorem the operator satisfies the update postulates U1 to U8 (Katsuno and Mendelzon 1991, KR). The tests check all eight on random inputs.
- It is not a revision. In the book and magazine example, is consistent but the update is not , so the revision postulate R2 fails. Dalal's revision fails U8 on the same input: updating the two models of one by one gives , but revising the whole of gives .
- It depends only on the models. Winslett notes that the PMA depends on the models of the theory and not on how its formulas are written, unlike the possible worlds approach of Ginsberg and Smith (Winslett 1988, p. 90).
- It depends on the choice of atoms. In the book and magazine example, use the atoms and . Then is , and is . The world is . Its change sets are to and to , so only is kept, and the update becomes , the same as the revision.
- An inconsistent base stays inconsistent. If has no model, the union is empty. This is what U2 asks, since an unsatisfiable entails every .
Variants and improvements
- Forbus's update. Measure the change from by the number of differing atoms, the Hamming distance, and keep the nearest models of for each . The preorder is then total.
- Borgida's operator. Return when it is satisfiable and the PMA result otherwise. This is a revision operator built from the PMA (Eiter and Gottlob 1992, Section 3).
- Satoh's revision. Compare the change sets by inclusion, as the PMA does, but minimize over all pairs of a model of and a model of together, not for each model of on its own.
- Protected formulas. Winslett's integrity constraints must hold in every result. Add them to , or keep them apart so that they need not be stated again for each action.
- With a solver. For formulas, the inner test "no model of has a smaller change set from " is a SAT question, so a two-level search, with an NP oracle inside an NP search, decides entailment.
When to use it
Use the PMA when the new formula describes the result of a change in the world, such as an action, an event or a database update, and the old beliefs are a disjunction of possible states. Each possible state must then evolve on its own, and a state that was possible before must lead to some state after. If the new formula is only more information about an unchanged world, use a revision operator such as Dalal's. If the atoms are not equally important or changes should be counted, use Forbus's operator or a weighted variant. If actions have indirect effects, write them as protected formulas or use a richer action theory such as the situation calculus, since the PMA alone may let unrelated atoms change.
Pitfalls
- Minimal for each model, not over the set. The minimum is taken for each model of on its own. Taking the closest models of to the whole set gives Satoh's revision, which fails U8.
- Inclusion, not count. A change of two atoms is kept when no other model of changes a subset of those atoms. Counting the atoms gives Forbus's operator, which can give a different result.
- Lost facts. The update keeps no fact of that could change. In the example, is lost, because one old state moved to a world where is true.
- Indirect effects. Without constraints, the PMA lets only the atoms in change, and it may also make a disjunction where common sense expects one definite change. Winslett's frame problem example uses protected formulas so that moving one object updates the facts that depend on it.
- Inconsistent base. The result is empty, not . This differs from Dalal's revision, which returns .
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/possible-models-approach/. The authors are listed in prov/J9PKJ2.jsonl.
"""Winslett's possible models approach (PMA) to belief update.
A world over n atoms is an integer w with 0 <= w < 2**n: bit i of w is 1 when
atom i is true. A belief base is given by its set of models. The set of atoms
on which two worlds w and v differ is the integer w ^ v.
The update K <> p is the union, over the models w of K, of the models v of p
whose change set w ^ v is minimal under set inclusion among the change sets
from w to the models of p (Winslett 1988, Section 3).
For one model w, the method marks in an array C of 2**n bits every change set
x that leads from w into p, and then closes C upwards, one atom at a time, so
that C[x] says "some model of p differs from w only on atoms inside x". This
is the zeta transform over subsets. A model v of p is kept when no proper
subset of x = w ^ v is marked, and it is enough to test the n sets that miss
one atom of x.
"""
def _check_worlds(worlds, n, name):
out = frozenset(worlds)
limit = 1 << n
for w in out:
if not isinstance(w, int) or isinstance(w, bool) or w < 0 or w >= limit:
raise ValueError(f"{name} holds {w!r}, which is not a world over {n} atoms")
return out
def closest_models(w, p, n):
"""The models v of p for which w ^ v is minimal under set inclusion."""
if w in p:
return frozenset([w]) # the empty change set is below every other one
size = 1 << n
c = [False] * size
for v in p:
c[w ^ v] = True
for i in range(n):
bit = 1 << i
for x in range(size):
if x & bit and not c[x]:
c[x] = c[x ^ bit]
keep = []
for v in p:
x = w ^ v
if not any(x >> i & 1 and c[x ^ (1 << i)] for i in range(n)):
keep.append(v)
return frozenset(keep)
def pma_update(k_models, p_models, n):
"""Mod(K <> p) under the possible models approach, as a frozenset."""
if n < 0:
raise ValueError("n must be at least 0")
k = _check_worlds(k_models, n, "k_models")
p = _check_worlds(p_models, n, "p_models")
result = set() # @line L1
size = 1 << n
for w in sorted(k): # @line L2
if w in p: # @line L3
result.add(w) # @line L4
continue
c = [False] * size
for v in p:
c[w ^ v] = True # @line L5
for i in range(n): # @line L6
bit = 1 << i
for x in range(size):
if x & bit and not c[x]:
c[x] = c[x ^ bit] # @line L7
for v in p: # @line L8
x = w ^ v
if not any(x >> i & 1 and c[x ^ (1 << i)] for i in range(n)): # @line L9
result.add(v) # @line L10
return frozenset(result) # @line L11
def pma_update_per_model(k_models, p_models, n):
"""The same update, returned as a dict from each model of K to its set of closest models of p."""
k = _check_worlds(k_models, n, "k_models")
p = _check_worlds(p_models, n, "p_models")
return {w: closest_models(w, p, n) for w in sorted(k)}
test_possible_models_approach.py 234 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/possible-models-approach/. The authors are listed in prov/J9PKJ2.jsonl.
import random
import pytest
from possible_models_approach import closest_models, pma_update, pma_update_per_model
def worlds(n):
return range(1 << n)
def random_set(rng, n, prob):
return frozenset(w for w in worlds(n) if rng.random() < prob)
def all_subsets(n):
ws = list(worlds(n))
for mask in range(1 << len(ws)):
yield frozenset(w for j, w in enumerate(ws) if mask >> j & 1)
def subset_of(x, y):
return x & y == x
def brute_force(k, p, n):
"""Union over the models w of k of the models of p whose change set from w is inclusion-minimal."""
out = set()
for w in k:
for v in p:
x = w ^ v
if not any(subset_of(w ^ u, x) and w ^ u != x for u in p):
out.add(v)
return frozenset(out)
def dalal(k, p, n):
"""Dalal's revision by brute force: the models of p at least Hamming distance from the set k."""
k, p = frozenset(k), frozenset(p)
if not p:
return frozenset()
if not k:
return p
dist = {v: min(bin(v ^ w).count("1") for w in k) for v in p}
best = min(dist.values())
return frozenset(v for v in p if dist[v] == best)
def forbus(k, p, n):
"""Forbus's update by brute force: for each model of k, the models of p at least Hamming distance from it."""
out = set()
for w in k:
dist = {v: bin(v ^ w).count("1") for v in p}
if dist:
best = min(dist.values())
out |= {v for v in p if dist[v] == best}
return frozenset(out)
# The KM update postulates U1 to U8, with formulas given by their sets of models.
def update_violations(op, k, k2, p, p2, q, n):
bad = []
r = op(k, p, n)
if not r <= p:
bad.append("U1")
if k <= p and r != k:
bad.append("U2")
if k and p and not r:
bad.append("U3")
if op(sorted(k, reverse=True), sorted(p, reverse=True), n) != r:
bad.append("U4")
if not (r & q) <= op(k, p & q, n):
bad.append("U5")
r2 = op(k, p2, n)
if r <= p2 and r2 <= p and r != r2:
bad.append("U6")
if len(k) == 1 and not (r & r2) <= op(k, p | p2, n):
bad.append("U7")
if op(k | k2, p, n) != r | op(k2, p, n):
bad.append("U8")
return bad
# The KM revision postulates R1 to R6, used to show that the PMA is not a revision.
def revision_violations(op, k, p, q, n):
bad = []
r = op(k, p, n)
if not r <= p:
bad.append("R1")
if k & p and r != k & p:
bad.append("R2")
if p and not r:
bad.append("R3")
if op(sorted(k, reverse=True), sorted(p, reverse=True), n) != r:
bad.append("R4")
rpq = op(k, p & q, n)
if not (r & q) <= rpq:
bad.append("R5")
if r & q and not rpq <= r & q:
bad.append("R6")
return bad
@pytest.mark.parametrize("n", [0, 1, 2, 3, 4, 5])
def test_matches_brute_force(n):
rng = random.Random(100 + n)
for _ in range(300):
k = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
p = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
assert pma_update(k, p, n) == brute_force(k, p, n)
@pytest.mark.parametrize("n", [1, 2, 3, 4, 5])
def test_model_by_model(n):
# For each single model w, the closest models are the inclusion-minimal change sets.
rng = random.Random(200 + n)
for _ in range(200):
k = random_set(rng, n, 0.3)
p = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
per = pma_update_per_model(k, p, n)
assert set(per) == set(k)
for w in k:
assert per[w] == brute_force({w}, p, n)
assert closest_models(w, p, n) == per[w]
union = frozenset().union(*per.values()) if per else frozenset()
assert union == pma_update(k, p, n)
def test_exhaustive_two_atoms():
for k in all_subsets(2):
for p in all_subsets(2):
assert pma_update(k, p, 2) == brute_force(k, p, 2)
@pytest.mark.parametrize("n", [1, 2, 3, 4, 5])
def test_update_postulates_u1_to_u8(n):
rng = random.Random(300 + n)
for _ in range(250):
k = random_set(rng, n, rng.choice([0.0, 0.1, 0.3, 0.6]))
if rng.random() < 0.3:
k = frozenset([rng.randrange(1 << n)]) # complete bases for U7
k2 = random_set(rng, n, rng.choice([0.1, 0.3]))
p = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
p2 = random_set(rng, n, rng.choice([0.1, 0.3, 0.6]))
if rng.random() < 0.2:
p2 = p | random_set(rng, n, 0.2)
q = random_set(rng, n, rng.choice([0.2, 0.5, 0.8]))
assert update_violations(pma_update, k, k2, p, p2, q, n) == []
def test_update_postulates_exhaustive_two_atoms():
subsets = list(all_subsets(2))
rng = random.Random(400)
for k in subsets:
for p in subsets:
for p2 in subsets:
k2 = rng.choice(subsets)
q = rng.choice(subsets)
assert update_violations(pma_update, k, k2, p, p2, q, 2) == []
# Atoms: b (the book is on the table) is bit 0, m (the magazine is on the table) is bit 1.
B, M = 1, 2
def test_book_and_magazine_update_differs_from_revision():
# K: exactly one of the book and the magazine is on the table. p: the book is on the table.
k = frozenset({B, M})
p = frozenset({B, B | M})
assert pma_update(k, p, 2) == {B, B | M} # update: b, and nothing is known about m
assert dalal(k, p, 2) == {B} # revision: b and not m
assert pma_update_per_model(k, p, 2) == {B: {B}, M: {B | M}}
# The update breaks R2: K and p are consistent, but the result is not K and p.
assert "R2" in revision_violations(pma_update, k, p, frozenset(worlds(2)), 2)
# The revision breaks U8: the models of K are not updated one by one.
assert "U8" in update_violations(dalal, k, frozenset({M}), p, p, p, 2)
assert dalal({B}, p, 2) | dalal({M}, p, 2) == {B, B | M}
# Atoms a, b, c are bits 0, 1, 2. The example of the page.
A, Bb, C = 1, 2, 4
def test_page_example():
k = frozenset({0, Bb | C}) # not a, and b if and only if c
p = frozenset({A, Bb | C}) # (a and not b and not c) or (not a and b and c)
assert pma_update_per_model(k, p, 3) == {0: {A, Bb | C}, Bb | C: {Bb | C}}
assert pma_update(k, p, 3) == {A, Bb | C}
# Forbus counts the changed atoms and drops the world two atoms away from 000.
assert forbus(k, p, 3) == {A, Bb | C}
assert forbus({0}, p, 3) == {A}
assert pma_update({0}, p, 3) == {A, Bb | C}
# Dalal's revision keeps only the common model.
assert dalal(k, p, 3) == {Bb | C}
def test_dalal_breaks_update_postulates_and_pma_breaks_r2():
rng = random.Random(500)
dalal_bad = pma_bad = 0
for _ in range(2000):
n = 3
k = random_set(rng, n, 0.3)
k2 = random_set(rng, n, 0.3)
p = random_set(rng, n, 0.4)
p2 = random_set(rng, n, 0.4)
q = random_set(rng, n, 0.5)
if update_violations(dalal, k, k2, p, p2, q, n):
dalal_bad += 1
bad = revision_violations(pma_update, k, p, q, n)
assert "R1" not in bad and "R4" not in bad and "R5" not in bad
# R3 fails only for an inconsistent base, which an update keeps inconsistent.
assert "R3" not in bad or not k
if "R2" in bad:
pma_bad += 1
assert dalal_bad > 0 and pma_bad > 0
def test_inconsistent_inputs():
# An inconsistent base stays inconsistent, and an inconsistent formula gives no model.
assert pma_update(set(), {1, 2}, 2) == set()
assert pma_update({1}, set(), 2) == set()
assert pma_update({0}, {0}, 0) == {0}
def test_bad_world_rejected():
with pytest.raises(ValueError):
pma_update({4}, {1}, 2)
with pytest.raises(ValueError):
pma_update({1}, {-1}, 2)
with pytest.raises(ValueError):
pma_update({1}, {1}, -1)
History
Winslett presented the PMA at AAAI-88 as a way to reason about actions. She contrasted it with the possible worlds approach of Ginsberg and Smith, which changes a set of formulas and so depends on how they are written. The PMA works on the models: each model is changed by as few atoms as set inclusion allows, and protected formulas state the laws of the domain. Katsuno and Mendelzon (1991) separated update from revision. They gave the postulates U1 to U8, proved a representation by faithful assignments of preorders, one for each world, and showed that the PMA is an update operator in their sense. Eiter and Gottlob (1992) found that its entailment problem is complete for the second level of the polynomial hierarchy, and coNP-complete for Horn formulas.
References
- Marianne Winslett, Reasoning about action using a possible models approach, Proceedings of the Seventh National Conference on Artificial Intelligence (AAAI-88), 89 to 93 (1988), p. 90, Section 3 (the definition of Incorporate(S, M) by set inclusion on the differing atoms, and the union over the models of the theory) and Section 4 (the frame problem example)
- Hirofumi Katsuno and Alberto O. Mendelzon, On the difference between updating a knowledge base and revising it, in James Allen, Richard Fikes and Erik Sandewall (eds), Proceedings of the Second International Conference on Principles of Knowledge Representation and Reasoning (KR'91), Morgan Kaufmann, 387 to 394 (1991), the whole paper (the postulates U1 to U8, their representation by faithful assignments of partial preorders, and the possible models approach as an update operator)
- Thomas Eiter and Georg Gottlob, On the complexity of propositional knowledge base revision, updates, and counterfactuals, Artificial Intelligence 57(2-3), 227 to 270 (1992), Section 3 (the model-based operators of Winslett, Forbus, Satoh and Borgida), Theorem 6.4 (the general case) and Theorem 7.2 (Horn formulas)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag J9PKJ2 Edit this page History Report an error Markdown