Fitting¶
btorch.fitting
¶
Model-driven fitting and tuning utilities.
Unlike :mod:btorch.analysis (post-hoc statistics of recorded activity), the
tools here simulate :mod:btorch.models networks and optimise their parameters.
- :mod:
.tuning: constant-current f-I / V-I sweeps of a neuron class. - :mod:
.two_compartment: Allen-data fitting of the two-compartment GLIF neuron.
btorch.fitting.tuning
¶
Functions:¶
compute_fi_vi_curve(neuron_cls, neuron_params, current_start=0.0, current_end=20.0, steps=20, duration=1000, dt=1.0, device='cpu')
¶
Simulate a constant-current sweep and return the f-I and V-I curves.
Builds the neuron, wraps it in an RNN and runs it once with all currents as a batch (this is a simulation, not a lookup).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
neuron_cls
|
type[Module]
|
The neuron class to instantiate. |
required |
neuron_params
|
Mapping[str, Any]
|
Dictionary of parameters for the neuron. |
required |
current_start
|
float
|
Starting current value for sweep. |
0.0
|
current_end
|
float
|
Ending current value for sweep. |
20.0
|
steps
|
int
|
Number of currents to sweep. |
20
|
duration
|
float
|
Duration of simulation in ms. |
1000
|
dt
|
float
|
Time step in ms. |
1.0
|
device
|
str | device
|
Device to run on. |
'cpu'
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
A dictionary containing: - currents: Tensor of shape (steps,) - frequencies: Firing rate in Hz, shape (steps, n_neuron) - voltages: Tensor of shape (time_steps, steps, n_neuron) - time: Time axis in ms, shape (time_steps,) |
Source code in btorch/fitting/tuning.py
init_net_state(net, batch_size=None, **kwargs)
¶
Initialize state for all MemoryModule instances in a network.
Walks through every Module in net and calls init_state()
if it is a base.MemoryModule or has an init_state method.
Also moves the network to the device/dtype specified in kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Module
|
Network to initialize. |
required |
batch_size
|
int | Sequence[int] | None
|
Batch size(s) for state initialization. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Example
functional.init_net_state(model, batch_size=4, device="cuda")
Source code in btorch/models/functional.py
make_rnn(obj=None, allow_buffer=False, **rnn_kwargs)
¶
make_rnn(
obj: type[base.MemoryModule],
allow_buffer: bool = False,
**rnn_kwargs,
) -> type[RecurrentNNAbstract]
RNN wrapper.
Source code in btorch/models/rnn.py
btorch.fitting.two_compartment
¶
Allen-data fitting utilities for the two-compartment GLIF neuron.
Layout:
- :mod:
.data: Allen sweep loading, resampling and cell selection. - :mod:
.loss: :class:FitLossConfigand the voltage/spike loss terms. - :mod:
.evaluation: rollout and per-sweep evaluation. - :mod:
.report: fit report writer (JSON + figures). - :mod:
.fit: the staged / global / TBPTT fitting strategies.
Attributes¶
DEFAULT_TWO_COMPARTMENT_FIT_STAGES = (TwoCompartmentFitStage(name='passive', trainable_params=(frozenset({'E_L', 'tau_s'})), sweep_kind='silent', voltage_weight=1.0, spike_weight=0.0, spike_count_weight=10.0, spike_timing_weight=0.0, spike_count_over_weight=8.0, spike_count_under_weight=1.0, sparsity_weight=0.0, param_bounds={'E_L': (-82.0, -65.0), 'tau_s': (8.0, 60.0)}), TwoCompartmentFitStage(name='threshold_reset', trainable_params=(frozenset({'tau_s', 'E_L', 'R_s', 'v_threshold', 'v_reset', 'delta_T'})), sweep_kind='countcal', voltage_weight=0.02, spike_weight=1.0, spike_count_weight=50.0, spike_timing_weight=12.0, spike_count_over_weight=2.0, spike_count_under_weight=5.0, sparsity_weight=0.0, param_bounds={'tau_s': (6.0, 40.0), 'E_L': (-78.0, -66.0), 'R_s': (0.04, 0.35), 'v_threshold': (-50.0, -42.0), 'v_reset': (-78.0, -58.0), 'delta_T': (0.0, 12.0)}), TwoCompartmentFitStage(name='spike_init', trainable_params=(frozenset({'tau_s', 'E_L', 'R_s', 'v_threshold', 'delta_T'})), sweep_kind='spiking', voltage_weight=0.01, spike_weight=1.0, spike_count_weight=60.0, spike_timing_weight=15.0, spike_count_over_weight=2.0, spike_count_under_weight=6.0, sparsity_weight=0.0, param_bounds={'tau_s': (5.0, 35.0), 'E_L': (-78.0, -64.0), 'R_s': (0.05, 0.4), 'v_threshold': (-52.0, -40.0), 'delta_T': (0.5, 15.0)}), TwoCompartmentFitStage(name='adaptation', trainable_params=(frozenset({'tau_a', 'tau_th', 'delta_th'})), sweep_kind='spiking', voltage_weight=0.05, spike_weight=1.0, spike_count_weight=35.0, spike_timing_weight=10.0, spike_count_over_weight=2.0, spike_count_under_weight=4.0, sparsity_weight=0.0, param_bounds={'tau_a': (20.0, 250.0), 'tau_th': (5.0, 250.0), 'delta_th': (0.0, 15.0)}), TwoCompartmentFitStage(name='coupling', trainable_params=(frozenset({'w_Ca', 'theta_Ca', 'w_sa', 'w_as'})), sweep_kind='all', voltage_weight=0.02, spike_weight=1.0, spike_count_weight=25.0, spike_timing_weight=10.0, spike_count_over_weight=3.0, spike_count_under_weight=2.0, sparsity_weight=0.002, param_bounds={'w_Ca': (0.0, 1.0), 'theta_Ca': (0.0, 8.0), 'w_sa': (0.0, 1.2), 'w_as': (0.0, 1.2)}))
module-attribute
¶
DEFAULT_TWO_COMPARTMENT_PARAM_BOUNDS = {'tau_s': (5.0, 80.0), 'R_s': (0.01, 0.5), 'E_L': (-85.0, -55.0), 'tau_a': (20.0, 400.0), 'tau_th': (5.0, 400.0), 'delta_th': (0.0, 20.0), 'delta_T': (0.0, 10.0), 'w_Ca': (0.0, 3.0), 'theta_Ca': (-5.0, 15.0), 'w_sa': (0.0, 3.0), 'w_as': (0.0, 3.0), 'v_threshold': (-55.0, -35.0), 'v_reset': (-80.0, -50.0)}
module-attribute
¶
SweepKind = Literal['all', 'silent', 'lowrate', 'spiking', 'countcal']
module-attribute
¶
__all__ = ['AllenSweepBatch', 'DEFAULT_TWO_COMPARTMENT_PARAM_BOUNDS', 'DEFAULT_TWO_COMPARTMENT_FIT_STAGES', 'FitEvaluation', 'FitLossConfig', 'GlobalSearchConfig', 'StagedConfig', 'TbpttConfig', 'TwoCompartmentFitStage', 'TwoCompartmentModel', 'choose_current_clamp_sweeps', 'detect_spikes_from_voltage', 'evaluate_fit_across_sweeps', 'evaluate_two_compartment_fit', 'exponential_filter_spike_train', 'filter_mouse_visp_l5_pyramidal_cells', 'fit_two_compartment_model', 'get_cell_types_cache', 'load_allen_sweep', 'mask_post_spike_voltage_samples', 'plot_two_compartment_fit', 'query_mouse_visp_l5_pyramidal_cells', 'resample_trace', 'rollout_two_compartment', 'save_fit_report', 'spike_timing_loss', 'spike_timing_stats', 'two_compartment_loss']
module-attribute
¶
Classes¶
AllenSweepBatch
dataclass
¶
Preprocessed Allen sweep tensors for fitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specimen_id
|
int
|
Allen specimen identifier. |
required |
sweep_number
|
int
|
Sweep number within the NWB file. |
required |
dt
|
float
|
Simulation timestep in milliseconds. |
required |
i_soma
|
Tensor
|
Somatic current tensor shaped |
required |
v_true
|
Tensor
|
Recorded voltage tensor shaped |
required |
spike_true
|
Tensor
|
Binary spike tensor shaped |
required |
i_apical
|
Tensor | None
|
Optional apical input tensor shaped |
None
|
metadata
|
dict[str, Any] | None
|
Auxiliary Allen metadata retained for bookkeeping. |
None
|
Source code in btorch/fitting/two_compartment/data.py
FitEvaluation
dataclass
¶
Evaluation artifacts for a fitted model on one sweep.
Source code in btorch/fitting/two_compartment/evaluation.py
FitLossConfig
dataclass
¶
Loss weights and spike-matching settings for the two-compartment fit.
This is the single public way to configure the loss: pass one instance as
loss= to :func:two_compartment_loss,
:func:evaluate_two_compartment_fit, :func:evaluate_fit_across_sweeps
and :func:fit_two_compartment_model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage_weight
|
float
|
Weight of the masked voltage reconstruction loss. |
1.0
|
spike_weight
|
float
|
Weight of the smoothed spike-train loss. |
1.0
|
spike_count_weight
|
float
|
Weight of the spike-count matching penalty. |
0.0
|
spike_timing_weight
|
float
|
Weight of the hard spike-timing event loss. |
0.0
|
spike_count_over_weight
|
float
|
Weight of over-prediction in the count loss (must be positive). |
1.0
|
spike_count_under_weight
|
float
|
Weight of under-prediction in the count loss (must be positive). |
1.0
|
sparsity_weight
|
float
|
Weight of the |
0.0001
|
spike_tau_ms
|
float
|
Smoothing constant (ms) of the spike-train loss. |
10.0
|
post_spike_mask_ms
|
float
|
Duration (ms) of the post-spike voltage mask. |
3.0
|
spike_match_window_ms
|
float
|
Tolerance window (ms) for matching predicted and true spikes. |
10.0
|
spike_miss_penalty_ms
|
float | None
|
Per-event penalty (ms) assigned to unmatched spikes in the hard timing loss. Defaults to the match window. |
None
|
Source code in btorch/fitting/two_compartment/loss.py
GlobalSearchConfig
dataclass
¶
Options of the bounded global search ("global", "hybrid" and
every stage of "staged").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_bounds
|
dict[str, tuple[float, float]] | None
|
Per-parameter |
None
|
maxiter
|
int
|
Differential-evolution outer iterations. |
20
|
popsize
|
int
|
Differential-evolution population size multiplier. |
8
|
local_maxiter
|
int
|
Maximum L-BFGS-B iterations of the polish step. |
50
|
seed
|
int | None
|
Random seed ( |
0
|
polish
|
bool
|
Run L-BFGS-B after the global search. |
True
|
Source code in btorch/fitting/two_compartment/fit.py
StagedConfig
dataclass
¶
Options of the staged back-end (method="staged").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stages
|
Sequence[TwoCompartmentFitStage] | None
|
Stage definitions; |
None
|
Source code in btorch/fitting/two_compartment/fit.py
TbpttConfig
dataclass
¶
Options of the truncated-BPTT back-end
(method="tbptt"/"hybrid").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lr
|
float
|
Adam learning rate. |
0.001
|
epochs
|
int
|
Passes over the sweeps. |
10
|
chunk_size
|
int
|
Truncated-BPTT chunk length in time steps; the hidden state carries over between chunks while the graph is detached. |
500
|
Source code in btorch/fitting/two_compartment/fit.py
TwoCompartmentFitStage
dataclass
¶
Configuration for one stage of staged parameter fitting.
Source code in btorch/fitting/two_compartment/fit.py
TwoCompartmentModel
¶
Bases: Protocol
What the fitting and evaluation code needs from a neuron model.
:class:~btorch.models.neurons.two_compartment.TwoCompartmentGLIF
satisfies it. Besides the members below, the model must be a
:class:torch.nn.Module that works with
:func:btorch.models.functional.init_net_state and reset_net (hidden
state buffers), and its fitted parameters are those with
requires_grad=True (names must have bounds, see
DEFAULT_TWO_COMPARTMENT_PARAM_BOUNDS).
Attributes:
| Name | Type | Description |
|---|---|---|
w_Ca |
Tensor
|
Calcium-coupling weights; their mean absolute value is the sparsity penalty of the loss. |
Source code in btorch/fitting/two_compartment/evaluation.py
Methods:¶
multi_step_forward(i_soma_seq, i_apical_seq=None, *, return_state=False)
¶
Run (T, *batch, n_neuron) inputs and return (spike, v,
state) where state holds v_pre_spike, i_a and i_bap
(called with return_state=True).
Source code in btorch/fitting/two_compartment/evaluation.py
Functions:¶
_fit_sweeps_once(model, sweeps, *, device=None, dtype=torch.float32, loss)
¶
Evaluate the current model parameters on one or more sweeps.
Returns the per-sweep loss terms (see :func:_loss_floats) averaged over
sweeps.
Source code in btorch/fitting/two_compartment/fit.py
_fit_two_compartment_model_global(model, sweeps, *, config, device=None, dtype=torch.float32, loss)
¶
Fit with bounded global search and optional local L-BFGS-B polish.
Source code in btorch/fitting/two_compartment/fit.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
_loss_floats(losses)
¶
Convert a :func:two_compartment_loss result to float history entries.
Keys are "<component>_loss" for every loss term, e.g. "total_loss"
and "spike_count_loss".
Source code in btorch/fitting/two_compartment/loss.py
_prepare_sweep(model, sweep, *, device, dtype, init_state=True)
¶
Move a sweep to device/dtype and reset the model for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TwoCompartmentModel
|
Model whose state is (re)initialised for the sweep batch size. |
required |
sweep
|
AllenSweepBatch
|
Sweep to convert. |
required |
device
|
str | device | None
|
Target device. |
required |
dtype
|
dtype
|
Target dtype. |
required |
init_state
|
bool
|
Also call |
True
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor, Tensor, Tensor | None]
|
|
Source code in btorch/fitting/two_compartment/evaluation.py
choose_current_clamp_sweeps(sweep_records, *, preferred_stimuli=('long square',))
¶
Select current-clamp sweeps appropriate for somatic fitting.
Source code in btorch/fitting/two_compartment/data.py
detect_spikes_from_voltage(voltage, *, threshold=0.0)
¶
Detect upward threshold crossings in a voltage trace.
Source code in btorch/fitting/two_compartment/data.py
evaluate_fit_across_sweeps(model, sweeps, *, device=None, dtype=torch.float32, loss=None)
¶
Evaluate a fitted model on multiple sweeps and aggregate metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TwoCompartmentModel
|
Fitted two-compartment neuron. |
required |
sweeps
|
Iterable[AllenSweepBatch]
|
Sweeps to evaluate; at least one is required. |
required |
device
|
str | device | None
|
Torch device; defaults to the model's device. |
None
|
dtype
|
dtype
|
Torch dtype used for the rollouts. |
float32
|
loss
|
FitLossConfig | None
|
Loss weights and spike-matching settings (defaults to
:class: |
None
|
Returns:
| Type | Description |
|---|---|
list[FitEvaluation]
|
Per-sweep evaluations and the aggregate ( |
dict[str, float]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in btorch/fitting/two_compartment/evaluation.py
evaluate_two_compartment_fit(model, sweep, *, device=None, dtype=torch.float32, loss=None)
¶
Evaluate a fitted model on a single sweep and collect metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TwoCompartmentModel
|
Fitted two-compartment neuron. |
required |
sweep
|
AllenSweepBatch
|
Sweep to roll the model out on. |
required |
device
|
str | device | None
|
Torch device; defaults to the model's device. |
None
|
dtype
|
dtype
|
Torch dtype used for the rollout. |
float32
|
loss
|
FitLossConfig | None
|
Loss weights and spike-matching settings (defaults to
:class: |
None
|
Source code in btorch/fitting/two_compartment/evaluation.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
exponential_filter_spike_train(spike_train, *, tau_ms, dt)
¶
Apply a causal exponential filter to a spike train.
Source code in btorch/fitting/two_compartment/loss.py
filter_mouse_visp_l5_pyramidal_cells(cells)
¶
Filter Allen cell metadata to mouse VISp layer-5 pyramidal candidates.
Notes
Allen metadata can vary across cache versions, so this filter accepts a
few equivalent key names and uses spiny as a practical proxy for
pyramidal morphology when an explicit class label is unavailable.
Source code in btorch/fitting/two_compartment/data.py
fit_two_compartment_model(model, sweeps, *, method='hybrid', device=None, dtype=torch.float32, loss=None, tbptt=None, search=None, staged=None)
¶
Fit the model with a robust strategy for poor initialization.
Each back-end receives exactly its own option object; None selects its
defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TwoCompartmentModel
|
Two-compartment neuron to fit (see
:class: |
required |
sweeps
|
Iterable[AllenSweepBatch]
|
Allen or synthetic sweeps to fit against. |
required |
method
|
Literal['hybrid', 'global', 'tbptt', 'staged']
|
|
'hybrid'
|
device
|
str | device | None
|
Torch device for evaluation and refinement. |
None
|
dtype
|
dtype
|
Torch dtype used during fitting. |
float32
|
loss
|
FitLossConfig | None
|
Loss weights and spike-matching settings; |
None
|
tbptt
|
TbpttConfig | None
|
:class: |
None
|
search
|
GlobalSearchConfig | None
|
:class: |
None
|
staged
|
StagedConfig | None
|
:class: |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, float | str]]
|
A history list with one row per fitting stage or TBPTT chunk. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an option object is passed that |
Notes
The default "hybrid" method is intended for real fitting runs where
the starting parameters may be far from the biological regime. Global
search handles the large basin-finding problem more robustly than pure
BPTT, while the optional TBPTT stage can still fine-tune the result.
Source code in btorch/fitting/two_compartment/fit.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
get_cell_types_cache(manifest_file=None, *, cache=None)
¶
Create or reuse an AllenSDK CellTypesCache instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest_file
|
str | Path | None
|
Path of the cache manifest; |
None
|
cache
|
CellTypesCache | None
|
An existing cache, returned unchanged. |
None
|
Returns:
| Type | Description |
|---|---|
CellTypesCache
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If AllenSDK is not installed and no |
Source code in btorch/fitting/two_compartment/data.py
load_allen_sweep(specimen_id, sweep_number, *, dt=0.5, manifest_file=None, cache=None, voltage_spike_threshold=0.0, voltage_scale=1000.0, current_scale=1000000000000.0)
¶
Load one Allen ephys sweep and convert it to time-first torch tensors.
Notes
AllenSDK current-clamp sweeps are typically returned in SI units (volts and amps). The two-compartment neuron parameters in this module use biologically familiar millivolt-scale voltages and pA-scale input magnitudes, so the default conversion is volts -> mV and amps -> pA.
Source code in btorch/fitting/two_compartment/data.py
mask_post_spike_voltage_samples(spike_true, *, refractory_bins=3)
¶
Mask out voltage samples immediately after true spikes.
Source code in btorch/fitting/two_compartment/loss.py
plot_two_compartment_fit(evaluation, history=None, *, output_path)
¶
Create a compact fit-quality figure with traces and loss history.
Source code in btorch/fitting/two_compartment/_plots.py
query_mouse_visp_l5_pyramidal_cells(*, manifest_file=None, cache=None)
¶
Query candidate mouse VISp layer-5 pyramidal cells from AllenSDK.
Source code in btorch/fitting/two_compartment/data.py
resample_trace(trace, *, source_dt, target_dt)
¶
Resample a 1D trace to a new timestep using linear interpolation.
Source code in btorch/fitting/two_compartment/data.py
rollout_two_compartment(model, i_soma, i_apical=None)
¶
Run a time-first rollout and collect fitting-relevant traces.
Source code in btorch/fitting/two_compartment/evaluation.py
save_fit_report(model, evaluations, aggregate_metrics, history, *, output_dir)
¶
Save fitted parameters, metrics, history, and plots to disk.
Writes fitted_parameters.json (every named parameter, flattened),
fit_metrics.json (aggregate plus per_sweep entries),
fit_history.json and one PNG per evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Fitted model; its |
required |
evaluations
|
Sequence[FitEvaluation]
|
Per-sweep evaluations to plot and record. |
required |
aggregate_metrics
|
dict[str, float]
|
Metrics averaged over sweeps. |
required |
history
|
Sequence[dict[str, float | str]]
|
Rows returned by |
required |
output_dir
|
str | Path
|
Directory (created if missing). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
Dict with |
dict[str, Path]
|
(JSON paths), |
dict[str, Path]
|
|
dict[str, Path]
|
last figure). Both plot entries fall back to |
dict[str, Path]
|
|
Source code in btorch/fitting/two_compartment/report.py
spike_timing_loss(spike_true, spike_pred, *, dt, match_window_ms=10.0, miss_penalty_ms=None)
¶
Compute a hard event-based spike-timing loss for global optimization.
Source code in btorch/fitting/two_compartment/loss.py
spike_timing_stats(spike_true, spike_pred, *, dt, match_window_ms=10.0)
¶
Match predicted and true spikes using a tolerance-window cost.
Source code in btorch/fitting/two_compartment/loss.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
two_compartment_loss(*, v_pred, spike_pred, v_true, spike_true, dt, w_Ca=None, loss=None)
¶
Compute a composite fitting loss for the two-compartment model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v_pred
|
Tensor
|
Predicted voltage, shape |
required |
spike_pred
|
Tensor
|
Predicted spikes, shape |
required |
v_true
|
Tensor
|
Recorded voltage, same shape as |
required |
spike_true
|
Tensor
|
Recorded spikes, same shape as |
required |
dt
|
float
|
Simulation step in ms. |
required |
w_Ca
|
Tensor | None
|
Optional calcium-coupling weights for the sparsity penalty. |
None
|
loss
|
FitLossConfig | None
|
Loss weights and spike-matching settings. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dict with the weighted |
dict[str, Tensor]
|
|
dict[str, Tensor]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spike-count over/under weights are not positive. |
Source code in btorch/fitting/two_compartment/loss.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |