PineForge HPO 1.11.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
pineforge_hpo.walkforward Namespace Reference

Classes

class  WalkforwardError
 

Functions

dict walkforward (Any windows, Any sources, *str metric, str direction, Any space=None, int|None max_work=None)
 

Variables

str CONTRACT = "pineforge-hpo-walkforward/v1"
 
str ALGORITHM = "exact_per_window_v1"
 
tuple DIRECTIONS = ("maximize", "minimize")
 
tuple CODES
 
tuple INTERPRETATION
 

Detailed Description

Post hoc walk-forward analysis of finished per-window studies.

``walkforward(windows, sources, *, metric, direction, space=None, max_work=None)``
reads the caller's ordered plan and one finished study per supplied window. It runs
no window, evaluates nothing, writes no file, keeps no state and changes no native
result. v1 analyses finished studies; native in-loop walk-forward comes later.

Contract ``pineforge-hpo-walkforward/v1``, algorithm ``exact_per_window_v1``:

Only ``ok`` rows with finite metric cells compete. Other statuses are excluded as
``status_<status>``, absent cells as ``metric_not_recorded`` and null cells as
``metric_unavailable``, in that order. An invalid cell on an ok row, or a non-finite
or JSON-unwritable cell on any row, or an integer too large for binary64 on any
row, refuses the call. Numeric cells are binary64;
booleans are not numbers. The metric is ``objective`` or an exact recorded name.

Selection minimises ``(sign * value, trial_id)``, with sign -1.0 for maximize and
+1.0 for minimize. A supplied window with no eligible row has no selection; none
anywhere refuses. Missing sources appear in ``never_run`` in plan order. Gaps
between consecutive supplied windows appear in ``chain_breaks``.

For adjacent supplied windows whose first has a selection, its exact parameter
key is looked up in the target's rows. Every such pair appears, including a target
without eligible rows. Eligible matches must have one value; unequal values refuse,
otherwise the lowest id is reported with ``row_found`` true. Its mid-rank is
``better + (equal + 1) / 2`` among target eligible rows. Without an eligible match,
``row_found`` is false, numeric fields are null, and the reason is that of the
lowest-id matching row, or ``no_row``. When ``row_found`` is true, parameters belong
to the matching row; when false, they are the source window's selected parameters
(the vector looked up). No value is inferred.

Stability lists selected parameters as recorded, in plan order, with distinct
typed-scalar counts and exact numeric minimum and maximum for both integer and real
dimensions, keeping the first recorded value on equality. Boolean and categorical
extremes are null. Real identity equates integer and real spellings and signed zeros.
There is no tolerance, averaging, interpolation, threshold or robustness verdict.

The shared reader checks each supplied study and its context separately. Recorded
spaces and row space hashes must agree across windows; bar and timeframe counters
are compared only inside a window. Top-level result hashes are not compared. For
objective, the recorded common space's direction is checked first, then source
directions; a passed space's direction is not compared.
Hash-mismatch ``ids`` ascend: one id per differing row, so an id that occurs in
several windows is listed once for each.

Refusals raise ``WalkforwardError`` with its refused ``document()``. The first
defect decides: missing options before invalid options; unknown labels; no source;
reading and each window's context; recorded spaces then row hashes; direction;
metric name; cells; every row's parameters; carried duplicates; no eligible row;
admission figure. The figure is rows read + sum e(e-1)/2 + sum target eligible
counts over carry-over pairs, bounded only by a caller-supplied ``max_work``.

The document and digest ignore row and mapping insertion order. The digest is
SHA-256 of sorted raw per-row SHA-256 digests of compact, key-sorted ASCII JSON
``[window label, trial_id, status, cell]``. It covers every status, normalises numeric
cells to binary64, writes absent/null as null, and preserves other JSON cells on
excluded rows. It omits metric name, direction and plan position. Listings follow
the plan, dimensions follow code-point name order, exclusion status reasons precede the
missing and null metric reasons, and ids ascend. ``interpretation`` is fixed.

Function Documentation

◆ walkforward()

dict pineforge_hpo.walkforward.walkforward ( Any  windows,
Any  sources,
*str  metric,
str  direction,
Any   space = None,
int | None   max_work = None 
)
Summarise finished studies in plan order; raise ``WalkforwardError`` on refusal.

``windows`` is a non-empty list or tuple of distinct non-empty labels, and
``sources`` maps supplied labels to complete results, rows lists or file paths.
``metric`` and ``direction`` are required; there is no inferred direction.
``space`` is used only when no source records one. ``max_work`` bounds the
declared admission figure, with equality admitted and None unbounded.

Definition at line 472 of file walkforward.py.

Variable Documentation

◆ ALGORITHM

str pineforge_hpo.walkforward.ALGORITHM = "exact_per_window_v1"

Definition at line 95 of file walkforward.py.

◆ CODES

tuple pineforge_hpo.walkforward.CODES
Initial value:
1= (
2 "walkforward_parameter_missing",
3 "walkforward_parameter_invalid",
4 "walkforward_window_unknown",
5 "walkforward_no_supplied_sources",
6 "walkforward_input_invalid",
7 "walkforward_rows_incomplete",
8 "walkforward_space_missing",
9 "walkforward_space_mismatch",
10 "walkforward_context_mismatch",
11 "walkforward_direction_mismatch",
12 "walkforward_metric_unknown",
13 "walkforward_duplicate_vector",
14 "walkforward_no_eligible_rows",
15 "walkforward_resource_exceeded",
16)

Definition at line 97 of file walkforward.py.

◆ CONTRACT

str pineforge_hpo.walkforward.CONTRACT = "pineforge-hpo-walkforward/v1"

Definition at line 94 of file walkforward.py.

◆ DIRECTIONS

tuple pineforge_hpo.walkforward.DIRECTIONS = ("maximize", "minimize")

Definition at line 96 of file walkforward.py.

◆ INTERPRETATION

tuple pineforge_hpo.walkforward.INTERPRETATION
Initial value:
1= (
2 "(a) This module runs no window and evaluates nothing. The studies were run by "
3 "the caller's own application; this module reads rows that already exist.\n"
4 "(b) No claim is made about what data any window's study used. The context checks "
5 "are necessary, not sufficient: equal bar counters, one shared space and one "
6 "shared space hash do not prove the same data, the same fixed inputs or the same "
7 "strategy, and the windows may overlap, touch or be separated.\n"
8 "(c) Each window's selected value is in-sample for that window: it is the best "
9 "scored row of that window's rows.\n"
10 "(d) A carry-over value is a row that the user's own study recorded, for the "
11 "vector this contract's rule selects in the previous window, and nothing more. "
12 "No value here is claimed to be out of sample. When the previous window has a "
13 "selected vector the pair is always reported, and a target window that holds no "
14 "eligible row with that vector is reported with row_found false and a reason: "
15 "that is not a zero and not a drop.\n"
16 "(e) The number of windows is small. The stability table is a summary of the "
17 "selected values in window order; it is not a trajectory, not a robustness "
18 "measure, and no threshold and no verdict is produced.\n"
19 "(f) v1 analyses finished studies; native in-loop walk-forward comes later."
20)

Definition at line 114 of file walkforward.py.