Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump Probability with Greyscale Images #24

Merged
merged 11 commits into from
Jun 15, 2023
Prev Previous commit
Next Next commit
Change the wy walls are checked for to include grey values and add ne…
…w example
  • Loading branch information
TomTranter committed May 14, 2020
commit 4b7647c0fb8ad6a82ccb3c9ffdaab660a5a9c66b
42 changes: 42 additions & 0 deletions checkers_and_stripes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 16:09:18 2020

@author: Tom
"""

import pytrax as pt
import numpy as np
import matplotlib.pyplot as plt
plt.close('all')
if __name__ == '__main__':
n = 5
im_chess = np.ones([10*n, 10*n])
g = 0.25
for i in range(10*n):
for j in range(10*n):
if (np.floor(i/n) % 2) != (np.floor(j/n) % 2):
im_chess[i, j] = g
plt.figure()
plt.imshow(im_chess)
rw_c = pt.RandomWalk(im_chess)
rw_c.run(nt=10000, nw=10000, num_proc=1, same_start=True)
rw_c.calc_msd()
rw_c.plot_msd()
rw_c.plot_walk_2d()
rw_c.plot_walk_2d(w_id=np.argmin(rw_c.sq_disp[-1, :]), data='t')
rw_c.plot_walk_2d(w_id=np.argmax(rw_c.sq_disp[-1, :]), data='t')

im = np.ones([10*n, 10*n])
for i in range(10*n):
if (np.floor(i/n) % 2 == 0):
im[i, :] = g
plt.figure()
plt.imshow(im)
rw = pt.RandomWalk(im)
rw.run(nt=10000, nw=10000, stride=10, num_proc=1, same_start=True)
rw.calc_msd()
rw.plot_msd()
rw.plot_walk_2d()
rw.plot_walk_2d(w_id=np.argmin(rw.sq_disp[-1, :]), data='t')
rw.plot_walk_2d(w_id=np.argmax(rw.sq_disp[-1, :]), data='t')
2 changes: 1 addition & 1 deletion grey.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

for case in [im, grey]:
rw = pt.RandomWalk(case, seed=False)
rw.run(num_t, num_w, same_start=False, stride=stride, num_proc=8)
rw.run(num_t, num_w, same_start=False, stride=stride, num_proc=10)
# Plot mean square displacement
rw.plot_msd()
rw.plot_walk_2d()
15 changes: 3 additions & 12 deletions pytrax/__RandomWalk__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ def _get_wall_map(self, image):
def check_wall(self, walkers, move):
r'''
The walkers are an array of coordinates of the image,
the wall map is a boolean map of the image rolled in each direction.
directions is an array referring to the movement up or down an axis
and is used to increment the walker coordinates if a wall is not met

move is the vector of their next movement, if a wall is not met
or the chance of entering a grey value is met then False is returned
Parameters
----------
walkers: ndarray of int and shape [nw, dim]
Expand All @@ -141,14 +139,7 @@ def check_wall(self, walkers, move):
the index of the wall map corresponding to the move vector
'''
next_move = walkers + move
if self.dim == 2:
move_ok = self.wall_map[next_move[:, 0],
next_move[:, 1]]
elif self.dim == 3:
move_ok = self.wall_map[next_move[:, 0],
next_move[:, 1],
next_move[:, 2]]
return ~move_ok
return self.get_probable_cancels(next_move)

def check_edge(self, walkers, axis, move, real):
r'''
Expand Down