## gallery.stack()


Fit stacking weights on one panel, build stacked forecasts at a later one.


Usage

``` python
gallery.stack(
    weights_panel,
    evaluation,
    *,
    method="mle",
    seed=None,
)
```


`weights_panel` is the ALIGNED earlier panel (its `pointwise` frame is the fitting data); `evaluation` is the later cutoff's forecasts as the raw [CohortForecast](gallery.CohortForecast.md#ibnr.gallery.CohortForecast) objects - a `ForecastPanel` will not do here, because the stacked pseudo-model is built from the members' `(n_draws, n_cells)` arrays and a panel only retains their reductions.

Refused, each with the reason it must be:

- `weights_panel.as_of >= evaluation as_of` - weights graded on the cells that chose them measure selection, not skill;
- mixed [as_of](Triangle.as_of.md#ibnr.Triangle.as_of)/`task`/segment schema/measure among the evaluation forecasts, and any disagreement of those with the weights panel. What is checked WHERE: those four panel-identity checks happen here; `apply_weights()` checks per-cohort member agreement (task, field, cell keys, observed values, `eval_date`, `train_origins`); the remaining panel checks - premium agreement, the upstream exclusion censuses, cross-cohort duplicates - happen when the stacked forecasts are aligned WITH their members, which is the only supported way to score them;
- a member-set mismatch: the models offering a density at evaluation must be EXACTLY the weight panel's ELPD members. A weight vector fitted over one member set cannot be applied to another silently - a missing member leaves its weight stranded, an extra one has no weight at all. Evaluation forecasts from draws-only models are ignored (they are not in the stack; see the module docstring);
- fewer than two ELPD members - there is nothing to weight;
- an `mle` solve whose scipy result reports `success = False` (`RuntimeError`, carrying scipy's status and message): bayesblend returns the vector SLSQP stopped at rather than raising, and that vector passes every check on the weights themselves.

`seed` reaches the fitters that take one (`pseudo_bma`, `bayes`, `hierarchical`); `mle` is deterministic and ignores it.
