skills/cv/snapshot-cosine-ensemble/SKILL.md
Cyclic cosine annealing LR that produces M diverse snapshots from a single training run for free ensembling
npx skillsauth add wenmin-wu/ds-skills cv-snapshot-cosine-ensembleInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Snapshot ensembling runs cosine LR cycles during a single training pass. Each cycle converges to a different minimum, giving M diverse models for the cost of training one. Combined with SWA or simple prediction averaging, this provides cheap ensemble diversity without M training runs.
import numpy as np
from keras.callbacks import LearningRateScheduler, ModelCheckpoint
class SnapshotCallbackBuilder:
def __init__(self, nb_epochs, nb_snapshots, init_lr=0.1):
self.T = nb_epochs
self.M = nb_snapshots
self.alpha_zero = init_lr
def _cosine_anneal(self, epoch):
cos_inner = np.pi * (epoch % (self.T // self.M)) / (self.T // self.M)
return float(self.alpha_zero / 2 * (np.cos(cos_inner) + 1))
def get_callbacks(self, model_prefix='snap'):
return [
ModelCheckpoint(f'{model_prefix}_best.h5', monitor='val_loss',
save_best_only=True),
LearningRateScheduler(self._cosine_anneal),
]
# Usage: 50 epochs, 5 snapshots, init_lr=1e-3
builder = SnapshotCallbackBuilder(nb_epochs=50, nb_snapshots=5, init_lr=1e-3)
model.fit(..., epochs=50, callbacks=builder.get_callbacks('run1'))
init_lr at cycle startdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF