Skip to content

Commit

Permalink
Added util function to generate Poisson Spike Train based on value ve…
Browse files Browse the repository at this point in the history
…ctor
  • Loading branch information
GuillaumeLam authored and SBuercklin committed Aug 27, 2021
1 parent c85bfd5 commit b550487
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/WaspNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ using Parameters
using Random

include("types.jl")

include("defs.jl")
include("neurons.jl")
include("layer.jl")
include("network.jl")
include("neurons.jl")
include("simulate.jl")
include("utils.jl")

Expand All @@ -22,4 +23,6 @@ export update

export batch_layer_construction, network_constructor, layer_constructor, feed_forward_network

export poissonST

end # module
14 changes: 14 additions & 0 deletions src/utilities/poisson.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
poissonST(l::AbstractVector)
Generates Poisson Spike Trains based on the normalized vector. Each
pseudo-neuron (probability p in vector), fires with probability p at each
timestep of simulation.
# Inputs
- `l`: array of values
"""

function poissonST(l::AbstractVector)
return poissonST(t) = [Float64(rand(Bernoulli(p), 1)[1]) for p in normalize(l)]
end
6 changes: 4 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Various useful utility functions
# Various useful utility functions

include("utilities/utils.jl")

# A pruning framework to remove neurons from Networks and Layers
include("utilities/pruning.jl")
include("utilities/pruning.jl")

include("utilities/poisson.jl")
6 changes: 6 additions & 0 deletions test/utility_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ using WaspNet

include("pruning_tests.jl")

@test begin
inputs = [1,1]
p = poissonST(inputs)
spikes = p(1)
spikes == [0,0] || spikes == [0,1] || spikes == [1,0] || spikes == [1,1]
end
end

0 comments on commit b550487

Please sign in to comment.