-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHKPNT] Organised repo; Added Readout training
- Loading branch information
1 parent
aacb98d
commit 25d2518
Showing
16 changed files
with
318 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
"type": "julia", | ||
"request": "launch", | ||
"name": "Run active Julia file", | ||
"program": "${file}", | ||
"stopOnEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"juliaEnv": "${/home/guilam/phd-psy/ppsp/LiquidStateMachine.jl/LSM-v1}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[deps] | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
SpikingNN = "a2976702-bddd-11e9-29f3-e11e525b718e" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[deps] | ||
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
SpikingNeuralNetworks = "9d8b7fda-1049-58bc-9481-071a9f369938" |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# from: https://github.com/darsnack/SpikingNN.jl/blob/master/examples/stdp-test.jl | ||
# download with ] add {github page link} | ||
|
||
# PROS: | ||
# GPU integration | ||
# Clean code | ||
# CONS: | ||
# <<N | ||
|
||
using Plots | ||
using SpikingNN | ||
|
||
# simulation parameters | ||
T = 1000 | ||
|
||
# create three SRM0 neurons | ||
η₀ = 5.0 | ||
τᵣ = 1.0 | ||
vth = 1.0 | ||
|
||
# create population | ||
weights = Float32[ 0 5; | ||
0 0] | ||
pop = Population(weights; cell = () -> SRM0(η₀, τᵣ), | ||
synapse = Synapse.Alpha, | ||
threshold = () -> Threshold.Ideal(vth), | ||
learner = STDP(0.5, 0.5, size(weights, 1))) | ||
|
||
# create step input currents | ||
input = InputPopulation([ConstantRate(0.8)]) | ||
|
||
# create network | ||
net = Network(Dict([:input => input, :pop => pop])) | ||
connect!(net, :input, :pop; weights = [1 0], synapse = Synapse.Alpha) | ||
|
||
# simulate | ||
w = Float64[] | ||
voltages = Dict([(i, Float64[]) for i in 1:2]) | ||
cb = () -> begin | ||
push!(w, net[:pop].weights[1, 2]) | ||
for id in 1:size(pop) | ||
push!(voltages[id], getvoltage(pop[id])) | ||
end | ||
end | ||
@time outputs = simulate!(net, T; cb = cb, dense = true) | ||
|
||
weight_plot = plot(1:T, w, label = "") | ||
title!("Synaptic Weights Over Simulation") | ||
xlabel!("Time (sec)") | ||
ylabel!("Weight") | ||
|
||
raster_plot = rasterplot(outputs[:pop]) | ||
title!("Raster Plot") | ||
xlabel!("Time (sec)") | ||
|
||
plot(voltages[1], label = "Input") | ||
voltage_plot = plot!(voltages[2], label = "Neuron") | ||
title!("Membrane Voltages") | ||
xlabel!("Time (sec)") | ||
ylabel!("Voltage (V)") | ||
|
||
plot(weight_plot, raster_plot, voltage_plot, layout = grid(3, 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# from: https://docs.sciml.ai/SciMLTutorialsOutput/html/models/08-spiking_neural_systems.html | ||
|
||
using DifferentialEquations | ||
# load error :/ | ||
using Plots | ||
gr() | ||
|
||
function lif(u,p,t); | ||
gL, EL, C, Vth, I = p | ||
(-gL*(u-EL)+I)/C | ||
end | ||
|
||
function thr(u,t,integrator) | ||
integrator.u > integrator.p[4] | ||
end | ||
|
||
function reset!(integrator) | ||
integrator.u = integrator.p[2] | ||
end | ||
|
||
threshold = DiscreteCallback(thr,reset!) | ||
current_step= PresetTimeCallback([2,15],integrator -> integrator.p[5] += 210.0) | ||
cb = CallbackSet(current_step,threshold) | ||
|
||
u0 = -75 | ||
tspan = (0.0, 40.0) | ||
# p = (gL, EL, C, Vth, I) | ||
p = [10.0, -75.0, 5.0, -55.0, 0] | ||
|
||
prob = ODEProblem(lif, u0, tspan, p, callback=cb) | ||
|
||
sol = solve(prob) | ||
|
||
plot(sol) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# install: julia> Pkg.add("https://github.com/AStupidBear/SpikingNeuralNetworks.jl") | ||
|
||
using Plots | ||
using Random | ||
using SpikingNeuralNetworks | ||
SNN.@load_units | ||
|
||
# N = 1000 | ||
# E1 = SNN.IF(;N = N) | ||
# E2 = SNN.IF(;N = N) | ||
# EE = SNN.SpikingSynapse(E1, E2, :ge) | ||
# for n = 1:E1.N SNN.connect!(EE, n, n) end | ||
# SNN.monitor([E1, E2], [:fire]) | ||
# SNN.monitor(EE, [:W]) | ||
|
||
# @time for t = 1:N | ||
# E1.v[t] = 100 | ||
# E2.v[N - t + 1] = 100 | ||
# SNN.train!([E1, E2], [EE], 0.5ms, (t - 1) * 0.5ms) | ||
# end | ||
# SNN.raster([E1, E2]) | ||
# ΔW = EE.records[:W][end] | ||
# plot(ΔW) | ||
|
||
# spike_train = E1.:fire | ||
# plot(spike_train) | ||
|
||
E = SNN.IF(;N = 3200, param = SNN.IFParameter(;El = -49mV)) | ||
I = SNN.IF(;N = 800, param = SNN.IFParameter(;El = -49mV)) | ||
EE = SNN.SpikingSynapse(E, E, :ge; σ = 60*0.27/10, p = 0.02) | ||
EI = SNN.SpikingSynapse(E, I, :ge; σ = 60*0.27/10, p = 0.02) | ||
IE = SNN.SpikingSynapse(I, E, :gi; σ = -20*4.5/10, p = 0.02) | ||
II = SNN.SpikingSynapse(I, I, :gi; σ = -20*4.5/10, p = 0.02) | ||
P = [E, I] | ||
C = [EE, EI, IE, II] | ||
|
||
SNN.monitor([E, I], [:fire]) | ||
SNN.monitor([EE, EI, IE, II], [:W]) | ||
|
||
SNN.sim!(P, C; duration = 1second) | ||
SNN.raster(P) | ||
SNN.train!(P, C; duration = 1second) | ||
|
||
ΔW = EE.records[:W][end] | ||
plot(ΔW) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,43 @@ | ||
module LiquidStateMachine | ||
|
||
using CUDA | ||
using Distributions | ||
# using DifferentialEquations | ||
using Pkg | ||
|
||
Pkg.activate("LSM-v1") | ||
|
||
using Flux | ||
using LinearAlgebra | ||
using Random | ||
using StableRNGs | ||
using WaspNet | ||
using Zygote | ||
using ChainRulesCore | ||
using Plots | ||
using SparseArrays | ||
using Statistics | ||
|
||
include("util.jl") | ||
export genPositive, discretize | ||
include("min_lsm_v1.jl") | ||
export LSM | ||
|
||
include("params.jl") | ||
# using CUDA | ||
# using Distributions | ||
# # using DifferentialEquations | ||
# using Flux | ||
# using LinearAlgebra | ||
# using Random | ||
# using StableRNGs | ||
# using WaspNet | ||
# using Zygote | ||
|
||
include("spike_interpreter.jl") | ||
export SpikeTrainGenerator, SpikeTrainDecipher | ||
# include("util.jl") | ||
# export genPositive, discretize | ||
|
||
include("lsm.jl") | ||
export LSM, LSM_Params | ||
# include("params.jl") | ||
|
||
# include("spike_interpreter.jl") | ||
# export SpikeTrainGenerator, SpikeTrainDecipher | ||
|
||
using Plots | ||
# include("lsm.jl") | ||
# export LSM, LSM_Params | ||
|
||
|
||
# using Plots | ||
|
||
include("liquid_util.jl") | ||
export SP,eigen_spectrum | ||
# include("liquid_util.jl") | ||
# export SP,eigen_spectrum | ||
|
||
end # module |
Oops, something went wrong.