Skip to main content

Import

thx_train.rate_loss

Cross-entropy loss over spike counts (rate coding). The canonical loss function for THRINDEX classifiers.
Parameters Behavior Computes spike counts per neuron (sum over T), then applies standard cross-entropy:
This is equivalent to treating spike counts as unnormalized logits. The model’s output neurons compete to spike the most — the one that wins is the prediction. Usage

thx_train.reconstruction_loss

Mean squared error between output and input spike rasters. The loss function for autoencoder training.
Equivalent to torch.nn.functional.mse_loss(output, target, reduction=reduction), provided here for consistency.

thx_train.accuracy

Computes classification accuracy from a spike raster.
Returns the fraction of samples where the argmax of spike counts matches the target label. Usage

thx_train.SpikeRegularizer

A regularization term that penalizes high or low firing rates, preventing silent or saturated networks.
Parameters Behavior Penalizes the squared deviation of each neuron’s mean firing rate from target_rate:
where rate[b, n] = mean_t(spikes[b, t, n]). Typical values: target_rate=0.05 (5% activity) with weight=1e-3. Increase weight if the network develops dead neurons or saturates.

thx_train.DelayOptimizer

An optimizer wrapper that handles integer delay learning via a straight-through gradient estimator.
Parameters Notes Delays are integers. The DelayOptimizer maintains a continuous surrogate for each delay, updates the surrogate with the straight-through gradient from the backward pass, and rounds to the nearest integer every delay_update_every steps. Delays are clamped to [1, max_delay] after each update.