Skip to content

Commit

Permalink
Merge pull request #25 from yfukai/add_example
Browse files Browse the repository at this point in the history
Add example
  • Loading branch information
yfukai authored Sep 21, 2021
2 parents 1da536a + e8c10d8 commit af1fedc
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/brownian_motion_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#%% # noqa:
from itertools import product

import numpy as np
from matplotlib import pyplot as plt

from laptrack import laptrack

track_length = 100
track_count = 10
L = 10
dimension = 2
diffusion_coef = 0.1

#%% # noqa:

init_cond = np.random.rand(track_count, dimension) * L

brownian_poss = np.array(
[
init_cond[i]
+ np.concatenate(
[
[np.zeros(dimension)],
np.cumsum(
np.sqrt(diffusion_coef)
* np.random.normal(size=(track_length, dimension)),
axis=0,
),
]
)
for i in range(track_count)
]
)

#%% # noqa:
for j, pos in enumerate(brownian_poss):
line = plt.plot(*zip(*pos), label=j)
c = line[0].get_color()
plt.plot(*map(lambda x: [x], init_cond[j]), "o", c=c)
plt.legend()

spots = [np.array([pos[t] for pos in brownian_poss]) for t in range(track_length)]
tree = laptrack(spots)
#%% # noqa:
for edge in tree.edges():
if (edge[0][0] + 1 != edge[1][0]) or (edge[0][1] != edge[1][1]):
print(edge)

for i, j in product(range(track_length - 1), range(track_count)):
if not any([edge[0] == (i, j) and edge[1] == (i + 1, j) for edge in tree.edges()]):
print(i, j)
# %%

0 comments on commit af1fedc

Please sign in to comment.