cleverly.Targeting#
- class cleverly.Targeting(fluctuation: Literal['logistic', 'linear'] = 'logistic', algorithm: Literal['iterative', 'one_step'] = 'iterative', g_bounds: Literal['auto'] | float | tuple[float, float] = 'auto', q_bounds: tuple[float, float] | None = None, nuisance_bound: float = 0.01, submodel_alpha: float = 0.9995, target_weights: bool = False, step_size: float = 0.001, max_iter: int = 20, tol: float = 1e-10, stopping: Literal['relative', 'scaled_var', 'sample_size'] = 'relative', step_bound: float | None = None, step_search: bool = True, iterate: Literal['last', 'best'] = 'last', isotonic: bool = False)[source]#
Configure fluctuation, nuisance bounds, and solver behavior.
- Parameters:
- fluctuation{“logistic”, “linear”}, default=”logistic”
Fluctuation submodel family.
- algorithm{“iterative”, “one_step”}, default=”iterative”
Targeting algorithm.
- g_bounds{“auto”},
float,ortupleoffloat, default=”auto” Treatment or cumulative-mechanism bounds.
- q_bounds
tupleoffloatorNone, default=None The known support of a continuous outcome.
Nonewidens the observed range by ten percent, which reads every observed outcome, so a cross-fitted fit of a continuous outcome requires the support here. Refused on a binary outcome, which the estimator does not rescale.cleverly.datasets.make_nonlinear_boundeddraws a proportion, for whichq_bounds=(0.0, 1.0)states a fact about the law.- nuisance_bound
float, default=0.01 Lower bound used by auxiliary nuisance regressions.
- submodel_alpha
float, default=0.9995 Logistic-submodel shrink bound.
- target_weightsbool, default=False
Whether probability weights enter the targeting score.
- step_size
float, default=1e-3 Step size for compatible targeting.
- max_iter
int, default=20 Maximum targeting iterations.
- tol
float, default=1e-10 Score-equation convergence tolerance. It is the bar of
stopping="relative", and the tolerance of the inner Newton solve under every rule.- stopping{“relative”, “scaled_var”, “sample_size”}, default=”relative”
The rule that decides the score equation is solved.
"relative"is the shipped test: the largest score over the mean absolute clever covariate is at mosttol."scaled_var"and"sample_size"are thetmle3convergence_typerules. Each compares the score, in the outcome’s units, withsd / (sqrt(n_u) * min(log(n_u), 10))or1 / n_u, wheren_ucounts the distinct units among the rows the solver receives andsdis the sample SD of the column’s per-unit influence curve. A declared rule is refused besidefluctuation="linear", which has no iteration to stop.- step_bound
floatorNone, default=None The longest step of one targeting iteration, in the units of the fluctuation coefficient.
Nonetakes the full Newton step. A positive number replaces the Newton step by thetmle3constrained step: the iteration moves along the normalised score vectors / ||s||and goes no further thanstep_bound. It needsalgorithm="iterative"andfluctuation="logistic". A bounded walk can stop short oftol. Then the fit warns, reportsconverged=Falseandfailure="max_iter_reached", andscore_checkfails it. Thetmle3pairing isstopping="sample_size"with a largermax_iter. Understopping="relative"the walk reachestol=1e-10only withstep_search=Trueand well over the defaultmax_iter: 25 to 190 iterations on the six arm-mean fits oftests/unit/test_step_bound.py::TestRelativeReachability. A fit whose initial regression already meets the rule takes no step.- step_searchbool, default=True
Under
step_bound,Truetakes the length in(0, step_bound]that minimises the weighted mean quasi-loss along the step, astmle3does withoptim_delta_epsilon.Falsetakes the whole bound, asdelta_epsilondoes. It needsstep_bound.- iterate{“last”, “best”}, default=”last”
Which iterate of the targeting walk the fit reports.
"last"reports the iterate at which the walk stopped."best"isuse_bestoftmle3: it reports the iteratek >= 1whose raw score vector has the smallest 2-norm, the first of any tie. The initial fit is never reported while a step exists. The walk still stops by the rule,n_iterandtracedescribe the whole walk, andconvergedis judged at the reported iterate.Fluctuation.best_iteraterecords the index. The best iterate differs from the last on a walk that oscillates, such asstep_search=False. Onalgorithm="one_step"the norm never rises, so the best iterate is the last. It is refused besidefluctuation="linear", which has no iterates.- isotonicbool, default=False
Whether a longitudinal survival fit projects each curve’s levels and band limits onto a non-decreasing curve; see
LTMLE. A point-treatment fit refusesTrue.
See also
TMLEMethodMethod configuration this object is the targeting half of.
InferenceInterval settings, which own
alpharather thansubmodel_alpha.cleverly.sensitivity.truncation_curveWhat the estimate does across
g_bounds.
Examples
Truncate the treatment mechanism at a fixed bound rather than the data-driven one:
>>> from cleverly import Targeting >>> Targeting(g_bounds=0.025).g_bounds 0.025
>>> Targeting().g_bounds 'auto'
Stop the targeting step by the
tmle3scaled_varrule instead of the shipped relative score:>>> Targeting(stopping="scaled_var").stopping 'scaled_var'