Skip to content

Instantly share code, notes, and snippets.

@AidanRocke AidanRocke/crazy_paths.jl
Last active Mar 27, 2019

Embed
What would you like to do?
A generative model based on the 2/3 power law
using Random
function crazy_paths(N,delta_t)
ddx, dx = 10*(2*rand(N+1) .-1.0), 10*(2*rand(N+1) .-1.0)
ddy, dy = 10*(2*rand(N+1) .-1.0), 10*(2*rand(N+1) .-1.0)
x, y = 10*(2*rand(N+1) .-1.0), 10*(2*rand(N+1) .-1.0)
K = abs(ddx[1]*dy[1]-dx[1]*ddy[1])
A, B = zeros(N), zeros(N)
for i = 1:N
## the transformation:
alpha, beta, theta = (-1)^rand(1:2)*rand(0.1:0.01:10), (-1)^rand(1:2)*rand(0.1:0.01:10), rand()
delta = 2*rand(2) .-1.0 ## a translation vector which doesn't change the volume
M = [cos(2*pi*theta)/alpha sin(2*pi*theta)*beta; -1*sin(2*pi*theta)/beta cos(2*pi*theta)*alpha];
A[i], B[i] = M[1], M[3]
## update the variables:
#ddx[i+1] = M[1]*ddx[i] + M[3]*dx[i] .+ delta[1]
#ddy[i+1] = M[1]*ddy[i] + M[3]*dy[i] .+ delta[1]
#dx[i+1] = M[2]*ddx[i] + M[4]*dx[i] .+ delta[2]
#dy[i+1] = M[2]*ddy[i] + M[4]*dy[i] .+ delta[2]
## update the variables:
ddx[i+1] = M[1]*ddx[i] + M[3]*dx[i]
ddy[i+1] = M[1]*ddy[i] + M[3]*dy[i]
dx[i+1] = M[2]*ddx[i] + M[4]*dx[i]
dy[i+1] = M[2]*ddy[i] + M[4]*dy[i]
## update:
x[i+1] = x[i] + dx[i]*delta_t + 0.5*ddx[i]*delta_t^2
y[i+1] = y[i] + dy[i]*delta_t + 0.5*ddy[i]*delta_t^2
end
q_4 = ddy[1]*A[1] + dy[1]*B[1]
q_2 = ddx[1]*A[1] + dx[1]*B[1]
return x,y,q_4, q_2
end
function test_hypothesis(N,delta_t)
output = zeros(100)
for i=1:100
x,y,q_4, q_2 = crazy_paths(N,delta_t)
range = rand(20:80)
lower, upper = rand(1:N-range), rand(N-range+1:N)
expected_slope = q_4/q_2
actual_slope = (y[upper]-y[lower])/(x[upper]-x[lower])
max_slope = max(expected_slope,actual_slope)
min_slope = min(expected_slope,actual_slope)
sign_exp, sign_act = abs(expected_slope)/expected_slope, abs(actual_slope)/actual_slope
if sign_exp*sign_act == 1.0 && max_slope/min_slope < 2.0
output[i] = 1.0
end
end
return output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.