-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sam Buercklin
committed
Dec 17, 2019
1 parent
372b3b8
commit b54ed74
Showing
6 changed files
with
132 additions
and
10 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,45 @@ | ||
# This file is machine-generated - editing it directly is not advised | ||
|
||
[[Base64]] | ||
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | ||
|
||
[[Distributed]] | ||
deps = ["Random", "Serialization", "Sockets"] | ||
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" | ||
|
||
[[InteractiveUtils]] | ||
deps = ["Markdown"] | ||
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | ||
|
||
[[Logging]] | ||
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | ||
|
||
[[Markdown]] | ||
deps = ["Base64"] | ||
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | ||
|
||
[[OrderedCollections]] | ||
deps = ["Random", "Serialization", "Test"] | ||
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" | ||
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | ||
version = "1.1.0" | ||
|
||
[[Parameters]] | ||
deps = ["OrderedCollections"] | ||
git-tree-sha1 = "b62b2558efb1eef1fa44e4be5ff58a515c287e38" | ||
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" | ||
version = "0.12.0" | ||
|
||
[[Random]] | ||
deps = ["Serialization"] | ||
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
|
||
[[Serialization]] | ||
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | ||
|
||
[[Sockets]] | ||
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" | ||
|
||
[[Test]] | ||
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] | ||
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
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 |
---|---|---|
|
@@ -2,3 +2,6 @@ name = "nnsim" | |
uuid = "2a7ddd44-2043-11ea-1b23-d1c817c05b75" | ||
authors = ["Sam Buercklin <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" |
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,6 +1,2 @@ | ||
# NNsim | ||
<<<<<<< HEAD | ||
|
||
`NNsim` is a Julia package meant for fixed-time-step simulations of neural networks, both artificial and spiking neural networks (ANNs and SNNs respectively). | ||
======= | ||
>>>>>>> 3736522c4565f06620c6c4d8c2280346f7a3a0e5 |
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,72 @@ | ||
# LIF Neuron | ||
@with_kw mutable struct LIF{F}<:AbstractNeuron | ||
τ::F = 5. # Time Constant (ms) | ||
R::F = 10.E3 # "Resistor" (kOhms) | ||
θ::F = 30. # Threshold voltage (mV) | ||
v0::F = -55. # Reset voltage (mV) | ||
I::F = 40. # Background current injection (mA) | ||
v::F = -55. # Membrane potential (mV) | ||
end | ||
|
||
function update!(neuron::LIF, input_update, dt, t) | ||
retval = 0 | ||
# If an impulse came in, add it | ||
neuron.v += input_update | ||
|
||
# Euler method updates to potential in 2 steps for numerical stability | ||
println("pre:", neuron.v) | ||
neuron.v += (dt/2 * 1/neuron.τ) * (-neuron.v + neuron.R*neuron.I) | ||
neuron.v += (dt/2 * 1/neuron.τ) * (-neuron.v + neuron.R*neuron.I) | ||
println("post:", neuron.v) | ||
|
||
# Check for thresholding | ||
if neuron.v >= neuron.θ | ||
neuron.v = neuron.v0 | ||
retval = 1 # Binary output | ||
end | ||
|
||
return retval | ||
end | ||
|
||
function reset!(neuron::LIF) | ||
neuron.v = neuron.v0 | ||
end | ||
|
||
# QIF Neuron | ||
# @with_kw struct QIF<:AbstractNeuron | ||
# c | ||
# end | ||
|
||
# Izhikevich Neuron | ||
@with_kw struct Izh{F}<:AbstractNeuron | ||
a::F = 0.02 | ||
b::F = 0.2 | ||
c::F = -65. | ||
d::F = 8. | ||
I::F = 25. # Background current injection (mA) | ||
v0::F = -65. # Reset voltage (mV) | ||
θ::F = 30. # Threshold potential (mV) | ||
|
||
v::F = -65. # Membrane potential (mV) | ||
u::F = 0. # Recovery variable | ||
end | ||
|
||
function update!(neuron::Izh, input_update, dt, t) | ||
retval = 0 | ||
|
||
# Euler method updates to potential in 2 steps for numerical stability | ||
neuron.v += (dt/2)*(0.05 * neuronv.v^2 + 5*neuron.v + 140 - neuron.u + neuron.I) | ||
neuron.u += (dt/2)*(neuron.a)*(neuron.b*neuron.v-neuron.u) | ||
|
||
neuron.v += (dt/2)*(0.05 * neuronv.v^2 + 5*neuron.v + 140 - neuron.u + neuron.I) | ||
neuron.u += (dt/2)*(neuron.a)*(neuron.b*neuron.v-neuron.u) | ||
|
||
# Check for thresholding | ||
if neuron.v >= neuron.θ | ||
neuron.v = neuron.v0 | ||
neuron.u += d | ||
retval = 1 | ||
end | ||
|
||
return retval | ||
end |
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,5 +1,10 @@ | ||
module nnsim | ||
|
||
greet() = print("Hello World!") | ||
using Parameters | ||
|
||
include("types.jl") | ||
include("neurons.jl") | ||
|
||
export AbstractNetwork, AbstractNeuron, Layer | ||
|
||
end # module |
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,6 +1,7 @@ | ||
abstract type Neuron | ||
abstract type AbstractNetwork end | ||
|
||
struct Layer{T} | ||
neurons::T | ||
W | ||
end | ||
abstract type AbstractNeuron <: AbstractNetwork end | ||
|
||
struct Layer{T}<:AbstractNetwork | ||
|
||
end |