From 0210e408183e78ffbaa03e8fc03294720b6e5958 Mon Sep 17 00:00:00 2001 From: Haris Orgn Date: Tue, 16 Jan 2024 18:29:35 +0200 Subject: [PATCH] add function to get weight values between two bloxs --- src/Neuroblox.jl | 1 + src/blox/blox_utilities.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Neuroblox.jl b/src/Neuroblox.jl index 2bd4cd2c..e85cd03e 100644 --- a/src/Neuroblox.jl +++ b/src/Neuroblox.jl @@ -181,5 +181,6 @@ export create_adjacency_edges! export get_namespaced_sys, nameof export run_experiment!, run_trial! export addnontunableparams, get_hemodynamic_observers +export get_weights end \ No newline at end of file diff --git a/src/blox/blox_utilities.jl b/src/blox/blox_utilities.jl index d345a92c..02095996 100644 --- a/src/blox/blox_utilities.jl +++ b/src/blox/blox_utilities.jl @@ -235,6 +235,22 @@ function get_event_time(kwargs, name_blox1, name_blox2) end end +function get_weights(agent::Agent, blox_out, blox_in) + ps = parameters(agent.odesystem) + pv = agent.problem.p + map_idxs = Int.(ModelingToolkit.varmap_to_vars([ps[i] => i for i in eachindex(ps)], ps)) + + name_out = String(namespaced_nameof(blox_out)) + name_in = String(namespaced_nameof(blox_in)) + + idxs_weight = findall(ps) do p + n = String(Symbol(p)) + occursin("w_", n) && occursin(name_out, n) && occursin(name_in, n) + end + + return pv[map_idxs[idxs_weight]] +end + function find_spikes(x::AbstractVector{T}; minprom=zero(T), maxprom=nothing, minheight=zero(T), maxheight=nothing) where {T} spikes, _ = argmaxima(x) peakproms!(spikes, x; minprom, maxheight)