Note
Click here to download the full example code
Drunkard’s walk¶
The deeptime.data.drunkards_walk()
model, a markov state model on a 2-dimensional grid.
Number of steps in the walk: 74
8 import matplotlib.pyplot as plt
9
10 from deeptime.data import drunkards_walk
11
12 sim = drunkards_walk(grid_size=(10, 10),
13 bar_location=[(0, 0), (0, 1), (1, 0), (1, 1)],
14 home_location=[(8, 8), (8, 9), (9, 8), (9, 9)])
15
16 sim.add_barrier((5, 1), (5, 5))
17 sim.add_barrier((0, 9), (5, 8))
18 sim.add_barrier((9, 2), (7, 6))
19 sim.add_barrier((2, 6), (5, 6))
20
21 sim.add_barrier((7, 9), (7, 7), weight=5.)
22 sim.add_barrier((8, 7), (9, 7), weight=5.)
23
24 sim.add_barrier((0, 2), (2, 2), weight=5.)
25 sim.add_barrier((2, 0), (2, 1), weight=5.)
26
27 start = (7, 2)
28 walk = sim.walk(start=start, n_steps=250, seed=40)
29 print("Number of steps in the walk:", len(walk))
30
31 fig, ax = plt.subplots(figsize=(10, 10))
32
33 ax.scatter(*start, marker='*', label='Start', c='cyan', s=150, zorder=5)
34 sim.plot_path(ax, walk)
35 handles, labels = sim.plot_2d_map(ax)
36 ax.legend(handles=handles, labels=labels)
Total running time of the script: ( 0 minutes 0.752 seconds)
Estimated memory usage: 25 MB