-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward.py
More file actions
31 lines (21 loc) · 872 Bytes
/
Copy pathforward.py
File metadata and controls
31 lines (21 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def expect(xDistribution, function):
fxProduct=[px*function(x) for x, px in xDistribution.items()]
expectation=sum(fxProduct)
return expectation
def forward(xT_1Distribution, eT, transitionTable, sensorTable):
temp = {xT:expect(xT_1Distribution,lambda xt_1:transitionTable[xt_1][xT])*sensorTable[xT][eT] for xT in xT_1Distribution.keys()}
if sum(temp.values()) == 0:
alpha = 0
else:
alpha = 1/sum(temp.values())
xT = {nextState:alpha*prob for nextState,prob in temp.items()}
return xT
def main():
pX0={0:0.3, 1:0.7}
e=1
transitionTable={0:{0:0.6, 1:0.4}, 1:{0:0.3, 1:0.7}}
sensorTable={0:{0:0.6, 1:0.3, 2:0.1}, 1:{0:0, 1:0.5, 2:0.5}}
xTDistribution=forward(pX0, e, transitionTable, sensorTable)
print(xTDistribution)
if __name__=="__main__":
main()