polars_online.spec.ewridge¶
- polars_online.spec.ewridge(name: str, *, targets: Sequence[str | Target | FormulaTarget | Expr], features: list[str], ridge: float | list[float] | None = None, feature_sets: dict[str, list[str]] | None = None, standardize: bool = False, ridge_scale: Literal['mean', 'sum'] = 'mean', coef_prior: list[list[float]] | None = None, session_shrink: float | None = None, long_half_life: float | timedelta | str | Expr | None = None, solve_every: float | timedelta | str | Expr | None = None, max_rows_between_solves: int | None = None, gram_block_rows: int | None = None, gram_threads: int | Literal['auto'] | None = None, target_gaps: Literal['own_rows', 'pairwise'] = 'own_rows', window_size: float | timedelta | str | Expr | None = None, closed: Literal['right', 'both'] = 'right', snapshot_every: float | timedelta | str | Expr | None = None, max_rows_between_snapshots: int | None = None, window_budget: dict[Literal['thin', 'refuse'], float] | None = None, **common: Unpack[CommonKwargs]) dict[str, Any][source]¶
Exponentially weighted ridge regression on running sums.
Use it as the default model for a numeric target, where one set of running sums fits a grid of ridge values and feature sets for one extra solve each, and a row takes no more time to learn for the grid. Use
kalman()for coefficients that drift,huber()orquantile()for outliers or a quantile, andlasso()for a sparse fit. Usesgd()orpa()where learning a row must take O(k) time forkfeatures: this model takes O(k²).Parameters
The stream parameters every builder takes, such as
clock,half_life,gap_cap,min_weight,groupand the diagnostics, are inpolars_online.spec. This model’s own:ridgeThe penalty that pulls the slopes toward
coef_prior, or toward 0, so that a fit on few rows or collinear features stays determined. In the features’ squared units, unlessstandardize. Default1e-6, a ridge too small to move a fit on features of unit scale that still keeps its solve determined. For features far from unit scale, setstandardize=True: on features far smaller than 1, such as returns, the default ridge outweighs the data, and on features far larger it may not keep a nearly collinear solve determined. Finite and at least 0:0is plain least squares. It never penalizes the intercept, except underridge_scale = "sum". A list of two or more values fits one slot per value from the same sums, reported side by side aspred_<t>__r<ridge>. A list of one value is no grid, and a value listed twice is refused.feature_setsNamed subsets of
features, each fitted from the same sums, reported aspred_<t>__<set>. Default: one fit over every feature. Only the named sets are fitted, so to keep a fit on every feature, name a set that holds them all. With two or more sets,emit_selectedreports the set doing best. A single set is no grid: it is fitted alone, and its fields take no suffix. Refused when it names no set, names a set twice, holds an empty set, or names a column not infeaturesor one twice in a set.standardizeSolve on the correlation matrix and unscale the coefficients after, so that
ridgemeans the same whatever the features’ units, and a feature whose variance is zero, which would make the system singular, is dropped from the solve. Without an intercept it scales by each column’s root mean square instead, and drops only a column that is all zero (Standardizing without an intercept in Notes). DefaultFalse, which keepsridgein the features’ squared units, as a plain ridge regression has it.huber()andquantile()standardize the same way.ridge_scaleWhat the ridge is scaled against, which decides whether its pull lasts or fades.
Sandetaare the running means of The update,Wthe weight behind them, andpthe product of every decay the stream has applied:setting
the prior
the system
"mean"(the default)a fixed per-observation penalty whose pull is permanent: “always stay near this belief”
(S + ridge * D) beta = eta, the intercept unpenalized"sum"sits on the decaying sum scale and fades as data arrives, the usual warm start: “begin at yesterday’s fit and let evidence take over”
rls()’s,(W S + p * ridge * I) beta = W eta, penalizing every coefficient, the intercept’s includedThe default keeps the ridge a penalty, as in a plain ridge regression.
"sum"is refused besidestandardize, beside any grid ofridgevalues and feature sets (two or moreridgevalues, or two or more sets), and besidewindow_size.coef_priorThe coefficients to shrink toward instead of zero, such as yesterday’s fit: one vector per target, in the features’ original units,
len(features) + 1long when there is an intercept. Default none, which shrinks toward zero. The intercept’s entry is read only underridge_scale = "sum", the one solve that penalizes the intercept. Refused with the wrong number of vectors, a vector of the wrong length, or a value that is not finite.session_shrinkA middle way between a session’s decay and a full reset: at each session change, blend this session’s running sums with the long run’s,
session_shrinkbeing the long run’s share, in[0, 1].0keeps this session’s sums, and1takes the long run’s moments at this session’s weight. Default none, no blend. It moves the running sums’ means and moments, wheresession_gaponly decays their weight. It needs asessioncolumn andlong_half_life. It is refused besidesession_gap = "reset", which resets the model at the change, besidegroup_close = "session", which closes the group there, and besidewindow_size.long_half_lifeThe half-life of the long run that
session_shrinkblends in, in clock units, above 0;infkeeps the whole history. A second set of running sums, the slow twin, decays at it. Default none, which keeps no twin, and refused withoutsession_shrink.solve_everyHow often the model solves for its coefficients, in clock units, at least 0:
0solves on every row, andinfnever on the clock. Left out, the schedule is by weight: a solve once the weight learned since the last reachesln 2 / 50of the weight the fit holds, which in steady state is everyhalf_life / 50of clock, at any row spacing. Underhalf_life = infand underlam, the default solves on every row. A prediction uses the coefficients of the last solve, so a coarser schedule is faster and its coefficients older. The solve schedule in Notes gives the rules at the schedule’s edges.max_rows_between_solvesThe most rows between two solves, whatever the clock does, at least 1. Default off, so the clock or the weight alone sets the schedule.
1solves on every row, so the coefficients are current at every row.gram_block_rowsFor a fit over hundreds of features: hold that many rows back and add them to the
k x kmatrix of the running sums in one matrix product, in place of adding each row to it as it is learned. Default 0, off: the gain is for fits of hundreds of features, and the held rows travel in the state. Refused where no schedule spaces the solves (solve_every <= 0, the default underlamandhalf_life = inf, ormax_rows_between_solves <= 1), besidewindow_size, and past 256 MiB of held rows.gram_threadsThe most of the bank’s threads one update of the
k x kmatrix may use: a whole number of at least 1, or"auto". Default"auto"(Noneacts as it), which splits an update only where the bank has idle threads. The threads are the bank’s own, so it never adds one, and the output is the same to the bit at every count. Threads in Notes gives the rule"auto"follows.target_gapsWhich rows a target’s fit is read from where the target is null on some:
setting
the feature covariance is taken over
what that gives
"own_rows"(the default)the target’s own rows, so its fit is the fit of those rows alone; targets present on the same rows share one matrix, and one that goes missing where the others are present takes a copy and keeps its own from then on
several targets keep one
k x kmatrix per pattern of missing rows, and a single target keeps one"pairwise"every row, the way pandas’
DataFrame.covtakes a pairwise-complete covariance: one matrix whatever the gapsexact when the gaps have nothing to do with the features; where they do, each slope is scaled by the ratio of the feature’s variance on the target’s rows to its variance on all of them
Keep the default where the gaps depend on the features, as with a target present only on trade rows between market-data rows. Either way
weight_sumcounts every row, and a null target is still predicted.window_sizeA hard window: the age, in clock units, finite and above 0, at which a row counts for nothing, where the decay alone would leave
0.5 ** (age / half_life)of it. Inside the hard window the weights are still exponential, so this is an exponentially weighted regression under a hard window, not rolling least squares. Default none. It is refused besideridge_scale = "sum", whose prior’s scale is the product of every decay the stream applied, which a hard window cuts the data of but not the prior. It is refused besidesession_shrink, whose slow twin is a second set of running sums under a longer half-life, and besidegram_block_rows.closedWhich edge of the hard window holds the row exactly
window_sizeold, in Polars’ words (rolling_sum_by(closed=))."right", the default, keeps the rows less thanwindow_sizeold, as the window operators (polars_online.ewm_mean) androlling_sum_bydo."both"keeps that row too, and is refused withoutwindow_size."left"and"none"would leave out the row the hard window ends at, which a model cannot do, since it reads its fit after learning that row: both are refused.snapshot_everyHow often the hard window takes a snapshot of the running sums, in clock units, finite and at least 0: a number of the clock’s units, a duration on a temporal clock (
"1m"), or0for every row. Default none: every row, unlessmax_rows_between_snapshotsis given. A coarser cadence divides the hard window’s memory, and can only shorten the hard window it keeps. Refused withoutwindow_size.max_rows_between_snapshotsThe most rows between two snapshots, at least 1. Whichever of it and
snapshot_everycomes first takes a snapshot. Default off, so the clock alone spaces them. Refused withoutwindow_size.window_budgetA bound, in MiB above 0, on the memory each hard window’s ring of snapshots takes, and what happens at it:
window_budgetat the bound
{"thin": mib}drops every other snapshot and doubles the spacing between the rest, the clock’s or the rows’ or both, as often as it takes; like
snapshot_every, that can only shorten the hard window{"refuse": mib}refuses the chunk, naming the ring’s size and its cadence
unset
refuses past 256 MiB per ring;
{"refuse": float("inf")}is no boundRefused without
window_size.
Output
One output column, named after the spec, whose value in each row is a record of these fields. docs/OUTPUTS.md#ewridge gives each field’s type and when it is null:
pred_<t>,resid_<t>Per target: the prediction, and
y - predwhere the target is not null.weight_sumThe weight the model has accumulated before the row and before the row’s own decay.
settled_fracHow far the model had come toward its steady state under decay before the row.
withheld_reasonWhy the row’s predictions were withheld, null where they were not.
coefPer (target, ridge value, feature set) slot in the order the
predfields declare them, the intercept then one entry per feature, zero for a feature outside the slot’s set.coef_index()maps each position to its term, andcoef_fields()names the column each becomes when the output column is unnested.support_coefOn
coef’s rows, each coefficient’s data share, laid out likecoef: how much of the fit after the row the data determined rather than the ridge (polars_online.spec).
plus the fields of the diagnostics switched on, as
polars_online.specdescribes them. Under a half-life grid every field is suffixed per instance (the part of the model that fits one half-life), and under a ridge or feature-set grid each slot’s fields (polars_online.spec, “What a spec writes”). A combined grid joins the suffixes, aspred_y__mkt_r0.1.polars_online.ModelBank.gram()returns the sums behind the fit, one entry per Gram (undertarget_gaps = "own_rows", one per set of targets present on the same rows). A group that closes writes one row per Gram topolars_online.ModelBank.closed_groups().Raises
As every builder does (
polars_online.spec), andValueErrornaming the problem for:a
ridgebelow 0 or not finite, or listed twice;a
feature_setsthat names no set, names one twice, holds an empty set, or names a column not infeaturesor one twice in a set;a
coef_priorwith the wrong number of vectors, a vector of the wrong length, or a value that is not finite;a
ridge_scaleother than"mean"or"sum", and"sum"besidestandardize, any grid ofridgevalues and feature sets (two or more of either), orwindow_size;a
session_shrinkoutside[0, 1], or withoutlong_half_lifeorsession, or besidesession_gap = "reset",group_close = "session"orwindow_size;a
long_half_lifenot above 0, or withoutsession_shrink;a
solve_everybelow 0, and amax_rows_between_solvesormax_rows_between_snapshotsof 0;a
gram_block_rowsbesidewindow_size, without a solve cadence, or past 256 MiB of held rows, and agram_threadsof 0;a
window_sizenot finite or not above 0; aclosedof"left"or"none"; asnapshot_everybelow 0 or not finite; awindow_budgetnot above 0; andclosed="both",snapshot_every,max_rows_between_snapshotsorwindow_budgetwithoutwindow_size.
The update
Per row,
wis the row’s weight,λ = 0.5 ** (Δclock / half_life)its decay (lam ** Δclockunderlam), andzthe features with the intercept in front.Δclockis the clock’s step since the last row the model did not skip, capped atgap_cap, orsession_gapat a session change, as the glossary’s decay says. Under the defaulttarget_gaps = "own_rows",W_jis the weight behind targetjover the rows that target is present on, andS_jandeta_jare its running means ofz z'and ofz * y_jover those rows. Under"pairwise"the slopes solve the centered system of Target gaps in Notes instead, with the feature covariance taken over every row.beta0_jis the target’scoef_prior, 0 without one:W_j' = λ * W_j + w S_j' = (λ * W_j * S_j + w * z z') / W_j' eta_j' = (λ * W_j * eta_j + w * z * y_j) / W_j' on the schedule: (S_j + ridge * D) beta_j = eta_j + ridge * D * beta0_j D = I with a 0 at the interceptExample
This code fits a slope that drifts from 1 to 3, under two ridge values, and prints the slope each found at the last row. A half-life of 500 rows lags the drift a little, and the ridge of 0.5 divides the slope by about
1 + 0.5 / var(x):import numpy as np rng = np.random.default_rng(1) x = rng.standard_normal(5_000) slope = 1.0 + np.arange(5_000) / 2_500 # the true slope, row by row y = slope * x + 0.5 * rng.standard_normal(5_000) pl.DataFrame({"x": x, "y": y}).write_parquet("drift.parquet") rr = po.spec.ewridge( "rr", targets=["y"], features=["x"], half_life=500.0, ridge=[1e-6, 0.5], # one fit per value, from the same sums ) bank = po.ModelBank([rr]) bank.fit(pl.scan_parquet("drift.parquet")) # learn every row, keep no output print(f"the true slope at the last row: {slope[-1]:.2f}") for r in bank.coef().filter(pl.col("term") == "x").iter_rows(named=True): print(f"ridge {r['ridge']:g}: slope {r['coef']:.2f}")
the true slope at the last row: 3.00 ridge 1e-06: slope 2.70 ridge 0.5: slope 1.81
See also
ewridge in docs/MODELS.md: recipes on data whose answer is known, and what the model is checked against.
rls(), the fitridge_scale="sum"gives, by recursive least squares, which loses half as many digits on a nearly collinear design.huber(), these sums with each row down-weighted by its residual, which takes this model’sfeature_setsandridge_scale.polars_online.ModelBank.gram()andpolars_online.gram, to read the sums back, pool them and solve them offline.
Notes
The sums. The sums are means, not totals, so they stay bounded over a stream of any length. Every fit in a grid is solved from them, which is why a grid of ridge values and feature sets costs a solve each, and a row is learned once whatever the grid. A list of half-lives keeps one set of sums each. The second moments are kept centered (a weighted Welford update), so a feature far from zero loses no precision.
The solve. The solve is a Cholesky factorization. A near-singular system is retried with a small jitter added to its diagonal, growing at each try, so each try is a rung of a ladder of jitters. A solve that needed one is counted in
polars_online.ModelBank.solve_failures(). A count above zero points at constant or collinear features, or too few rows for the features. A wide solve runs on the bank’s threads, and its result is the same to the bit whatever their number (POLARS_ONLINE_MAX_THREADS, or the machine’s cores): at 2,000 features a factorization and solve took 18 ms on eight threads against 68 on one.The condition check. A system can factorize and still be too nearly singular for its solve to keep a digit. Rounding can leave a matrix past
1/uin condition positive definite, withu = 2**-53. Its coefficients then come out wrong by more than their own size: two features equal to within1e-11of their spread gave slopes of -364.1 and 363.1 for a truth of 1 and -2. So each factorization estimates the condition of the systemAwith each column scaled by the root of its diagonal,H = E^-1 A E^-1withE = diag(sqrt(a_ii + delta)). That is what a Cholesky solve is accurate to, whatever the features’ units. A factorization that needed a jitterdeltaon the diagonal is judged as the system it solves,A + delta I. On a design where one column is an exact combination of the others, the first rung’sdelta,1e-12of the mean diagonal, leaves||H^-1||_1near1e12, past the limit from about 30 coefficients.An upper bound from the factor decides most systems for a fraction of one solve, and the rest take an estimate of
||H^-1||_1by Hager and Higham’s method (LAPACK’sdlacn2), about four solves, from the factor inO(k^2). The factorization and solve are backward stable, with a backward error of at mostgamma_{3k+1}in each ofH’s entries, wheregamma_m = m u / (1 - m u), and sok * gamma_{3k+1}in its 1-norm. So the forward error of the scaled coefficients is at most2 kappa eta / (1 - kappa eta), withkappa eta = k * gamma_{3k+1} * ||H^-1||_1. Where that bound reaches 1, no digit is promised:withheld where 3 * k * gamma_{3k+1} * ||H^-1||_1 >= 1 (k = 3: ||H^-1||_1 >= 1.0e14; k = 10: 9.7e12; k = 50: 4.0e11)There the fit is withheld:
coef,support_coefand the predictions are null,withheld_reasonreadsill_conditioned, and the solve is counted insolve_failures. The next solve whose system is within the limit reports again. A ridge,standardizewith a ridge, or fewer collinear features keep a system inside it.rlsrotates the design where this model squares it, and loses half as many digits to the same design.The ridge’s two scales.
Sis a weighted mean, so the two settings ofridge_scalemean two different priors. Under"sum"a constant target of 5 reads an intercept of 3.5 at row 20 underridge=10,half_life=50, and 4.95 at row 200, until the prior fades. Acoef_priorintercept is what it shrinks toward.Standardizing without an intercept. Under
standardizewithout an intercept nothing is centered. The system is scaled by each column’s root mean square instead, a fit through the origin is least squares through the origin, and the column dropped is one that is all zero.The session blend. On a session boundary the fit’s moments become a mixture of the two data sets,
1 - fof this session’s andfof the long run’s,fbeingsession_shrink:m' = (1 - f) * m_fast + f * m_slow C' = (1 - f) * C_fast + f * C_slow + f * (1 - f) * (m_fast - m_slow)(m_fast - m_slow)'
for the means and the centered moments. The weight stays this session’s, so
weight_sum, the warm-up gates and the solve schedule do not move. The blend changes the moments and nothing else. The coefficients stay as last solved until the next solve the schedule brings due, which reads the blended moments together with every row learned since. So the output is continuous inf, and0is the same as nosession_shrink, to the bit. For the new session’s first rows to read the blend at once, solve on every row (max_rows_between_solves = 1). The solve on the new session’s first row then reads it, and the row after is predicted from it. Withridge_scale = "sum"the prior keeps this session’s scale too, so at1the fit is the twin’s moments under this session’s prior.The solve schedule.
solve_every = infnever solves on the clock: the sums are collected and nothing is solved but where the row cap and a target’s first rows say. Any value of1e18or more does the same, past the end of any stream on every clock.1e18seconds is 3.2e10 years,1e18rows is 31.7 years at a billion rows a second, and on a number clock it is 31.7 years of epoch nanoseconds. The schedule by weight solves more often during warm-up and after a gap, where the fit moves most. A half-life far longer than the stream still solves, at rows further apart as the weight grows. The coefficients are solved from the sums as they stood at the last solve.The floor is the least of a row per unknown (
k + 1,kwithout an intercept),min_weightand each target’s own value of it. The schedule by weight runs no solve that comes due while the weight is below(1 - ln 2 / 50)(1 - 2**-16)of the floor, whether the weight ormax_rows_between_solvesbrings it due, unless a hard window is set. Until the next solve comes due, the weight learned since is less thanln 2 / 50of the weight, so every row stays below the floor and is withheld, and none could read the solve. The2**-16covers the weight’s rounding. The schedule moves on as after the solve. So every prediction, residual and spread is the one running every due solve would give, to the bit, apart from two rare cases: a target whose weight has decayed to exactly 0 below the floor, and a fit whose factorization fails at every rung. There a later row reads the last fit solved.coefthere is the last fit solved, null before the first, and a solve not run is not counted insolve_failures.So a group whose weight never reaches the floor, such as one of two rows over two features, reports no
coefon any row, inbank.coef()or as a closed group. To keep every solve, givemin_weight = 0, which makes the floor 0 and withholds no prediction for its weight, orsolve_every = 0, which solves on every row by the clock and runs every solve. The solves not run are most of the warm-up’s at a thousand features, and a fit there runs several times faster until the weight reaches the floor. The weight brings a solve due each time it has grown byln 2 / 50, about 1.4%: at rows of weight 1 and a weight of 1,000, every 14 rows. A row cap brings more solves due than that only where it is shorter, and a row cap of 1 brings one due on every row, so the skip saves most there.A given
solve_everyruns every solve its clock or its row cap brings due. No share of the weight bounds the weight learned between two of those, so it can cross the floor before the next one, and a row then reads the fit of a solve that ran below the floor. Withsolve_every = inf, a row cap of 3, six features and rows of weight 1 with no decay, the solve on the sixth row, below the floor of 7, serves the eighth and ninth rows.A given
solve_everyabove 0 and below1e18starts with a first period that solves by weight: once the weight learned since the last solve reachesln 2 / 50of the weight the fit holds, underhalf_life = infandlamtoo, where the default solves on every row. The period lasts untilsolve_everyhas passed since the group’s first row or its last reset, or untilmax_rows_between_solvesrows with weight have been learned. On the row clock, that start is a row before the first row. So an early fit of a few rows is not held for a whole period. The row that ends the period solves, and the schedule’s clock and row count run from there. On a wide fit the period’s solves can be most of the time. At 1,000 features andmin_weight = 50,solve_every = 1e9besidemax_rows_between_solves = 1000solved 185 times in its first 1,000 rows, and ran 20,000 rows at 5,400 a second.solve_every = infwith the same row cap solved on rows 50, 1,050 and every 1,000 rows after, at 16,800 a second (an M4 Pro on two threads, load near 10). For solves by a row cap alone, givesolve_every = inf.A target’s first solve falls on the row its weight reaches
k + 1(kwithout an intercept), where the schedule has not solved it sooner, whatevermin_weightabove that says.min_weightwithholds the output alone, so the fit is the same at anymin_weightfromk + 1up, on every schedule. A row of weight 0 is clock alone: it never solves and is no row of the cap. A solve that comes due on one waits for the next row with weight, and the solves fall where they would without it.Blocked updates. Holding rows back gains from a few hundred features: with blocks of 256 rows, a fit that never solved learned its rows 5.1 to 6.6 times as fast as adding each row as it came, from 256 to 2,000 features. With a solve every 512 rows it was about 4 times as fast. Under
gram_block_rowsthe matrix is brought up to date at the end of each block and before every solve, so the block never exceeds the solve cadence.weight_sum, the timing of every prediction and chunk invariance are unchanged to the bit. The blocked sum is the same sum in another order, so a blocked fit agrees with an unblocked one to rounding. Each target’s cross-moments with the features wait for the block as well, and are merged from the same pass over its rows. So a target adds little beside the product: at 200 features about 0.13 ns per feature and row (0.18 where the target has gaps), against 0.35 for adding its cross-moments row by row (one fit, one core of an Apple M4 Pro). A target’s weight, mean and variance still take every row. The held rows travel in the state file, with each target’s value on them. They are refused over 256 MiB, counting the slow twin ofsession_shrinkand, undertarget_gaps = "own_rows", a block per target.Threads.
gram_threadsruns the update of thek x kmatrix on up to that many threads: the block’s matrix product undergram_block_rows, and each row’s rank-one update without it. The bank’sthreadssets how many threads it has (POLARS_ONLINE_MAX_THREADS, or one per core, when it isNone). The option caps how many of them one spec’s update may take, so a count above the bank’s number of threads runs on that number. A solve is not capped by this count: its factorization can use every thread the bank has. Each entry of the matrix is still summed by one thread in one order, because the product is cut into pieces bykalone, never by the count. So the output is the same to the bit at every count."auto"splits only where the bank has idle threads. On each chunk the bank counts the pieces of work it runs side by side, one per spec and group,T, on itsPthreads. When2 * T <= P, each update may use2 * P // Tthreads, at mostP. Otherwise it uses one. Twice the even share lets a thread whose group is done take pieces of another group’s update. The rule reads the two counts and nothing else, so it does not depend on timing. Measured on 14 cores against a count of 1: one group at 2,000 features learned 3.0 times as fast, and 3.5 times withgram_block_rows=256. Four groups at 800 features learned 1.6 times as fast, and seven were even to 1.1 times. From eight groups up, a split of every count was even or up to 10% slower, so"auto"does not split there. With every fast core already running a group, splitting each row’s update only adds the cost of handing it out. Up to 256 columns (the features and the intercept) the product is one piece, and below 725 a row’s update stays on one thread, so the option changes nothing there. Being the same to the bit at every count, it is a setting and not part of the state. A saved bank resumes under the count of the specs given toload, or, given none, under the count in the saved spec.The hard window. A hard window is exact. The weighted totals behind the means,
W * S, are sums of per-row contributions. So everything at or before a timeuisλ_utimes the totals as they stood then,λ_ubeing the decay fromuto now, and subtracting that leaves the hard window. The model keeps a ring of snapshots to do it, so its memory grows with the snapshots the hard window holds: one per row by default, or one persnapshot_every. A half-life grid is one instance per entry, each with its own ring.snapshot_everyspaces the snapshots on the clock, assolve_everyspaces solves, andmax_rows_between_snapshotscaps the rows between them, asmax_rows_between_solvescaps the rows between solves. A row of weight zero counts, a gap capped atgap_capcounts as the cap, and without a clock column the clock is the row’s number. Under a clock spacing, every row at mostwindow_size - snapshot_everyold is kept and none older thanwindow_size. So the hard window kept is in[window_size - snapshot_every, window_size]in clock units, exactly, withsnapshot_everythe spacing in force: a thinningwindow_budgetdoubles it. A burst of rows inside one spacing takes no snapshot of its own.The bank plays each chunk’s clock through its rings’ snapshot schedule before it learns a row, so a chunk that would pass a refusing
window_budgetis refused whole and the bank goes on as it was. Underdrift_action="reset", whose resets that check cannot foresee, the ring finds the overrun as the rows go in instead. The bank then refuses every laterfit_predict,predictandsave: load its last save withpolars_online.ModelBank.load(), and feed it the rows since.weight_sum,sigmaandzscoreare read over the hard window as well, so the spread describes the rows the fit describes. The spread keeps a ring of its own for it, two floats and a row count a slot, bounded with the fit’s. Everything that reads the spread reads it over the hard window too: drift’s scale, the conformal band, and the rankingemit_selectedandemit_averagedtake. The coefficients are the hard window’s as of the last solve, so a coarsesolve_everyreports a hard window that has since moved on.Target gaps. Target
jkeeps its meanybar_j, the column meansm_jand the centered cross-momentsc_j, the exponentially weighted mean of(x - m_j)(y_j - ybar_j), over the rows it is present on. Its slopes solve(C + ridge * I) beta = c_j, with interceptybar_j - m_j . beta.target_gapsdecides which rows the feature covarianceCis taken over.