Skip to content

Commit

Permalink
step_input_sequence gets multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
aquaresima committed Dec 11, 2024
1 parent 557a94e commit 6b807f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
34 changes: 26 additions & 8 deletions src/stimuli/bioseq/import_bioseq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,21 @@ function seq_bioseq(;experiment, stage::String, kwargs...)
end


function root_path(path, exp)
label = exp.info["label"]
seed = exp.info["seed_network"]
id = exp.info["seed"]
return joinpath(path, "id-$(id)_seed-$(seed)_$(label)") |> mkpath
end

function store_experiment_data(path, exp, network, seq)
## Root
_root = root_path(path, exp)

## Experiment data
label = exp.info["label"]
seed = exp.info["seed_network"]
id = exp.info["seed"]
_root = joinpath(path, "id-$(id)_seed-$(seed)_$(label)") |> mkpath
mapping = Dict(string(k)=>string.(v) for (k,v) in seq.dict)
exp_data = Dict(
"seed"=> seed,
Expand All @@ -132,31 +141,40 @@ function store_experiment_data(path, exp, network, seq)
return _root
end

function store_activity_data(_root::String, stage::String, sequence, model)
function store_activity_data(_root::String, stage::String, sequence, model; targets=[:d])
folder = joinpath(_root, stage) |> mkpath
@unpack stim = model
myspikes = vcat(spiketimes(model.pop.E), spiketimes(model.pop.I1), spiketimes(model.pop.I2))
myspikes = myspikes |> d-> Dict("$n"=>d[n] for n in eachindex(d))
labels = let
labels, target_pops, = let
stim_id =[]
stim_time = []
targets = Dict{String, Vector{Int}}()
target_pops = Dict{String, Vector{Int}}()
for k in sequence.symbols.phonemes
cells = []
for t in targets
t = Symbol(string(k,"_",t))
ph_stim = getfield(stim, t)
push!(cells, ph_stim.cells)
end
push!(target_pops, string(k)=>Set(vcat(cells...))|> collect)
end
for k in sequence.symbols.phonemes
ph_stim = getfield(stim,Symbol(string(k)*"_d"))
ph_stim = getfield(stim,Symbol(string(k,"_",targets[1])))
for interval in ph_stim.param.variables[:intervals]
push!(stim_time, interval[1])
push!(stim_id, k)
end
targets[string(k)] = ph_stim.cells
end
iid = sort(1:length(stim_id), by=x->stim_time[x])
labels = Dict{}()
for (k,t) in zip(stim_id[iid], stim_time[iid])
labels[string(t)] = string(k)
end
labels
labels, target_pops
end
DrWatson.save(joinpath(folder,"labels.h5"), labels)
DrWatson.save(joinpath(folder,"target_pops.h5"), target_pops)
DrWatson.save(joinpath(folder,"spiketimes.h5"), myspikes )

membrane, r_t = SNN.interpolated_record(model.pop.E, :v_s)
Expand Down Expand Up @@ -187,4 +205,4 @@ function store_activity_data(_root::String, stage::String, sequence, model)
end
##

export import_bioseq_tasks, seq_bioseq, bioseq_epochs, bioseq_lexicon, store_experiment_data, store_activity_data
export import_bioseq_tasks, seq_bioseq, bioseq_epochs, bioseq_lexicon, store_experiment_data, store_activity_data, root_path
18 changes: 12 additions & 6 deletions src/stimuli/sequence/sequence_generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,23 @@ function step_input_sequence(;
variables = merge(parameters, Dict(:intervals=>sign_intervals(s, seq)))
param = PSParam(rate=attack_decay,
variables=variables)
push!(stim, s =>Dict{Symbol,Any}())
@show stim
for t in targets
push!(stim, Symbol(string(s,"_",t)) => SNN.PoissonStimulus(E, :he, t, μ=proj_strength, param=param, name="w_$s", p_post=p_post))
push!(stim[s], t => SNN.PoissonStimulus(E, :he, t, μ=proj_strength, param=param, name="w_$s", p_post=p_post))
if !words
getfield(stim, Symbol(string(s,"_",t)) ).param.active[1] = false
stim[s][t].param.active[1] = false
end
end
end
for s in seq.symbols.phonemes
variables = merge(parameters, Dict(:intervals=>sign_intervals(s, seq)))
param = PSParam(rate=attack_decay,
variables=variables)
push!(stim, s =>Dict{Symbol,Any}())
for t in targets
push!(stim,Symbol(string(s,"_",t)) => SNN.PoissonStimulus(E, :he, t, μ=proj_strength, param=param, name="$s", p_post=p_post)
# ph = Symbol(string(s,"_",t))
push!(stim[s], t => SNN.PoissonStimulus(E, :he, t, μ=proj_strength, param=param, name="$s", p_post=p_post)
)
end
end
Expand All @@ -295,13 +299,15 @@ function randomize_sequence!(;lexicon, model, targets::Vector{Symbol}, words=tru
@unpack stim = model
for target in targets
for s in seq.symbols.words
getfield(stim, Symbol(string(s,"_",target)) ).param.variables[:intervals] = sign_intervals(s, new_seq)
word =Symbol(string(s,"_",t))
get(stim, word, error("Access to non-existing word")).param.variables[:intervals] = sign_intervals(s, new_seq)
if !words
getfield(stim, Symbol(string(s,"_",target)) ).param.active[1] = false
get(stim, word, error("Access to non-existing word")).param.active[1] = false
end
end
for s in lexicon.symbols.phonemes
getfield(stim, Symbol(string(s,"_",target)) ).param.variables[:intervals] = sign_intervals(s, new_seq)
ph = Symbol(string(s,"_",target))
get(stim, ph, error()).param.variables[:intervals] = sign_intervals(s, new_seq)
end
end
return new_seq
Expand Down

0 comments on commit 6b807f9

Please sign in to comment.