pub fn stacking_weights(lpd: &[Vec<f64>]) -> Result<Vec<f64>>Expand description
Stacking weights: the w on the simplex that maximizes
Σ_i log Σ_k w_k exp(lpd_ik), the log score of the mixture of the
models’ predictive distributions. lpd[k][i] is model k’s held-out
log density of observation i.
Unlike pseudo-BMA, stacking gives weight to a model that is worse on its own when it predicts well where the others do not, and drops models that add nothing (their weights are exactly 0). The objective is concave; it is solved by EM, then Newton’s method on the models kept, checked against the optimality conditions.
use prospicio_models::stack::stacking_weights;
// Model 0 predicts the first half well, model 1 the second half.
let a = [-0.1, -0.1, -3.0, -3.0];
let b = [-3.0, -3.0, -0.1, -0.1];
let w = stacking_weights(&[a.to_vec(), b.to_vec()]).unwrap();
assert!((w[0] - 0.5).abs() < 1e-9 && (w[1] - 0.5).abs() < 1e-9);