-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleCode.py
81 lines (55 loc) · 1.59 KB
/
exampleCode.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Example code
execfile('decisionNode.py')
# Construct a tree with both left and right children
n=decisionNode() # root node 0
n.child0=decisionNode() # 1 3
n.child1=decisionNode() # 2
n.child0.child0=decisionNode()
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
# Now, construct a tree with four options and explore the effect of v
n = decisionNode() # root node 0
n.child0 = decisionNode() # 1 2
n.child1 = decisionNode() # options 1 2 3 4
# Default values of v result in deadlock.
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
plot(n.tt, n.mOptions)
# Increase v to destabilize deadlock
n.child0.v *= 100
n.child1.v *= 100
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
plot(n.tt, n.mOptions)
# Even with large v values symmetric initial conditions result in deadlock
# Perturb initial conditions to avoid deadlock.
n.m0[0] = 0.1
n.child0.m0[1] = 0.1
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
plot(n.tt, n.mOptions)
# Perturb v to make a clear winner.
n.child1.v[0] += 10
n.child0.m0[0] = 0.1
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
plot(n.tt, n.mOptions)
# And now, perturb v again so there are two winners
n.child1.v[1] += 10
n.child0.m0[1] = 0.095 # Make the initial condition symmetric
n.setup()
n.simulate()
n.mOut = n.parseMStates(n.zOut)
n.mOptions = n.parseLeafStates(n.mOut)
figure()
plot(n.tt, n.mOptions)