romtools.workflows.inverse.vi.gains#

Cross-fitted ACV gains from cached score/weight moments.

Functions

append_training_batch(batches, batch, limit)

Trim accepted samples to the same count limit used for ROM training.

fit_history_gain(high_weights, low_weights, ...)

Weighted covariance fit; probabilities enter moments once, not twice.

gain_folds(n[, num_folds])

Balanced, value-independent folds; None selects singleton LOO folds.

gaussian_history_kernels(data)

Mean/log-std gradient and Hessian kernels at the current target distribution.

history_weights(data, scale[, entropy_strategy])

importance_weights(samples, target_mean, ...)

Balance-mixture MIS weights; normalize in log space without clipping.

k_fold_acv_estimator(*args[, gain_num_folds])

Fit gains on complementary paired folds, with inner LOO baselines.

loo_acv_estimator(high_weights, low_weights, ...)

Cross-fit stable ACV gains with a fold-only extreme-coefficient guard.

normalize_strategy(value, name, choices)

regularized_matrix_gain(variance, cross[, ...])

Solve the ridge fit on the covariance range, excluding numerical nulls.

sample_ids(directory, count)

validate_gain_num_folds(value)

validate_gain_sampling(gain_strategy, ...)

romtools.workflows.inverse.vi.gains.append_training_batch(batches, batch, limit)[source]#

Trim accepted samples to the same count limit used for ROM training.

romtools.workflows.inverse.vi.gains.fit_history_gain(high_weights, low_weights, scores, baseline_method, mode, sample_weights=None)[source]#

Weighted covariance fit; probabilities enter moments once, not twice.

romtools.workflows.inverse.vi.gains.gain_folds(n, num_folds=None)[source]#

Balanced, value-independent folds; None selects singleton LOO folds.

romtools.workflows.inverse.vi.gains.gaussian_history_kernels(data)[source]#

Mean/log-std gradient and Hessian kernels at the current target distribution.

romtools.workflows.inverse.vi.gains.importance_weights(samples, target_mean, target_std, target_correlation, batches)[source]#

Balance-mixture MIS weights; normalize in log space without clipping.

romtools.workflows.inverse.vi.gains.k_fold_acv_estimator(*args, gain_num_folds=5, **kwargs)[source]#

Fit gains on complementary paired folds, with inner LOO baselines.

romtools.workflows.inverse.vi.gains.loo_acv_estimator(high_weights, low_weights, extra_weights, scores, extra_scores, baseline_method, mode, *, force_unit_gain=False, high_reference_terms=None, epsilon=1e-12, gain_regularization=1.0, return_baselines=False, fixed_gain=None, num_folds=None)[source]#

Cross-fit stable ACV gains with a fold-only extreme-coefficient guard.

num_folds=None uses singleton LOO folds; otherwise use balanced contiguous k-fold partitions. Prefix/suffix covariance merges exclude the held-out fold without unstable scatter downdates. Weight offsets are removed before multiplication by scores. The fold containing the reference row is computed separately with a reference from its own fitting set. Moment work remains O(n*p**2); matrix solves are performed once per fold.

Ordinary gains are not shrunk toward a preset coefficient. To guard against tiny fitting variances, positive gain_regularization limits scalar/componentwise magnitudes and matrix spectral norms to 1 + sqrt(training_count/gain_regularization)/2. The limit grows with sample count; zero disables it. All coefficient decisions exclude the held-out fold and LF-only samples. Matrix coefficients use delta_L @ A.

romtools.workflows.inverse.vi.gains.regularized_matrix_gain(variance, cross, epsilon=1e-12, max_rank=None, noise_floor=0.0)[source]#

Solve the ridge fit on the covariance range, excluding numerical nulls.