using FileIO
using Parameters

include("random_matrices.jl")
include("network_sims.jl")
include("LS_calculations.jl")

#------------------------------------------------------------------------------
# This is the part where we find which eta and network realization to

J_seeds = collect(5000:5019)
etas = collect(-1.0:0.1:1.0)

ind = parse(Int64, ARGS[1])
ps = [(eta, J_seed) for eta in etas, J_seed in J_seeds]
eta, J_seed = ps[ind]
#------------------------------------------------------------------------------

# Where the results will be saved
dir = "results1"

N = 1000
g = 10.0
s = 1.0

h0_seed = 6000
dh_seed = 7000
Q0_seed = 8000

J = generate_J(N, eta, seed=J_seed)
h = generate_nv(N, Float64, seed=h0_seed)
dh = generate_nv(N, Float64, seed=dh_seed)
Q = generate_ONB(N, Float64, seed=Q0_seed)

dt = 0.01
t_bound = 2000.0
t_ONS = 1.0
wait = 200.0


@time Lspec, max_LE = sim_lyapunov(J, g, h, dh, Q; s=s, dt=dt, t_bound=t_bound,
		t_ONS=t_ONS, wait=wait, return_max_LE=true, printstuff=false,
		p_factor=1e-3, scale_limit=100)

dimensionality = KY_attractor_dim(Lspec)
entropy_rate = KS_entropy_rate(Lspec)


fn = "Lspecs_E$(ind)_N=$N,g=$g,eta=$eta,J_seed=$J_seed.jld2"
out = Dict{String,Any}()
@pack! out = N, g, eta, s, J_seed, h0_seed, dh_seed, Q0_seed, dt, t_bound,
		t_ONS, wait, Lspec, max_LE, dimensionality, entropy_rate

save(joinpath(dir, fn), out)
