cotOptions: Options available for the COT method

View source: R/cotClass.R

cotOptionsR Documentation

Options available for the COT method

Description

Options available for the COT method

Usage

cotOptions(
  lambda = "auto",
  delta = NULL,
  opt.direction = deprecated(),
  dual.solver = c("fixed_point_joint", "joint", "entropy", "fixed_point"),
  debias = TRUE,
  solver = c("fixed_point", "lbfgs", "mirror"),
  polish = c("auto", "none"),
  p = 2,
  cost.function = NULL,
  cost.online = "auto",
  diameter = NULL,
  balance.formula = NULL,
  quick.balance.function = TRUE,
  grid.length = 7L,
  torch.optimizer = torch::optim_rmsprop,
  torch.scheduler = torch::lr_multiplicative,
  niter = 500L,
  nboot = 100L,
  lambda.bootstrap = 0.05,
  lambda.selector = c("auto", "bootstrap"),
  lambda.selector.control = list(),
  tol = 1e-04,
  device = NULL,
  dtype = NULL,
  ...
)

Arguments

lambda

The entropy penalty in solver cost units. The default, "auto", selects one positive value before fitting by predicting binary treatment from pooled covariates. A numeric scalar or vector specifies fixed candidates and NULL fits a default grid. "auto" requires calc_weight(), uniform observation weights and a conditionally negative definite cost (built-in costs with p <= 2 or a qualifying custom cost); otherwise the default grid is fit and lambda.selector chooses among it. It searches the multiplier of the median off-diagonal solver cost using centered kernel ridge treatment prediction with the solver's Gibbs kernel exp(-C/lambda) (Gaussian RBF for p = 2), an unpenalized intercept and leave-one-out scoring, profiling nine ridge penalties. The full-data ridge penalty is held fixed for deletion. The result is the best evaluated score within a bounded search, not a global optimum. The default budget is 50 evaluations with at most two boundary expansions; scores within ⁠1e-10 * max(1, abs(best score))⁠ are tied in favor of larger multipliers. Selection evaluates solver costs on CPU in double precision, independently of the final fit's device and dtype, for stable spectral calculations. Each evaluation requires dense cubic-time linear algebra. Above 2000 rows a reproducible treatment-stratified subsample determines the cost scale and lambda, while final weights use all rows. Selection diagnostics are in weights@info$lambda_selection; set lambda.selector.control = list(details = TRUE) to retain the evaluation trace. Numeric lambda values remain in solver units; for squared Euclidean cost the median solver cost is half the median squared distance.

delta

The bound for balancing functions if they are being used. Only available for biased entropy penalized optimal transport. Can be a single number or a set of numbers to try.

opt.direction

[Deprecated] Use solver instead. Should the optimizer solve the primal or dual problems. One of "dual" or "primal".

dual.solver

Legacy solver selection when opt.direction = "dual". "fixed_point" selects the entropy-potential fixed-point solver; the legacy default "fixed_point_joint" is a different joint KL trainer. "joint" and "entropy" select the other legacy dual trainers.

debias

Should debiased optimal transport be used? TRUE or FALSE.

solver

Solver for COT weight optimization. "fixed_point" (the default) uses entropy-potential updates with Anderson acceleration and requires debiased transport without balance constraints. When omitted, balance constraints or debias = FALSE select "lbfgs" instead. "lbfgs" optimizes weights directly and "mirror" uses mirror descent.

polish

"auto" (the default) or "none". "auto" refines eligible fixed-point, L-BFGS, and mirror fits with one debiased weight problem and no balance constraints in float64. It skips refinement when the initial free set exceeds 2000 points. info()$polish reports the status and number of refinement iterations; convergence is reported in info()$converged and info()$reason. Fixed-point fits with "none" may stop at the iteration cap without a warning and retain their phase-1 convergence status.

p

The power of the cost function to use for the cost.

cost.function

A function to calculate the pairwise costs. Should take arguments x1, x2, and p. Default is NULL.

cost.online

Should an online cost algorithm be used? One of "auto", "online", or "tensorized". "tensorized" is the offline option.

diameter

The diameter of the covariate space, if known. Default is NULL.

balance.formula

Formula for the balancing functions.

quick.balance.function

TRUE or FALSE denoting whether balance function constraints should be selected via a linear program (TRUE) or just checked for feasibility (FALSE). Default is TRUE.

grid.length

The number of penalty parameters to explore in a grid search if none are provided in arguments lambda or delta.

torch.optimizer

The torch optimizer to use for methods using debiased entropy penalized optimal transport. If debiased is FALSE or opt.direction is "primal", will default to torch::optim_lbfgs(). Otherwise torch::optim_rmsprop() is used for the dual potential block. Joint dual solvers use an internal RMSprop optimizer for the trainable log-weight block.

torch.scheduler

The scheduler for the optimizer. Defaults to torch::lr_multiplicative() for RMSprop-based dual solvers and torch::lr_reduce_on_plateau() for LBFGS.

niter

The maximum number of solver iterations (default 500).

nboot

The number of iterations for the bootstrap to select the final penalty parameters.

lambda.bootstrap

The penalty parameter to use for the bootstrap hyperparameter selection of lambda.

lambda.selector

How to select lambda among a fitted grid. The default, "auto", scores the positive finite candidates by pooled binary-label prediction, without refitting. Grid ATE uses one score and a candidate usable by both arm fits. "bootstrap" is the bootstrap selector used in previous versions of the package, controlled by nboot and lambda.bootstrap. "auto" uses "bootstrap" when its own rule does not apply (non-uniform weights, a cost that is not conditionally negative definite, or no finite positive candidate) and records why in weights@info$metric$lambda.note.

lambda.selector.control

Optional list of controls for lambda selection. The only entry is details; TRUE keeps the evaluation trace of the "auto" search.

tol

Relative tolerance for final fit convergence (default 1e-4), shared by phase 1 and polish: gap <= atol + tol * max(0, D), where D is the debiased divergence. Unpolished fits use atol = ot_tol (default 1e-3) and must stop normally rather than reach niter. Thus unpolished converged means accurate to about ot_tol in absolute terms; when D is much smaller than ot_tol, even a large gap/D can pass. Lower ot_tol for more phase-1 accuracy, or use the polish for tol relative accuracy. Polished fits use atol = 64 * eps64 * scale plus 16 times the polish's Sinkhorn tolerance (1e-13), where scale is the cost scale, regardless of phase-1 iteration caps. ot_tol is also the inner Sinkhorn tolerance: iterations stop once the largest change in the potentials is below ot_tol * lambda, that is, once the log marginal violation is below ot_tol.

device

An object of class torch_device denoting which device the data will be located on. Default is NULL, which uses the CPU. Pass torch::torch_device("cuda") or torch::torch_device("mps") to use a GPU.

dtype

An object of class torch_dtype that determines data type of the data, i.e. double, float, integer. Default is NULL which will try to select for you.

...

Arguments passed to the solvers. See details. Named arguments not used by any solver produce a warning. For dual.solver = "fixed_point", these include fixed_point_update ("anderson" or "momentum"), fixed_point_eta (default 1), fixed_point_beta (default 0.9), anderson_m (default 5), check_every (default 50), and fixed_point_lambda_order ("ascending", the default, or "descending"). fixed_point_warm_start_mix (default 1) is the fraction of uniform mass mixed into the incoming weights before the entropy potential is rebuilt when more iterations are needed. The default 1 restarts each lambda from uniform weights; values below 1 keep part of the previous solution. Each new lambda first checks the incoming weights and returns them exactly if they already pass the gap test.

Value

A list of class cotOptions with the following slots

  • lambdaThe penalty parameter for the optimal transport distance

  • deltaThe constraint for the balancing functions

  • opt.direction Whether to solve the primal or dual optimization problems

  • dual.solver Solver used for dual optimization problems.

  • solver Solver used for the selected optimization direction.

  • debiasTRUE or FALSE if debiased optimal transport distances are used

  • balance.formula The formula giving how to generate the balancing functions.

  • quick.balance.function TRUE or FALSE whether quick balance functions will be run.

  • grid.length The number of parameters to check in a grid search of best parameters

  • p The power of the cost function

  • cost.online Whether online costs are used

  • cost.function The user supplied cost function if supplied.

  • diameter The diameter of the covariate space.

  • torch.optimizer The torch optimizer used for Sinkhorn Divergences

  • torch.scheduler The scheduler for the torch optimizer

  • solver.options The arguments to be passeed to the torch.optimizer

  • scheduler.options The arguments to be passeed to the torch.scheduler

  • osqp.options Arguments passed to the osqp function if quick balance functions are used.

  • niter The number of iterations to run the solver

  • nboot The number of bootstrap samples

  • lambda.bootstrap The penalty parameter to use for the bootstrap hyperparameter selection.

  • lambda.selector The normalized lambda selection rule used after fitting the lambda grid.

  • lambda.selector.control The lambda selector control list.

  • tol The tolerance for convergence.

  • device An object of class torch_device.

  • dtype An object of class torch_dtype.

Solvers and distances

The function is setup to direct the COT optimizer to run two basic methods: debiased entropy penalized optimal transport (Sinkhorn Divergences) or entropy penalized optimal transport (Sinkhorn Distances).

Sinkhorn Distances

The optimal transport problem solved is min_w OT_\lambda(w,b) where

OT_\lambda(w,b) = \sum_{ij} C(x_i, x_j) P_{ij} + \lambda \sum_{ij} P_{ij}\log(P_{ij}),

such that the rows of the matrix P_{ij} sum to w and the columns sum to b. In this case C(,) is the cost between units i and j.

Sinkhorn Divergences

The Sinkhorn Divergence solves

min_w OT_\lambda(w,b) - 0.5 OT_\lambda(w,w) - 0.5 * OT_\lambda(b,b).

The solver for this function uses the torch package in R. Dual solvers default to optim_rmsprop for the potential block. Joint dual solvers additionally use an internal RMSprop optimizer for the trainable log-weight block. Your desired torch optimizer can be passed via torch.optimizer with a scheduler passed via torch.scheduler. GPU support is available as detailed in the torch package. Additional arguments in ... are passed as extra arguments to the torch optimizer and schedulers as appropriate.

Function balancing

There may be certain functions of the covariates that we wish to balance within some tolerance, \delta. For these functions B, we will desire

\frac{\sum_{i: Z_i = 0} w_i B(x_i) - \sum_{j: Z_j = 1} B(x_j)/n_1}{\sigma} \leq \delta

, where in this case we are targeting balance with the treatment group for the ATT. \sigma is the pooled standard deviation prior to balancing.

Cost functions

The cost function specifies pairwise distances. If argument cost.function is NULL, the function will default to using L_p^p distances with a default p = 2 supplied by the argument p. So for p = 2, the cost between units x_i and x_j will be

C(x_i, x_j) = \frac{1}{2} \| x_i - x_j \|_2^2.

If cost.function is provided, it should be a function that takes arguments x1, x2, and p: function(x1, x2, p){...}.

Examples

if ( torch::torch_is_installed()) {
opts1 <- cotOptions(lambda = 1e3, torch.optimizer = torch::optim_rmsprop)
opts2 <- cotOptions(lambda = NULL)
opts3 <- cotOptions(lambda = seq(0.1, 100, length.out = 7))
opts4 <- cotOptions(lambda = "auto")
}

causalOT documentation built on Nov. 24, 2026, 1:06 a.m.