In class-incremental learning the classifier head grows as classes arrive, and after training on a new task the new classes' logits dominate because they were trained against each other on fresh data while old classes only appeared through replay. Bias Correction (BiC) fixes the imbalance with two scalars fitted on a small balanced validation set. Implement the head expansion and the correction.
expand_head(W, b, n_new)
W is (d, C), b is (C,). Return (W_new, b_new) of shapes (d, C + n_new) and (C + n_new,) with the old columns copied and the new ones zero. Inputs must not be modified.bic_apply(logits, n_old, alpha, beta)
logits is (N, C). Return a copy where the columns from n_old onward are replaced by alpha * logit + beta; the first n_old columns are unchanged.bic_fit(logits_val, y_val, n_old, alphas, betas)
(alpha, beta) pair in the Cartesian product (outer loop over alphas, inner over betas), compute the mean softmax cross-entropy of bic_apply(logits_val, n_old, alpha, beta) against y_val, and return (alpha, beta, loss) for the first pair achieving the minimum loss (strict < comparison), with the loss rounded to 6 decimals.new_class_prediction_rate(logits, n_old)
>= n_old) as a Python float.bic_apply must not touch its input; make a copy before scaling the new-class block.