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

Function compute_transport_plan

ot/regpath.py:915–982  ·  view source on GitHub ↗

r"""Given the regularization path, this function computes the transport plan for any value of gamma thanks to the piecewise linearity of the path. .. math:: t(\gamma) = \phi(\gamma) - \gamma \delta(\gamma) where: - :math:`\gamma` is the regularization parameter - :math

(gamma, gamma_list, Pi_list)

Source from the content-addressed store, hash-verified

913
914
915def compute_transport_plan(gamma, gamma_list, Pi_list):
916 r"""Given the regularization path, this function computes the transport
917 plan for any value of gamma thanks to the piecewise linearity of the path.
918
919 .. math::
920 t(\gamma) = \phi(\gamma) - \gamma \delta(\gamma)
921
922 where:
923
924 - :math:`\gamma` is the regularization parameter
925 - :math:`\phi(\gamma)` is the corresponding intercept
926 - :math:`\delta(\gamma)` is the corresponding slope
927 - :math:`\mathbf{t}` is the flattened version of the transport matrix
928
929 Parameters
930 ----------
931 gamma : float
932 Regularization coefficient
933 gamma_list : list
934 List of regularization parameters of the regularization path
935 Pi_list : list
936 List of all the solutions of the regularization path
937
938 Returns
939 -------
940 t : np.ndarray (dim_a*dim_b, )
941 Vectorization of the transport plan corresponding to the given value
942 of gamma
943
944 Examples
945 --------
946 >>> import ot
947 >>> import numpy as np
948 >>> n = 3
949 >>> xs = np.array([1., 2., 3.]).reshape((n, 1))
950 >>> xt = np.array([5., 6., 7.]).reshape((n, 1))
951 >>> C = ot.dist(xs, xt)
952 >>> C /= C.max()
953 >>> a = np.array([0.2, 0.5, 0.3])
954 >>> b = np.array([0.2, 0.5, 0.3])
955 >>> t, pi_list, g_list = ot.regpath.regularization_path(a, b, C, reg=1e-4)
956 >>> gamma = 1
957 >>> t2 = ot.regpath.compute_transport_plan(gamma, g_list, pi_list)
958 >>> t2
959 array([0. , 0. , 0. , 0.19722222, 0.05555556,
960 0. , 0. , 0.24722222, 0. ])
961
962
963 .. _references-regpath:
964 References
965 ----------
966 .. [41] Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
967 Unbalanced optimal transport through non-negative penalized
968 linear regression. NeurIPS.
969 """
970
971 if gamma >= gamma_list[0]:
972 Pi = Pi_list[0]

Callers

nothing calls this directly

Calls 1

whereMethod · 0.45

Tested by

no test coverage detected