Utility functions
Blox are the basic components of neural circuits. For documentation of the kinds of blox available, please see the Blox documentation page. Internally these are represented as ModelingToolkit systems.
The following functions are used to query blox.
NeurobloxBase.get_exci_neurons — Function
get_exci_neurons(n::Union{GraphSystem, AbstractBlox})Returns all excitatory neurons within a blox or graph.
- If
n <: Union{GraphSystem, AbstractComposite}, returns all excitatory neurons within the graph or composite blox. - If
n::AbstractExciNeuron, returns a single-element vector[n].
NeurobloxBase.get_inh_neurons — Function
get_inh_neurons(n::Union{GraphSystem, AbstractBlox})Returns all inhibitory neurons within a blox or graph.
- If
n <: Union{GraphSystem, AbstractComposite}, returns all inhibitory neurons within the graph or composite blox. - If
n::AbstractInhNeuron, returns a single-element vector[n].
Base.nameof — Function
nameof(blox)Returns the name of blox without the namespace prefix.
See also namespaced_nameof and full_namespaced_nameof.
NeurobloxBase.namespaced_nameof — Function
namespaced_nameof(blox)Returns the name of the blox, prefaced by its entire inner namespace (all levels of the namespace EXCEPT for the highest level). Namespaces represent the parent composite blox or graph that blox belongs to. E.g. the name cort1.wta2.neuron4 comes from a neuron neuron4 which belongs to wta2 (possibly a WinnerTakeAll blox) which in turn is part of cort1 (possibly a Cortical blox).
See also nameof and full_namespaced_nameof.
NeurobloxBase.full_namespaced_nameof — Function
full_namespaced_nameof(blox)Return the name of the blox, prefaced by its entire inner namespace (all levels of the namespace INCLUDING for the highest level). Namespaces represent the parent composite blox or graph that blox belongs to. E.g. the name mdl.cort1.wta2.neuron4 comes from a neuron neuron4 which belongs to wta2 (possibly a WinnerTakeAll blox), which in turn is part of cort1 (possibly a Cortical blox), which finally is part of a circuit mdl.
See also nameof and namespaced_nameof.
Additionally there are several helpers for extracting useful information from solutions to simulations, such as the timing of spikes and the firing rate. Several of these are called by the plotting functions.
NeurobloxBase.detect_spikes — Function
detect_spikes(blox::AbstractNeuron, sol::AbstractSolution;
threshold=nothing,
tolerance=1e-3,
ts=nothing,
scheduler=:serial)Find the spike timepoints of blox according to simulation solution sol. Return a SparseVector that is equal to 1 at the timepoints of each spike.
Keyword arguments: - threshold : [mV] Spiking threshold. Note that neurons like NeurobloxPharma.HHNeuronExci and NeurobloxPharma.HHNeuronInhib do not inherently contain a threshold and so require this threshold argument to be passed in order to determine spiking events. - tolerance : [mV] The tolerance around the threshold value in which a maximum counts as a spike. - ts : [ms] Timepoints in simulation solution sol where spikes are detected. It can be a range, a vector or an individual timepoint. If no values are passed (and ts=nothing) then the entire range of the solution sol is used.
NeurobloxBase.firing_rate — Function
firing_rate(blox::Union{AbstractComposite, Vector{AbstractNeuron}}, sol::AbstractSolution;
transient=0, win_size=last(sol.t) - transient,
overlap=0, threshold=nothing,
scheduler=:serial, kwargs...)Calculates the firing rate of blox. If blox is a composite blox or a vector containing multiple elements, then the average firing rate across all neurons in blox is returned.
Keyword arguments:
- win_size : [ms] Sliding window size.
- overlap : in range [0,1]. Overlap between two consecutive sliding windows.
- transient : [ms] Transient period in the beginning of the timeseries that is ignored during firing rate calculation.
- threshold : [mV] Spiking threshold.
See also frplot.
NeurobloxBase.inter_spike_intervals — Function
inter_spike_intervals(blox::AbstractNeuron, sol; threshold, ts)Return the time intervals between subsequent spikes in the solution of a single neuron.
inter_spike_intervals(blox::AbstractNeuron, sol; threshold, ts)Return the time intervals between subsequent spikes in the solution of a Blox. Outputs a matrix whose rows are the interspike intervals for a single neuron.
NeurobloxBase.flat_inter_spike_intervals — Function
flat_inter_spike_intervals(blox::AbstractNeuron, sol; threshold, ts)Return the time intervals between subsequent spikes in the solution of a Blox. Concatenates the lists of interspike intervals of all vectors into a single vector.
NeurobloxBase.powerspectrum — Function
powerspectrum(cb::Union{AbstractComposite, Vector{AbstractNeuron}}, sol::AbstractSolution; sampling_rate=nothing, method=periodogram, window=nothing)Calculate the power spectrum of the voltage timeseries for all neurons and/or neural masses contained in blox.
See powerspectrumplot for more information on the keyword arguments.
NeurobloxBase.voltage_timeseries — Function
voltage_timeseries(cb::Union{AbstractComposite, Vector{Union{AbstractNeuron, AbstractNeuralMass}}, sol::AbstractSolution; ts)Return the voltage timeseries of all neurons and/or neural masses contained in blox. The output is a Matrix where each row is a separate neuron or neural mass and each column is a timepoint.
Keyword arguments:
- ts : [ms] Timepoints at which the voltage values are evaluated in simulation solution
sol. It can be a range, a vector or an individual timepoint. If no values are passed (andts=nothing) then the entire range of the solutionsolis used.
NeurobloxBase.meanfield_timeseries — Function
meanfield_timeseries(cb::Union{AbstractComposite, Vector{AbstractNeuron}, sol, state; ts)Return the average timeseries of state variable state over all neurons contained in cb.
Keyword arguments:
- ts : [ms] Timepoints at which the timeseries is evaluated in simulation solution
sol. It can be a range, a vector or an individual timepoint. If no values are passed (andts=nothing) then the entire range of the solutionsolis used.
Missing docstring for state_timeseriesg. Check Documenter's build log for details.
Parameter and Optimization Utilities
When fitting model parameters to experimental data or running optimization workflows, the following utilities build a ComponentVector from the current parameter and/or state-variable values of an ODEProblem and apply changes back without manually maintaining symbol-value lists.
NeurobloxBase.extract_vars — Function
extract_vars(prob, syms::AbstractVector{Symbol}) :: ComponentVectorBuild a nested ComponentVector from a problem, carrying the current values for the given symbols. syms may contain a mix of parameter and state-variable accesses, e.g.:
julia> using NeurobloxBasics
julia> @graph g begin
@nodes ho = HarmonicOscillator(;ω=23.0)
end
GraphSystem(...1 nodes and 0 connections...)
julia> prob = ODEProblem(g, [], (0.0, 1.0));
julia> v = extract_vars(prob, [ho.ω, ho.ζ, ho.x])
ComponentVector{Float64}(g = (ho = (ω = 23.0, ζ = 1.0, x = 1.0)))
julia> v.g.ho.ω # Namespaced indexing
23.0apply_vars is the 'inverse' of this operation, i.e. apply_vars(prob, v) will produce a new prob with new values for states and parameters corresponding to the entries of the ComponentVector.
NeurobloxBase.apply_vars — Function
apply_vars(prob, v::ComponentVector) :: ODEProblemRemake prob with updated values from v. The ComponentVector may contain a mix of parameter and state-variable entries; they are separated automatically and applied via remake(prob; p=..., u0=...). Inverse of extract_vars.
julia> using NeurobloxBasics
julia> @graph g begin
@nodes ho = HarmonicOscillator(;ω=23.0)
end
GraphSystem(...1 nodes and 0 connections...)
julia> prob = ODEProblem(g, [], (0.0, 1.0));
julia> v = extract_vars(prob, [ho.ω, ho.ζ, ho.x]);
julia> prob2 = apply_vars(prob, v);
julia> v.g.ho.x = 3.0 # update a state
3.0
julia> prob2 = apply_vars(prob, v); # produce a new problem object
julia> getsym(prob2, ho.x)(prob2) # the value of x is updated
3.0The original problem is left unchanged:
julia> getsym(prob, ho.x)(prob)
1.0