Sinkorn solver (standard)

class MultiScaleOT.TSinkhornSolverBase

This is an abstract base class for the specialized SinkhornSolver classes. It does not expose a constructor to the user but its methods are inherited by all specialized Sinkhorn solver classes.

absorb(self: MultiScaleOT.TSinkhornSolverBase) int

Absorb current values of scaling factors into dual variables and reset scaling factors to 1. After calling this, one should usually set kernelValid to false.

changeEps(self: MultiScaleOT.TSinkhornSolverBase, newEps: float) int

Set current epsilon. Experimental.

changeLayer(self: MultiScaleOT.TSinkhornSolverBase, newLayer: int) int

Set current layer. Experimental.

checkAbsorb(self: MultiScaleOT.TSinkhornSolverBase, maxValue: float) int

Tests whether values of the scaling factors exceed maxValue. If so, an absorption and subsequent kernel computation are recommended.

Parameters:

maxValue – threshold for scaling factors

Returns:

  • 1 if maxValue is exceeded

  • 0 otherwise

  • other values indicate an error

property errorGoal

Double. Target accuracy for stopping the Sinkhorn algorithm.

generateKernel(self: MultiScaleOT.TSinkhornSolverBase) int

Recompute truncated kernel matrix based on current dual variables.

getEps(self: MultiScaleOT.TSinkhornSolverBase) float

Return current value of epsilon.

getError(self: MultiScaleOT.TSinkhornSolverBase) float

Return current error (used as stopping criterion).

getLayer(self: MultiScaleOT.TSinkhornSolverBase) int

Return current layer index.

initialize(self: MultiScaleOT.TSinkhornSolverBase) int

Must be called after constructor before any other methods.

iterate(self: MultiScaleOT.TSinkhornSolverBase, n: int) int

Perform n iterations.

property kernelValid

Boolean. Is the currently stored kernel object valid (e.g. was epsilon changed or have absorbed dual variables changed since last computation). Experimental. Only experts should modify this.

refineDuals(self: MultiScaleOT.TSinkhornSolverBase, newLayer: int) int

Refines duals from coarse layer <newLayer-1> to <newLayer>. Experimental.

solve(self: MultiScaleOT.TSinkhornSolverBase) int

Run the full main algorithm to solve the problem.

solveLayer(self: MultiScaleOT.TSinkhornSolverBase) int

Solve over epsilon list at current layer. Experimental.

solveSingle(self: MultiScaleOT.TSinkhornSolverBase) int

Solve for current epsilon at current layer. Experimental.

class MultiScaleOT.TSinkhornSolverStandard

Solver class for standard entropic optimal transport problems with fixed marginal constraints.

__init__(self: MultiScaleOT.TSinkhornSolverStandard, epsScalingHandler: MultiScaleOT.TEpsScalingHandler, layerCoarsest: int, layerFinest: int, errorGoal: float, MultiScaleSetupX: MultiScaleOT.TMultiScaleSetup, MultiScaleSetupY: MultiScaleOT.TMultiScaleSetup, costProvider: MultiScaleOT.THierarchicalCostFunctionProvider, cfg: MultiScaleOT.TSinkhornSolverParameters = <MultiScaleOT.TSinkhornSolverParameters object at 0x7aa40c5ff7b0>) None
Parameters:
  • epsScalingHandler – instance of TEpsScalingHandler to control epsilon schedule

  • layerCoarsest – coarsest layer at which to start solving

  • layerFinest – finest layer that should be solved

  • errorGoal – the primary stopping criterion is reaching this threshold

  • MultiScaleSetupX – TMultiScaleSetup instance describing first marginal

  • MultiScaleSetupY – TMultiScaleSetup instance describing second marginal

  • costProvider – THierarchicalCostFunctionProvider instance describing the cost function

  • cfg – TSinkhornSolverParameters (optional, default values will be used if omitted)

findKernelLine(self: MultiScaleOT.TSinkhornSolverStandard, layerFinest: int, a: int, mode: int, slack: float) tuple
Parameters:
  • layerFinest – index of desired layer

  • a – index of kernel line to be determined

  • mode – 0: rows, 1: columns

  • slack – threshold below maximal value up to which entries are included

Returns:

A tuple of an int32 array and a double array, containing indices and effective cost values of dominating kernel entries.

getKernel(self: MultiScaleOT.TSinkhornSolverStandard) MultiScaleOT.TKernelMatrix

Return a TKernelMatrix object holding the current stabilized kernel.

getKernelCSRData(self: MultiScaleOT.TSinkhornSolverStandard) MultiScaleOT.TSparseCSRContainer

Returns a TSparseCSRContainer object containing the non-zero stabilized kernel entries in sparse CSR format.

getKernelCSRDataTuple(self: MultiScaleOT.TSinkhornSolverStandard) tuple

Returns a tuple of numpy arrays (data,indices,indptr) of types (float64,int32,int32) containing the non-zero stabilized kernel entries in sparse CSR format (see scipy.sparse.csr_matrix).

getKernelEntryCount(self: MultiScaleOT.TSinkhornSolverStandard) int

Returns number of non-zero entries in current stabilized kernel.

getKernelPosData(self: MultiScaleOT.TSinkhornSolverStandard) MultiScaleOT.TSparsePosContainer

Returns a TSparsePosContainer object containing the non-zero stabilized kernel entries in sparse POS format.

getKernelPosDataTuple(self: MultiScaleOT.TSinkhornSolverStandard) tuple

Returns a tuple of numpy arrays (mass,posStart,posEnd) of types (float64,int32,int32) containing the non-zero stabilized kernel entries in sparse POS format (mass values, row indices, column indices, see also scipy.sparse.coo_matrix).

getMarginalX(self: MultiScaleOT.TSinkhornSolverStandard) numpy.ndarray[numpy.float64]

Return 1st marginal of current coupling.

getMarginalY(self: MultiScaleOT.TSinkhornSolverStandard) numpy.ndarray[numpy.float64]

Return 1st marginal of current coupling.

getScorePrimalUnreg(self: MultiScaleOT.TSinkhornSolverStandard) float

Return current primal cost without the entropy term (only transport term and marginal discrepancies in unbalanced cases).

getScoreTransportCost(self: MultiScaleOT.TSinkhornSolverStandard) float

Return transport cost of current coupling (i.e. integral of coupling against cost function on product space.

getU(self: MultiScaleOT.TSinkhornSolverStandard) numpy.ndarray[numpy.float64]
getV(self: MultiScaleOT.TSinkhornSolverStandard) numpy.ndarray[numpy.float64]
setFixDuals(self: MultiScaleOT.TSinkhornSolverStandard, arg0: bool) None
setSafeCTransform(self: MultiScaleOT.TSinkhornSolverStandard, arg0: bool) None
setSafeMode(self: MultiScaleOT.TSinkhornSolverStandard, arg0: bool) None
setU(self: MultiScaleOT.TSinkhornSolverStandard, v: numpy.ndarray[numpy.float64]) None
setV(self: MultiScaleOT.TSinkhornSolverStandard, v: numpy.ndarray[numpy.float64]) None