Import
thx_train.rate_loss
Cross-entropy loss over spike counts (rate coding). The canonical loss function for THRINDEX classifiers.
Behavior
Computes spike counts per neuron (sum over T), then applies standard cross-entropy:
thx_train.reconstruction_loss
Mean squared error between output and input spike rasters. The loss function for autoencoder training.torch.nn.functional.mse_loss(output, target, reduction=reduction), provided here for consistency.
thx_train.accuracy
Computes classification accuracy from a spike raster.thx_train.SpikeRegularizer
A regularization term that penalizes high or low firing rates, preventing silent or saturated networks.
Behavior
Penalizes the squared deviation of each neuron’s mean firing rate from
target_rate:
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.
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.