skwdro package

Subpackages

Submodules

skwdro.torch module

skwdro.wrap_problem module

skwdro.wrap_problem.dualize_primal_loss(loss_: Module, transform_: Module | None, rho: Tensor, xi_batchinit: Tensor, xi_labels_batchinit: Tensor | None, post_sample: bool = True, cost_spec: str | None = None, n_samples: int = 10, seed: int = 42, *, epsilon: float | None = None, sigma: float | None = None, l2reg: float | None = None, adapt: str | None = 'prodigy', imp_samp: bool = True) _DualLoss[source]

Provide the wrapped version of the primal loss.

Parameters:
loss_: nn.Module

the primal loss

transform_: nn.Module

the transformation to apply to the data before feeding it to the loss

rho: Tensor, shape (n_samples,)

Wasserstein radius

xi_batchinit: Tensor, shape (n_samples, n_features)

Data points to initialize the samplers and \lambda_0

xi_labels_batchinit: Optional[Tensor], shape (n_samples, n_features)

Labels to initialize the samplers and \lambda_0

post_sample: bool

whether to use a post-sampled dual loss

cost_spec: str|None

the cost specification in the format (k, p) for a sample k-norm and p-power. None to use the default (2, 2).

n_samples: int

number of \zeta samples to draw before the gradient descent begins (can be changed if needed between inferences)

seed: int

the seed for the samplers

epsilon: float|None

Epsilon if hard coded, None to let the algo find it.

sigma: float|None

Sigma if hard coded, None to let the algo find it.

l2reg: float|None

L2 regularization if needed

adapt: str|None

the adaptative step to use between “prodigy” and “mechanic”.

imp_samp: bool

whether to use importance sampling (will work only for (2, 2) costs).

skwdro.wrap_problem.expert_hyperparams(rho: Tensor, p: float, epsilon: float | None, epsilon_sigma_factor: float, sigma: float | None, sigma_factor: float) Tuple[Tensor, Tensor][source]

Tuning of the hyperparameters for the dual loss.

Parameters:
rho: Tensor, shape (n_samples,)

Wasserstein radius

p: float

power of norm

epsilon: float

Epsilon if hard coded, None to let the algo find it.

epsilon_sigma_factor: float

Estimated ratio \frac{\epsilon}{\sigma}

sigma: float

Sigma if hard coded, None to let the algo find it.

sigma_factor: float

Estimated ratio \frac{\sigma}{\rho}

skwdro.wrap_problem.power_from_parsed_spec(parsed_spec: ParsedCost | None) float[source]

Module contents