Skip to content
56 changes: 10 additions & 46 deletions scripts/dev/effect_of_v_only.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using GeneralAttractors.ManifoldUtils
using GeneralAttractors.Analysis
import GeneralAttractors.Analysis.ManifoldAnalysis: population_average
import GeneralAttractors.Simulations: decode_peak_location, plot_trajectory_and_decoded

import GeneralAttractors.Analysis: get_bump_speed

include("../networks/torus.jl")

Expand All @@ -22,8 +22,10 @@ and input velocities to see how it affects the bump speed

SIMULATE = true
fld_name = "torus_v_only"
can = toruscan

dt = 0.5
V = range(0.001, 1.0, length = 5) # speed stimuli
V = range(0.001, 0.05, length = 7) # speed stimuli


# ------------------------------ run simulations ----------------------------- #
Expand All @@ -43,39 +45,24 @@ if SIMULATE
"\n"^6 / hLine() |> print
println(Panel("Running sim $j/$(length(V))", style = "red", justify = :center))


can = CAN(
"torus",
cover,
n,
ξ_t,
d_t,
k_t;
offset_size = 1.5,
# Ω = Ω
)
TJ = Trajectory(
can;
T = nframes,
dt = dt,
σv = v,
μv = v,
vmax = v,
σθ = 0.0,
θ₀ = 0,
x₀ = 1,
y₀ = 1,
still = still,
modality=:constant
)


simulation = Simulation(can, TJ; η = 0.0, b₀ = 7.0)
simulation = Simulation(can, TJ; η = 0.0, b₀ = 7.0, τ=5)

# run
h, X̄ = @time run_simulation(
simulation;
frame_every_n = nothing,
discard_first_ms = 50,
discard_first_ms = still,
average_over_ms = 1,
fps = 10,
s₀ = 1.0 .* activate,
Expand All @@ -87,38 +74,15 @@ if SIMULATE
end


# ------------------------------- run analysis ------------------------------- #
can = CAN("torus", cover, n, ξ_t, d_t, k_t; offset_size = 0.1)



function ∑(x)
n, _, m = size(x)
real.(reshape(mean(x, dims = 2), (n, m)))
end


S = []
trajectory_V = []
for v in V
# get trjectory's speed
X = load_data(fld_name, "v_$(v)_torus_sim_trajectory_X")
traj_v = sum(diff(X[:, 1])) / (size(X, 1) * dt)
push!(trajectory_V, traj_v)
sim_name = "v_$(v)_torus"
push!(trajectory_V, v)

# load state history
history = load_simulation_history(fld_name, "v_$(v)_torus_history")
s = ∑(history.S)[:, 30:end]

# get peak location speed
peak_location = hcat(map(st -> decode_peak_location(st, can), eachcol(s))...)

on_mfld_speed = map(
i -> can.metric(peak_location[:, i], peak_location[:, i-1]),
2:size(peak_location, 2),
)
average_speed = sum(on_mfld_speed) / (length(on_mfld_speed) * dt) # tot displacement over time
push!(S, average_speed / (0.5))
push!(S, get_bump_speed(can, fld_name, sim_name*"_history"))
end


Expand Down
30 changes: 13 additions & 17 deletions scripts/dev/params_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fld_name = "ring_grid_search"
mfld = "ring"
# B = range(4, 6, length = 2) |> collect
B = [1]
D = range(0.05, 0.2, length = 35) |> collect
V = range(0.05, 0.2, length = 4) |> collect
D = range(0.05, 0.5, length = 35) |> collect
V = range(0.05, 0.5, length = 4) |> collect


params = product(B, D, V) |> collect
Expand Down Expand Up @@ -107,7 +107,7 @@ p2 = plot(

for (color, v) in zip(vcolors, V)
for (j, b) in enumerate(B)
_data = data[(data.v .== v).&(data.b.==b), :]
_data = data[(data.v.==v).&(data.b.==b), :]
p = j == 1 ? p1 : p2
plot!(
p,
Expand All @@ -122,11 +122,13 @@ for (color, v) in zip(vcolors, V)
[minimum(_data.s), maximum(_data.s)],
lw = 2,
color = color,
ls=:dash, alpha=.4, label=nothing
ls = :dash,
alpha = 0.4,
label = nothing,
)
end
end
plot(p1, size = (800, 800)) |> display
plot(p1, size = (800, 800)) |> display


p1 = plot(
Expand All @@ -135,28 +137,22 @@ p1 = plot(
# aspect_ratio = :equal,
# title = title * " b₀ = $(round(B[1], digits=1))",
)
vmin , vmax = V[1], V[2]
vmin, vmax = V[1], V[2]
for (color, d) in zip(dcolors, D)
for (j, b) in enumerate(B)
_data = data[(data.δ .== d).&(data.b.==b), :]
_data = data[(data.δ.==d).&(data.b.==b), :]

s_min = _data[_data.v .== vmin, :].s[1]
s_max = _data[_data.v .== vmax, :].s[1]
s_min = _data[_data.v.==vmin, :].s[1]
s_max = _data[_data.v.==vmax, :].s[1]


scatter!(
p1,
[d], [s_max/s_min],
lw = 2,
color = color,
label = nothing,
)
scatter!(p1, [d], [s_max / s_min], lw = 2, color = color, label = nothing)
end
end


# plot(p1, p2, size = (1000, 800)) |> display
plot(p1, size = (800, 800)) |> display
plot(p1, size = (800, 800)) |> display


# # ------------------------ plot v/s for different b\_0 ----------------------- #
Expand Down
14 changes: 7 additions & 7 deletions scripts/dev/run_sims_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fld_name = "ring_grid_search"
mfld = "ring"
# B = range(4, 6, length = 2) |> collect
B = [1]
D = range(0.05, 0.2, length = 35) |> collect
V = range(0.05, 0.2, length = 4) |> collect
D = range(0.05, 0.5, length = 35) |> collect
V = range(0.05, 0.5, length = 4) |> collect
τ = 20


Expand All @@ -42,14 +42,14 @@ function run_all_sims()
d = map(i -> toruscan.metric(x₀, toruscan.X[:, i]), 1:size(toruscan.X, 2))
activate = zeros(length(d))
activate[d.<0.5] .= 1

elseif mfld == "ring"
can = CAN("ring", cover, n, ξ_r, d_r, k_r; offset_size = δ, σ = σ)
x₀ = [π/2] # initialize state at position
x₀ = [π / 2] # initialize state at position
d = ringcan.metric.(x₀[1], ringcan.X[1, :])
activate = zeros(length(d))
activate[d .< .4] .= 1
activate[d.<0.4] .= 1

else
error()
end
Expand All @@ -74,7 +74,7 @@ function run_all_sims()
vmax = 2v,
x₀ = x₀,
still = still,
modality=:constant,
modality = :constant,
)
simulation = Simulation(can, TJ; η = 0.0, b₀ = b, τ = τ)

Expand Down
48 changes: 23 additions & 25 deletions scripts/networks/mobius.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using GeneralAttractors
using GeneralAttractors.Kernels
using GeneralAttractors: lerp
using GeneralAttractors.ManifoldUtils
import GeneralAttractors.ManifoldUtils: Manifoldℝ², Mobius, ψ_t, ψ_θ1, ψ_θ2
import GeneralAttractors.ManifoldUtils: Manifoldℝ², Mobius, MB_ψ1, MB_ψ2, MB_ψ3
import GeneralAttractors: MobiusEuclidean, mobius_embedding

println(Panel("Creating Mobius attractor", style = "green", justify = :center))
Expand All @@ -19,39 +19,37 @@ mfld = Mobius()
cover = CoverSpace(mfld)

# coordinates function (from neurons index to lattice coordintes)
ξ_m(i::Int, j::Int)::Vector =
[
lerp(i, n[1], mfld.xmin[1], mfld.xmax[1]),
lerp(j, n[2], mfld.xmin[2], mfld.xmax[2] - mfld.xmax[2] / n[2])
]
ξ_m(i::Int, j::Int)::Vector = [
lerp(i, n[1], mfld.xmin[1], mfld.xmax[1]),
lerp(j, n[2], mfld.xmin[2], mfld.xmax[2] - mfld.xmax[2] / n[2]),
]

# metric
d_m = MobiusEuclidean()

# connectivity kernel
k_m = LocalGlobalKernel(α = 1.25, σ = 1.5, β = 1.25)
k_m = LocalGlobalKernel(α = 2.5, σ = 1.5, β = 2.5)


# define offset vector fields
offsets =
[
p -> ψ_t(p),
p -> -ψ_t(p),
p -> ψ_θ1(p),
p -> -ψ_θ1(p),
p -> ψ_θ2(p),
p -> -ψ_θ2(p)
]
offset_size = 0.25
offsets = [
p -> MB_ψ1(p),
p -> -MB_ψ1(p),
p -> MB_ψ2(p),
p -> -MB_ψ2(p),
# p -> MB_ψ3(p),
# p -> -MB_ψ3(p)
]
offset_size = 0.2

# define one forms
Ω = [
OneForm(1, (t, θ) -> offset_size * ψ_t(t, θ)),
OneForm(2, (t, θ) -> -offset_size * ψ_t(t, θ)),
OneForm(3, (t, θ) -> offset_size * ψ_θ1(t, θ)),
OneForm(4, (t, θ) -> -offset_size * ψ_θ1(t, θ)),
OneForm(5, (t, θ) -> offset_size * ψ_θ2(t, θ)),
OneForm(6, (t, θ) -> -offset_size * ψ_θ2(t, θ)),
OneForm(1, (t, θ) -> offset_size * MB_ψ1(t, θ)),
OneForm(2, (t, θ) -> -offset_size * MB_ψ1(t, θ)),
OneForm(3, (t, θ) -> offset_size * MB_ψ2(t, θ)),
OneForm(4, (t, θ) -> -offset_size * MB_ψ2(t, θ)),
# OneForm(5, (t, θ) -> offset_size * MB_ψ3(t, θ)),
# OneForm(6, (t, θ) -> -offset_size * MB_ψ3(t, θ)),
]


Expand All @@ -67,6 +65,6 @@ mobiuscan = CAN(
offset_size = offset_size,
offsets = offsets,
Ω = Ω,
σ=:softrelu,
α = 7,
σ = :softrelu,
α = 35,
)
15 changes: 6 additions & 9 deletions scripts/networks/ring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import GeneralAttractors.ManifoldUtils: Ring, ring_ψ
println(Panel("Creating ring attractor", style = "green", justify = :center))

# neurons position and distance function
n = (200,) # number of neurons in the ring
n = (64,) # number of neurons in the ring

# neurons coordinates and metric
ξ_r(i::Int)::Vector = [lerp(i, n[1], 0.0, 2π - 2π / n[1])] # neurons coordinates function
Expand All @@ -25,21 +25,18 @@ k_r = LocalGlobalKernel(α = 2.5, σ = 0.25, β = 2.5)
cover = CoverSpace(Ring())

# offsets and one forms
offset_size = .1
offset_size = .15
offsets = [
p -> ring_ψ(p),
p -> -ring_ψ(p)
]

Ω = OneForm[
OneForm(1, (x) -> ring_ψ(x)),
OneForm(1, (x) -> -ring_ψ(x))
]
Ω = OneForm[OneForm(1, (x) -> ring_ψ(x)), OneForm(1, (x) -> -ring_ψ(x))]

# make network
ringcan = CAN("ring", cover, n, ξ_r, d_r, k_r;
offsets = offsets,
Ω = Ω,
# offsets = offsets,
# Ω = Ω,
offset_size = offset_size,
σ = :softrelu,
α = 350) # 120
α = 25) # 120
29 changes: 17 additions & 12 deletions scripts/networks/sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using GeneralAttractors
using GeneralAttractors.Kernels
using GeneralAttractors: lerp
using GeneralAttractors.ManifoldUtils
import GeneralAttractors.ManifoldUtils: sphere_embedding, ψx, ψy, ψz, fibonacci_sphere
import GeneralAttractors.ManifoldUtils: sphere_embedding, sphere_ψx, sphere_ψy, sphere_ψz, fibonacci_sphere
import GeneralAttractors.Can: OneForm


Expand All @@ -15,7 +15,7 @@ println(Panel("Creating sphere attractor", style = "green", justify = :center))


# number of neurons
m = 64
m = 40
n = m^2

# get neurons on S² ⊂ ℝ³
Expand All @@ -26,26 +26,30 @@ I = [(i,) for i = 1:size(X, 2)]

# distance metric on the unit sphere
d_s = SphericalDistance()
# d_s = SphericalAngle()

# kernel
k_s = LocalGlobalKernel(α = 0.5, σ = 0.5, β = 0.5)
k_s = LocalGlobalKernel(α = 2.5, σ = 40.5, β = 2.5)

# cover space
cover = CoverSpace(S²) # trivial cover space

# define offset vector fields
offsets = [p -> ψx(p), p -> -ψx(p), p -> ψy(p), p -> -ψy(p), p -> ψz(p), p -> -ψz(p)]
offset_size = 0.15
offsets = [
p -> sphere_ψx(p), p -> -sphere_ψx(p),
p -> sphere_ψy(p), p -> -sphere_ψy(p),
p -> sphere_ψz(p), p -> -sphere_ψz(p)
]
offset_size = 0.1

# define one forms
α = 1 / offset_size .* 2
Ω = [
OneForm(1, (x, y, z) -> α * ψx(x, y, z)),
OneForm(2, (x, y, z) -> -α * ψx(x, y, z)),
OneForm(3, (x, y, z) -> α * ψy(x, y, z)),
OneForm(4, (x, y, z) -> -α * ψy(x, y, z)),
OneForm(5, (x, y, z) -> α * ψz(x, y, z)),
OneForm(6, (x, y, z) -> -α * ψz(x, y, z)),
OneForm(1, (x, y, z) -> offset_size * sphere_ψx(x, y, z)),
OneForm(1, (x, y, z) -> -offset_size * sphere_ψx(x, y, z)),
OneForm(2, (x, y, z) -> offset_size * sphere_ψy(x, y, z)),
OneForm(2, (x, y, z) -> -offset_size * sphere_ψy(x, y, z)),
OneForm(3, (x, y, z) -> offset_size * sphere_ψz(x, y, z)),
OneForm(3, (x, y, z) -> -offset_size * sphere_ψz(x, y, z)),
]


Expand All @@ -61,4 +65,5 @@ spherecan = CAN(
offset_size = offset_size,
offsets = offsets,
Ω = Ω,
α = 46,
)
Loading