chc.experiment¶
Stability tier: experimental.
Which experiment, if any, to run before a decision: units per zone, the regret they remove, and a verdict to deploy now, experiment first, or abstain.
The decision (ZoneDecision) is one-shot, over K zones. Zone k's lever u_k moves
the zones' states through its own channel b_k, and a known coupling spreads the effect::
x = x0 + coupling diag(b) u, J(u; b) = (x - x*)' Q (x - x*) / 2 + u' R u / 2, lo <= u <= hi.
The channels are known up to a Gaussian posterior (ChannelPrior), and acting now costs
regret: what the best action under it, ZoneDecision.bayes_action, loses against the one
that knew b. An experiment
(ZoneExperiment) sets zone k's lever to +probe_k or -probe_k at random on
n_k units, each costing unit_cost_k and each adding probe_k^2 / noise_sd_k^2 to the
precision of b_k. design_experiment chooses the n_k that minimise the regret left
after the experiment, times the number of times the decision will be used, plus what the experiment
spends, within a budget. Then it measures the regret before and after by Monte Carlo, re-solving the
decision on every draw: the regrets, the value, its error and regret_bound are that
measurement. pinned and weights are not: they are the local model's, below.
The local model it optimises (the lab's value-of-information thread, independently verified):
- The decision weight
W = J_bu M^-1 J_ubover the free levers,Mthe Hessian ofJinu. It is the Hessian of the certainty-equivalent regret in the channel estimate, so a posterior with covarianceSleaves an expected regret oftr(W S) / 2to leading order. It is averaged over the prior's sigma points, because at a knife edge --q b^2 = rin one zone -- the plug-inWis zero and the regret is fourth order, not nil. - A pinned lever, held at its bound by a positive multiplier, has no local weight. It costs
regret only when the channel lies past its activation point:
s G(z) / (2 S)for a multiplierzstandard deviations from zero, withG(z) = E (Z - z)_+^2. What an experiment can buy there is at mostdelta^2 phi(z) / (S z^3)for everyz > 0,delta^2the multiplier's preposterior variance: a zone far from activation is not worth testing, and one near it is. - The allocation starts from reverse water-filling at the price of information,
unit_cost_k noise_sd_k^2 / probe_k^2, and minimises the full objective from there. With a flat prior that start is decision-Neyman,n_kproportional tonoise_sd_k sqrt(W_kk / unit_cost_k) / probe_k; on the lab's four-zone market classical Neyman, which ignoresW, left 1.5 times its regret.
The action, before the experiment and after it, is the Bayes one: the best action under the prior
now and under the posterior after. The expected cost under b ~ N(m, S) is
J(u; m) + u' ((coupling' Q coupling) o S) u / 2, o the elementwise product
(validation/experiment_bayes_action.mac), so the Bayes action is the certainty-equivalent one
with the action weight raised by (coupling' Q coupling) o S, and it holds back where the
channel is uncertain. The posterior's covariance does not depend on what the experiment reads, so
neither does the raise after it. Against the certainty-equivalent action an experiment was
credited with what acting well now would have saved without it: on one zone, Q = 1,
R = 0.1, a target 1 from a baseline 0 and b ~ N(0.5, 1), acting on the mean lost 1.01 and
the Bayes action 0.27; at a unit cost of 0.03 the experiment recommended against the first, worth
0.63 there, left 0.35 of regret and spent 0.03, and so lost 0.11 against the second. So
"experiment" says experimenting beats acting well now.
What the local model gets wrong, and what is done about it:
- A wide prior. At a prior sd of 37-50% of
bthe lab's local model put the regret after the experiment 32% low. The numbers reported are Monte Carlo's whatever the model says;model_gapis how far the model was from them, and a gap above 25% is logged as a warning. The model then only proposes: at every spend from the budget down by halves to one unit's, its best experiment that spends it, and none; Monte Carlo scores each on draws of its own and the best is reported on the main draws. The same search runs where the model's experiment does not pay, which the model read at that one allocation only: on one zone,R = 0.1,b ~ N(0.5, 1)and a unit costing 0.07, it chose none, and one unit was worth 0.033. - A channel whose sign is unknown. When a zone that matters stays within two posterior standard
deviations of zero after the experiment the budget buys, and the experiment does not pay, the
verdict is
"abstain": the sign decides which way to act. - Outside the model, and not checked: a response nonlinear in the lever, interference the coupling does not state, a probe that moves the state it measures, heavy-tailed noise, and a pinned lever's far bound, which the tail law ignores and so overstates what testing it buys.
A channel the logs do not identify -- chc.decision.NotIdentifiedError -- enters with the
prior its owner is prepared to state, a wide variance about the best guess; the design then says
how many units in which zones identifying it is worth, or "abstain" when nothing affordable is.
ZoneDecision
dataclass
¶
A one-shot decision over K zones, x = baseline + coupling diag(b) u and
J(u; b) = (x - target)' state_weight (x - target) / 2 + u' action_weight u / 2 on the box
lo <= u <= hi.
coupling[i, k] is how much of zone k's channel reaches zone i's state: the identity
when zones do not interact, I - P when a lever pulls a share P[i, k] of its effect from
its neighbours. baseline is the state with every lever at zero. action_weight must be
positive definite, so every channel vector has one best action; a bound may be infinite.
Raises:
| Type | Description |
|---|---|
ValueError
|
on shapes that do not agree, a non-finite entry other than a bound, a
|
cost(u, b)
¶
J(u; b).
solve(b)
¶
The best action for channels b, on the box.
regret(u, b)
¶
What u loses against the best action when the channels are b.
bayes_action(prior)
¶
The best action, on the box, for channels known only as prior: the action that
minimises the expected cost J(u; m) + u' ((coupling' Q coupling) o S) u / 2
(validation/experiment_bayes_action.mac), the certainty-equivalent one with the action
weight raised by (coupling' Q coupling) o S.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a prior whose length is not the decision's zones. |
ChannelPrior
dataclass
¶
What is known about the channels now, b ~ N(mean, covariance): a fit's estimate and its
covariance, say. A zero variance is a channel known exactly, and no experiment is spent on it.
Raises:
| Type | Description |
|---|---|
ValueError
|
on shapes that do not agree, a non-finite entry, or a covariance that is not symmetric positive semidefinite. |
ZoneExperiment
dataclass
¶
What a unit of experiment costs and tells, per zone.
A unit in zone k sets the lever to +probe_k or -probe_k at random and observes the
zone's response with noise sd noise_sd_k, so it adds probe_k^2 / noise_sd_k^2 to the
precision of b_k. It costs unit_cost_k, in the units of the decision's cost.
Raises:
| Type | Description |
|---|---|
ValueError
|
on vectors of different lengths, or an entry that is not positive and finite. |
information
property
¶
The precision one unit adds to each channel.
PinnedZone
dataclass
¶
A lever held at its bound at the prior mean: how far its multiplier is from releasing it, in
prior standard deviations, and the expected regret the pin costs now, times uses.
regret is the local model's Gaussian-tail law, s G(z) / (2 S), not a measurement: on one
lever pinned at zero, x = -1 + b u with b ~ N(-0.3, s^2), it read 14% under the exact
regret at z = 3, 6% under at z = 1.5, 8% over at z = 1 and 52% over at z = 0.6.
ExperimentDesign
dataclass
¶
What design_experiment recommends, and the numbers behind it.
The regrets are expectations over the prior, times uses: regret_now of the Bayes
action under the prior, ZoneDecision.bayes_action, and regret_after of the Bayes
action under the posterior once sample_sizes units have run (see chc.experiment).
Both are Monte Carlo's, over draws of the channels with the decision re-solved on every draw,
and error is a half-width that holds their expected difference with probability at least
0.95: the larger side of Hall's (1992) skewness-corrected interval, since the difference is
skewed to the right. value is what the experiment removes less what it spends.
regret_bound is the level quantile of the regret of acting now: with that probability
under the prior, deploying now loses at most this much. It is the draws' order statistic of
rank ceil(level (draws + 1)), which a fresh draw stays at or below with probability at
least level at any number of draws, and inf where draws is below
level / (1 - level), too few to show it.
model_gap is the local model's largest relative miss against the two Monte Carlo regrets;
above 25%, or where its experiment does not pay, the allocation is the best Monte Carlo
scored of the model's proposals, and reason says which. weights is the prior-averaged
decision weight W.
DitherDesign
dataclass
¶
What dither_covariance recommends: the dither's covariance over the levers, and
what it and two simpler designs leave.
value is tr(C V) + tr(Q (P0 + V)^-1) at covariance: what the dither costs the plan
plus the regret its information leaves. gap bounds how far value is above the least
value any dither reaches: 0 for the closed form, which is exact; on the numeric route, the
duality gap the stationarity of the solution certifies. diagonal and white are the
best designs that dither each lever on its own, diag(diagonal), and every lever alike,
white I, with their values.
ProbeDesign
dataclass
¶
What probe_design recommends: the probe's covariance over the levers, what the gain
re-solved after it is expected to lose, and the same for a white probe of the same power.
regret is the expected excess of the re-solved gain's average cost per period over the
optimal gain's, to first order in 1 / periods: Phi(U) / periods at covariance.
gap bounds how far it is above the least any probe of that power reaches, in the same
units: 0 for the closed form, the duality gap the gradient certifies on the numeric route.
white_regret is Phi of power / m times the identity over periods, and ratio
regret / white_regret, at most 1. cost and white_cost are what each probe adds to
the plan's average cost per period while it runs, exactly: tr((R + B' P B) U), P the
cost-to-go of gain, the gain the probe runs under.
design_experiment(decision, prior, experiment, budget, *, uses=1.0, level=0.95, draws=10000, seed=0)
¶
How many units to run in each zone before deciding, and whether to run any.
uses is how many times the decision will be taken on what is known after the experiment,
so the regret it leaves counts uses times and the spend once. The verdict:
"experiment": the regret the experiment removes, against the Bayes action now, exceeds its spend by more than the Monte Carlo error;"abstain": no experiment scored does, and a zone that matters stays within two posterior standard deviations of zero, so the sign of its channel -- which way to act there -- is still unknown;"deploy": no experiment scored does, and acting now, onZoneDecision.bayes_action, costsregret_nowon average and at mostregret_boundwith probabilitylevel.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a prior or an experiment whose length is not the decision's zones, a
|
dither_covariance(cost, weight, precision=None)
¶
The covariance of a dither over several levers that buys the most for what it costs.
Over K levers, a dither of covariance V costs the plan tr(C V) and leaves a regret
of tr(Q (P0 + V)^-1): C is cost, Q is weight and P0 is precision,
zero where not given. dither_covariance minimises their sum over V >= 0.
Where the three come from. A dither drawn afresh each period with covariance V, run for
n periods on a channel that does not move with the state (or a plant whose drift is known),
with noise covariance Sigma, adds n V (x) Sigma^-1 to the precision of the channel; a
plan whose regret in the channel's error is e' W e / 2 (the decision weight,
chc.plan.CausalPlan.decision_weight, or design_experiment's) then leaves
tr(Q V^-1), Q the weight traced against Sigma over 2 n, in the units P0
holds the prior's precision in. C is half the sum, over the dither's periods, of the plan's
action Hessian's diagonal blocks: what a dither costs a quadratic task, exactly, when the
dither is open loop. This is the criterion of Wagenmaker, Simchowitz and Jamieson (ICML 2021)
in its static case.
The closed form. The sum is convex in V, and stationary where C = M^-1 Q M^-1,
M = P0 + V: at the matrix geometric mean of C^-1 and Q (Pusz and Woronowicz, Rep.
Math. Phys. 1975; Ando, Linear Algebra Appl. 1979; Bhatia, Positive Definite Matrices, 2007,
ch. 4),
M* = C^-1 # Q = C^-1/2 (C^1/2 Q C^1/2)^1/2 C^-1/2,
the one positive definite solution of M C M = Q. Where V* = M* - P0 is positive
semidefinite it is the optimum, with value 2 tr((C^1/2 Q C^1/2)^1/2) - tr(C P0)
(validation/dither_covariance.mac). A diagonal C, Q and P0 give each lever the
precision sqrt(Q_kk / C_kk), the level design_experiment's water-filling starts
from. Where V* is not, the prior already holds more than the closed form asks along a
direction, the bound V >= 0 binds, and the optimum has no closed form: it is found over a
Cholesky factor of V by L-BFGS from three starts, and gap bounds what that leaves.
On C = [[2, 1], [1, 1]], Q = [[1, -1/2], [-1/2, 2]] and no prior the value is
2 sqrt(3 + sqrt 7) = 4.7522: 16 % below the best diagonal dither, 4 sqrt 2 = 5.6569,
and 21 % below the best white one, 6. A correlated dither moves the levers together where the
channel's error costs the plan least to learn.
It is a certainty-equivalent design: Q is read at the estimate, and the information is the
least-squares fit's. Where the dither also moves a state the plan reads, the state's own
excitation adds information this leaves out.
Raises:
| Type | Description |
|---|---|
ValueError
|
on matrices that are not square of one size, a non-finite entry, a |
probe_design(a, b, q, r, *, noise, power, periods, weight=None, gain=None)
¶
The covariance of a probe, at a cap on its power, that leaves the LQR gain re-solved after it the least expected regret.
The plant is x_{t+1} = A x_t + B u_t + w_t, w_t ~ N(0, noise) independent over t,
and the decision is the LQR gain of the average cost per period E[x' Q x + u' R u],
u = -K x. For periods periods the plant runs under gain, the LQR gain on (A, B)
unless given, plus a probe drawn afresh each period, u_t = -gain x_t + eta_t,
eta_t ~ N(0, U); [A B] is then fitted by least squares on (x_t, u_t) and the gain
re-solved on the fit. probe_design chooses the U >= 0 with tr U = power that
minimises what the re-solved gain is expected to lose.
The criterion is the task-optimal one of Wagenmaker, Simchowitz and Jamieson (ICML 2021):
the trace of the decision weight against the inverse information. To second order in the fit's
error e over theta = (A.ravel(), B.ravel()), the re-solved gain loses e' W e / 2 per
period, W the decision weight: weight, by default the LQR's own,
W = 2 J' (G (x) Sigma*) J, J the gain's Jacobian in theta, G = R + B' P* B and
Sigma* the closed loop's stationary state covariance under noise
(chc.regret.ce_regret_law's second-order law, doubled to a Hessian). To first order the
fit's error in [A B], row by row, is N(0, noise (x) Gamma^-1 / periods), Gamma the
stationary covariance of z = (x, u) in the probed loop, so the expected regret is
Phi(U) / periods with Phi(U) = tr(Wn Gamma(U)^-1) / 2, Wn the weight traced against
noise over the plant's rows, (n + m) x (n + m): the re-plan price tr(W S) / 2 of
chc.gate.ChannelMove.price at the fit's covariance S.
Where the probe's information goes. Gamma^-1 = E Sx^-1 E' + F U^-1 F', E = [I; 0]
and F = [gain'; I]: the fit reads B off the probe alone, U, and the closed loop
A - B gain off the state's excitation, Sx(U), the stationary solution of
Sx = A_cl Sx A_cl' + B U B' + noise (validation/dynamic_probe_design.mac). So
Phi(U) = (tr(Wn_xx Sx(U)^-1) + tr(F' Wn F U^-1)) / 2,
convex in U, since Sx is affine in it, and decreasing, so the cap binds. Where the
weight holds no state block the first term vanishes and the optimum is in closed form,
U* = power M / tr M with M = (F' Wn F)^1/2. That is the static case: a weight on B
alone, n m square and ravelled as B.ravel() (as
chc.plan.CausalPlan.decision_weight ravels the one-step channel), gives
dither_covariance's covariance with cost the identity and weight
F' Wn F / (2 periods) at the power that is its trace, and regret its regret term. A cap
on tr(C U) in place of tr U, such as the probe's own cost, C = R + B' P B, is this
one on the levers scaled by C^1/2: pass B C^-1/2 and C^-1/2 R C^-1/2. Otherwise the
optimum is found over a Cholesky factor of U scaled to the cap, by L-BFGS from the white
probe and from the closed form of the second term alone, and gap is
tr(D U) - power lambda_min(D), D the gradient of Phi, over periods: the
convex problem's Frank-Wolfe gap, a bound on how far the probe is from the best.
On A = [[0.9, 0.2], [-0.1, 0.7]], B = [[1, 0.1], [0.3, 0.2]], Q = I,
R = diag(1, 0.05), unit noise and power 1, the gain leans on the weak, cheap second lever;
the design gives it 0.83 of the power and leaves 0.753 of the white probe's regret. At power 10,
where the state's excitation counts, it leaves 0.942, where the closed form of the second term
alone leaves 1.004.
What it leaves out. It is first order in 1 / periods: the fit's error is not exactly
Gaussian, a fit of a few periods inflates its covariance, by periods / (periods - n - m -
1) for Gaussian regressors, and the exact regret's mean is infinite, since a fit can give a
gain that does not stabilise the plant (chc.regret.ce_regret_law reads its law). It
is a certainty-equivalent design: the weight and Gamma are read at the (A, B) given,
not at the truth. The probe is drawn afresh each period; a probe correlated over time, whose
spectrum Wagenmaker et al. design, can excite the state more at the same power, and is not
built. The fit is of all of [A B]: a fit that holds A known reads B off gain x
as well, and learns more than this credits. The cap is the caller's: what the probe costs over
the run, against the regret it removes over the uses after it, is not traded here.
Raises:
| Type | Description |
|---|---|
ValueError
|
on matrices of shapes that do not match, a non-finite entry, a |