rheon.spec.coef_index

rheon.spec.coef_index(spec: dict[str, Any]) → _Frame[source]

List the layout of a spec’s coef lists, one row per position.

Use it to find which position of a coef list holds a coefficient. Every instance’s list has this layout. coef_fields() is the same table for each instance, with the field each list sits in and the column each entry unnests to.

Parameters

spec

A spec, as a builder of rheon.spec returns it.

Returns

A frame with one row per position. coef is flat: for each target and grid point in turn, its terms in order. The frame maps position to target, the grid point’s ridge, feature_set and penalty, and term: "intercept", a feature name, or "level" or "trend" for holt().

  • For kmeans() the entries are the centers, so cluster reads 0, 1, and so on, and term is the feature whose coordinate the position holds.

  • For hmm() an entry is a state, in state, and for ew_class() a class, in class.

  • For deco() an entry is rho, or a block or a pair of blocks, in target, and term reads "rho".

It is empty, with the same columns, for a spec with no fixed layout to index, as coef_fields() is:

  • ew_cov, which has no coefficients;

  • seqtest, which reports evidence;

  • micro, whose coef has as many entries as there are established summaries;

  • marginal, rcov, corrchange, bocpd and audit, which report none.

Raises

ValueError

spec is not a valid spec, as for output_fields().

Examples

This code reads df from Example data:

grid = rp.spec.ewridge(
    "m", targets=["y"], features=["x0", "x1"], half_life=[100.0, 500.0], ridge=[1e-6, 0.5]
)
out = rp.ModelBank([grid]).fit_predict(df)    # a half-life grid by a ridge grid
ci = rp.spec.coef_index(grid)
pos = ci.filter(
    (pl.col("target") == "y") & (pl.col("ridge") == 0.5) & (pl.col("term") == "x1")
)["position"].item()
slope = out["m"].struct.field("coef@h100").list.get(pos)
print(ci.height, pos)
6 5

See also

  • coef_fields(), the same for each instance, with each entry’s column name.

  • output_index(), every field with the values its name encodes.