-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbias_random_walk.jl
74 lines (60 loc) · 1.69 KB
/
bias_random_walk.jl
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
using Gadfly;
using Distributions;
using PyPlot;
using Plotly;
# Initialize vectors
x = zeros(1000)
y = zeros(1000)
z = zeros(1000)
# Set initial time = 0 and have a total
t = 0
total_time = 1000
# Create vectors to store r, theta, phi, time, holding time for each xyz coordinate
all_r = zeros(1000)
all_theta = zeros(1000)
all_phi = zeros(1000)
time = zeros(1000)
holding_time = zeros(1000)
# Create starting position at the origin
x[1] = 0.0;
y[1] = 0.0;
z[1] = 0.0;
# Perform simulation while t is <= total time of the reaction
while t <= total_time
for i = 2:length(x)
# Sample holding time from exponential distribution or another dist?
t_next_jump = rand(Exponential())
# Update the time
t = t+t_next_jump
# Creating a random point in 3D
# Step size = r
# Same distribution used in Cell Press Paper
r = rand(TruncatedNormal(0,1,0,1))
theta = acos(1-2*rand()) # theta between 0:pi radians
phi = 2*pi*rand() # phi between 0:2*pi radians
# mapping spherical coordinates onto the cartesian plane
dx = r*sin(theta)*cos(phi);
dy = r*sin(theta)*sin(phi);
dz = r*cos(theta);
# Updated position
x[i] = x[i-1] + dx
y[i] = y[i-1] + dy
z[i] = z[i-1] + dz
# Push to store all values associated with a coordinate
push!(all_r, r)
push!(all_theta, theta)
push!(all_phi, phi)
push!(time, t)
push!(holding_time, t_next_jump)
end
end
println(all_phi)
# Plotting
using PyPlot; const plt = PyPlot
PyPlot.PyObject(PyPlot.axes3D)
x = x
y = y
z = z
fig = plt.figure()
ax = fig[:add_subplot](111, projection="3d")
ax[:plot](x, y, z)