1
Image courtesy of JPL
Model-based Programming
and Constraint-based HMMs
Brian C. Williams
16.412J/6.834J
March 15
th
, 2004
Brian C. Williams, copyright 2000
2
Outline
x Review of Diagnosis and Mode Estimation
x Generalizing Mode Estimation to Optimal CSPs
? Model-based Programming w/o State
? Mode Estimation as Trajectory Tracking
3
Model-based Diagnosis
? A failure is a discrepancy between the
model and observations of an artifact.
? A diagnosis restores consistency.
1. Enumerate candidates in order of likelihood.
2. Test novel failures by suspending
constraints and testing consistency.
3. Symptoms in candidate identify conflicting
modes.
4. Conflicts prune remaining candidates.
4
Consistency-based Diagnosis
And(i):
? G(i):
Out(i) = In1(i) AND In2(i)
? U(i):
? Model: (X,Y) over system variables X
and mode variables Y
? Obs: Assignment to O ? X ? Y
? Candidate C
i
: Assignment of modes to Y
? Diagnosis D
i
: A candidate such that
D
i
? Obs ? (X,Y) is satisfiable.
1
1
1
1
0
Or1
Or3
And1
A
B
C
D
E
F
G
X
Y
Z
0
1
Diagnosis = {A1=G, A2=U O1=G, O2=U, O3=G}
?ALL components have
“unknown mode” U.
?U never assigned in C
5
?
?
3
2
2
3
3
M1
M3
A1
A
B
C
D
E
F
G
X
Y
Z
10
12
?
Kernel Diagnosis
= {A2=U, M2=U}
Compact Encoding:
Kernel Diagnoses
Partial Diagnosis: A set of component modes P
i
all of whose extensions are diagnoses.
? P
i
removes all symptoms
?P
i
entails (X,Y) ? Obs (implicant)
Kernel Diagnosis: A minimal partial diagnosis K
i
? K
i
is a prime implicant of (X,Y) ? Obs
6
Diagnoses Found by Mapping
Conflicts to Kernels
Conflict: A set of component modes C
i
that are
inconsistent with the model and observations.
? (X,Y) ? Obs entails not C
i
Kernel Diagnosis: A minimal set of component modes K
i
that
eliminate all symptoms.
?K
i
is a prime implicant of (X,Y) ? Obs
?K
i
is a prime implicant of all (minimal) conflicts
M1
M2
A1
A
B
C
D
E
3
2
2
3
F
G
X
Y
Z
10
6
6
12
M3
A2
?
?
3
2
2
3
3
M1
M3
A1
A
B
C
D
E
F
G
X
Y
Z
10
12
?
7
A2=U M1=U
M3=UA1=U
A1=U, A2=U,
M1=U, M3=U
A1=U M1=U M2=U
A1=U
M1=U M1=U ? A2=U M2=U ? M3=U
Conflicts Map To Kernels by Minimal Set Covering
A1=U, M1=U , M2=U
Conflicts
8
Ranking Diagnoses by Probability
() ( )
iij
iij
yv c
pc py v
?
?
Assume Failure and
Observation Independence
P(x
i
=v
ij
| c) estimated using Model:
? If previous Obs, c and entails z = v
Then p(z = v | c) = 1
? If previous obs, c and entails x <> v
Then p(z = v | c) = 0
? If consistent with all values for z
Then p(x = v | c) is based on priors
? E.g., uniform prior = 1/m for m possible values of x
(|)(|)
(| , )
()
iij
iij
iij
p xvcpcObs
pc x v Obs
px v
Bayes’
Rule
Normalization
9
Increasing
Cost
Feasible
Infeasible
Conflict 3
Conflict 2
Conflict 1
Diagnosis as Conflict-directed
Best First Search
10
Enumerating Probable Candidates
Generate
Candidate
Test
Candidate
Consistent?Keep
Compute
Posterior p
Below
Threshold?
Extract
Conflict
Done
Yes No
Yes No
Leading Candidate
Based on Priors
Sherlock: [de Kleer & Williams, 89]
11
Outline
x Review of Diagnosis and Mode Estimation
x Generalizing Mode Estimation to Optimal CSPs
? Model-based Programming w/o State
? Mode Estimation as Trajectory Tracking
12
Mode Estimation is an
Optimization Problem
Given:
? System variables X with domain D
X
? Mode variables Y with domain D
Y
? System model (X,Y) : D
X
x D
Y
o {True, False}
? Observations Obs(X,Y) : D
X
x D
Y
o {True, False}
Compute:
? Leading Arg Max P(Y | Obs )
Y ? D
Y
s.t. X ? D
X
. (X,Y) ? OBS(X,Y) is consistent
13
Generalize to Optimal CSP
Constraint Satisfaction Problem CSP = <X, D
X
,C>
? variables X with domain D
X
? Constraint C(X): D
X
o {True,False}
Find X in D
X
s.t. C(X) is True
Optimal CSP OCSP= <Y, g, CSP>
? Decision variables Y with domain D
Y
? Utility function g(Y): D
Y
o ?
? CSP is over variables <X,Y>
Find Leading arg max g(Y)
Y ? D
y
s.t. X ? D
Y
s.t. C(X,Y) is True
14
Outline
x Review of Diagnosis and Mode Estimation
x Generalizing Mode Estimation to Optimal CSPs
? Model-based Programming w/o State
? Mode Estimation as Trajectory Tracking
System Model
Control Program
RMPL Model-based Program
Control Sequencer
Deductive Controller
CommandsObservations
Plant
Titan Model-based Executive
State goalsState estimates
Mode
Estimation
Mode
Reconfiguration
Tracks
likely
plant states
Tracks least
cost goal states
z Executes concurrently
z Preempts
z Queries (hidden) states
z Asserts (hidden) state
Closed
Valve
Open
Stuck
open
Stuck
closed
Open Close
0. 01
0. 01
0.01
0.01
inflow = outflow = 0
Generates target goal states
conditioned on state estimates
Example: The model-based program sets
engine = thrusting, and the deductive controller . . .
Determines that valves
on the backup engine
will achieve thrust, and
plans needed actions.
Deduces that a valve
failed - stuck closed
Plans actions
to open
six valves
Fuel tankOxidizer tank
Deduces that
thrust is off, and
the engine is healthy
Mode
Estimation
Mode Reconfiguration
Mode Reconfiguration Mode Estimation
System Model
Control Program
RMPL Model-based Program
Control Sequencer
Deductive Controller
CommandsObservations
Plant
Titan Model-based Executive
State goalsState estimates
Mode
Estimation
Mode
Reconfiguration
Tracks
likely
plant states
Tracks least
cost goal states
z Executes concurrently
z Preempts
z Queries (hidden) states
z Asserts (hidden) state
Closed
Valve
Open
Stuck
open
Stuck
closed
Open Close
0. 01
0. 01
0.01
0.01
inflow = outflow = 0
Generates target goal states
conditioned on state estimates
Mode Reconfiguration:
Select a least cost set of
commandable component
modes that entail the current
goal, and are consistent
Mode Estimation:
Select a most likely set of
component modes that are
consistent with the model and
observations
arg min P
t
(Y| Obs)
s.t. (X,Y) ? O(m’) is consistent
arg max R
t
(Y)
s.t. (X,Y) entails G(X,Y)
s.t. (X,Y) is consistent
System Model
Control Program
RMPL Model-based Program
Control Sequencer
Deductive Controller
CommandsObservations
Plant
Titan Model-based Executive
State goalsState estimates
Mode
Estimation
Mode
Reconfiguration
Tracks
likely
plant states
Tracks least
cost goal states
z Executes concurrently
z Preempts
z Queries (hidden) states
z Asserts (hidden) state
Closed
Valve
Open
Stuck
open
Stuck
closed
Open Close
0. 01
0. 01
0.01
0.01
inflow = outflow = 0
Generates target goal states
conditioned on state estimates
arg min P
t
(Y| Obs)
s.t. (X,Y) ? O(m’) is consistent
arg max R
t
(Y)
s.t. (X,Y) entails G(X,Y)
s.t. (X,Y) is consistent
OpSat:
arg min f(x)
s.t. C(x) is satisfiable
D(x) is unsatisfiable
19
Closed
Open
Stuck
open
Stuck
closed
Cost 5
Prob .9
A Simple Concurrent State Model
? A device is described by a set of components communicating
through shared variables.
? A component has a set of modes and state variables.
? Modes are mutually exclusive and collectively exhaustive
? All components include the unknown mode.
? A mode has a:
? probability
? cost
? state constraint
Vlv = closed =>
Outflow = 0;
vlv=open =>
Outflow = M
z
+
(inflow);
vlv=stuck open =>
Outflow = M
z
+
(inflow);
vlv=stuck closed=>
Outflow = 0;
Unknown
20
Simple Mode Estimation
Goal: Left engine on Observe
“no thrust”
Enumerate by decreasing prior probability.
Update by Bayes rule.
Find most likely modes
consistent with observations.
21
Simple Mode Reconfiguration
Current state
Enumerate by increasing immediate cost.
Goal
“nominal thrust”
Find allowed states that entail goal.
22
Conflicts Focus MR
Goal: Achieve Thrust
A conflict, C, is an assignment to a subset of the control variables
that entails the negation of the goal.
23
Goal: Achieve Thrust
A conflict, C, is an assignment to a subset of the control variables
that entails the negation of the goal.
Conflicts Focus MR
24
Goal: Achieve Thrust
A conflict, C, is an assignment to a subset of the control variables
that entails the negation of the goal.
Conflicts Focus MR
25
Goal: Achieve Thrust
A conflict, C, is an assignment to a subset of the control variables
that entails the negation of the goal.
Conflicts Focus MR
26
Performance on Cassini
Failure
scenario
MI time
(Sparc 5 in sec)
MR time
(Sparc 5 in sec)
MI time
(est Sparc 5 sec)
MR time
(est Sparc 5 sec)
EGA
preaim
2.2 1.7 .07 .17
BPLVD
2.7 2.9 .18 .29
IRU
1.5 1.6 .02 .03
EGA burn
2.2 3.6 .08 .03
ACC
2.5 1.9 .04 .02
ME too
hot
2.4 3.8 .18 .78
Acc low
5.5 6.1 .25 .05
Number of components: 80
Number of clauses: 11,101
27
Outline
x Review of Diagnosis and Mode Estimation
x Generalizing Mode Estimation to Optimal CSPs
? Model-based Programming w/o State
? Mode Estimation as Trajectory Tracking
28
Estimating Dynamic Systems
Given sequence of commands and observations:
1. Infer current distribution of (most likely) states
2. Infer (most likely) trajectories
S T
X
0
X
1
X
N-1
X
N
S T
29
Hidden Markov Model
? X, A, Z : Finite States, Actions &
Observations
? T(x,a,x’): State transition function
T: X x A o 3(X) p(x’|a,x)
? O(x,z): Observation function
O: X o 3(Z) p(z|x)
? S(x): Initial state distribution
S: 3(X)
30
Hidden Markov Models
? X = {Coin
1,
Coin
2
}
? Z = {H,T}
? A = {}
? T, O, S:
? Observed sequence:
h, t, h, h, h, h, t, h, t, t, h, h, h, h, h
? Hidden sequence:
C
1
,C
1
,C
1
,C
1
,C
1
,C
2
,C
2
,C
2
,C
2
,C
1
,C
1
,C
2
,C
2
,C
2
,C
2
0.90.9
0.1
0.1
H (0.7)
T (0.3)
H (0.4)
T (0.6)
0.5
0.5
31
HMM Belief Tracking
1) Initialization
2) Induction
1
() ()
i
p xx S
1
1||
1
(,) ( , ,) ( )
()
(|, )
it jti t j
jX
ti
ttt
Ox z Tx a x p x
px
pz a p
d d
a o
? ?
|
() ( | ,,)
tt
px px za S
PredictCorrect
Normalize
32
Concurrent Probabilistic
Constraint Automata
Standby
Engine Model
Off
Unknown
Firing
component modes…
one per component … operating concurrently
On
Camera Model
Off
described by finite domain constraints on variables…
(thrust = full) AND
(power_in = nominal)
(thrust = zero) AND
(power_in = zero)
(thrust = zero) AND
(power_in = nominal)
(power_in = zero) AND
(shutter = closed)
(power_in = nominal) AND
(shutter = open)
deterministic and probabilistic transitions
off-
cmd
standby-
cmd
0.01
0.01
standby-
cmd
fire-
cmd
turnon-
cmd
turnoff-
cmd
0.01
0.01
cost/reward
0 v
0 v
2 kv
2 kv
0 v
20 v
0 v
Comparison With Path Planning
1
? Few variables
?O(10
4
)states
? Simple Action
& Observation Models
? Hundreds of variables
?O(10
150
) states (modes)
? Propositional Action
& Observation Models
How can we avoid enumerating the belief state?
34
Online Mode Estimation
Left engine on Observe
“no thrust”
K-best Filtering:
Enumerate by decreasing probability.
Track distribution of reachable modes
consistent with observations.
Track most likely trajectories.
35
Online Mode Estimation
Current
S
i
? S
u
i
W
j
S
O
i+1
W
k
S
i+1
Previous
Observed
Predicted
6
? Find feasible next states, given current state distribution,
commands and next state observations.
U
S
i 1
{
?
W
j
?
U
S
i
? U
S
P
i
entails )
jk
<
jk
§