MCPcopy Create free account
hub / github.com/PythonOT/POT / semirelaxed_cg

Function semirelaxed_cg

ot/optim.py:541–666  ·  view source on GitHub ↗

r""" Solve the general regularized and semi-relaxed OT problem with conditional gradient The function solves the following optimization problem: .. math:: \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F + \mathrm{reg} \cdot f(\gamma)

(
    a,
    b,
    M,
    reg,
    f,
    df,
    G0=None,
    line_search=None,
    numItermax=200,
    stopThr=1e-9,
    stopThr2=1e-9,
    verbose=False,
    log=False,
    nx=None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

539
540
541def semirelaxed_cg(
542 a,
543 b,
544 M,
545 reg,
546 f,
547 df,
548 G0=None,
549 line_search=None,
550 numItermax=200,
551 stopThr=1e-9,
552 stopThr2=1e-9,
553 verbose=False,
554 log=False,
555 nx=None,
556 **kwargs,
557):
558 r"""
559 Solve the general regularized and semi-relaxed OT problem with conditional gradient
560
561 The function solves the following optimization problem:
562
563 .. math::
564 \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F +
565 \mathrm{reg} \cdot f(\gamma)
566
567 s.t. \ \gamma \mathbf{1} &= \mathbf{a}
568
569 \gamma &\geq 0
570
571 where :
572
573 - :math:`\mathbf{M}` is the (`ns`, `nt`) metric cost matrix
574 - :math:`f` is the regularization term (and `df` is its gradient)
575 - :math:`\mathbf{a}` and :math:`\mathbf{b}` are source and target weights (sum to 1)
576
577 The algorithm used for solving the problem is conditional gradient as discussed in :ref:`[1] <references-cg>`
578
579
580 Parameters
581 ----------
582 a : array-like, shape (ns,)
583 samples weights in the source domain
584 b : array-like, shape (nt,)
585 currently estimated samples weights in the target domain
586 M : array-like, shape (ns, nt)
587 loss matrix
588 reg : float
589 Regularization term >0
590 G0 : array-like, shape (ns,nt), optional
591 initial guess (default is indep joint density)
592 line_search: function,
593 Function to find the optimal step.
594 Default is None and calls a wrapper to line_search_armijo.
595 numItermax : int, optional
596 Max number of iterations
597 stopThr : float, optional
598 Stop threshold on the relative variation (>0)

Calls 2

get_backendFunction · 0.85

Tested by

no test coverage detected