OTNetworkSimplex {SBCK} | R Documentation |
Optimal Transport Network Simplex solver
Description
Solve the optimal transport problem with the package 'transport'
Details
use the network simplex algorithm
Public fields
p
[double] Power of the plan
plan
[matrix] transport plan
success
[bool] If the fit is a success or not
C
[matrix] Cost matrix
Methods
Public methods
Method new()
Create a new OTNetworkSimplex object.
Usage
OTNetworkSimplex$new(p = 2)
Arguments
p
[double] Power of the plan
Returns
A new 'OTNetworkSimplex' object.
Method fit()
Fit the OT plan
Usage
OTNetworkSimplex$fit(muX0, muX1, C = NULL)
Arguments
muX0
[SparseHist or OTHist] Source histogram to move
muX1
[SparseHist or OTHist] Target histogram
C
[matrix or NULL] Cost matrix (without power p) between muX0 and muX1, if NULL pairwise_distances is called with Euclidean distance.
Returns
NULL
Method clone()
The objects of this class are cloneable with this method.
Usage
OTNetworkSimplex$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
References
Bazaraa, M. S., Jarvis, J. J., and Sherali, H. D.: Linear Programming and Network Flows, 4th edn., John Wiley & Sons, 2009.
Examples
## Define two dataset
X = stats::rnorm(2000)
Y = stats::rnorm(2000 , mean = 5 )
bw = base::c(0.1)
muX = SBCK::SparseHist( X , bw )
muY = SBCK::SparseHist( Y , bw )
## Find solution
ot = OTNetworkSimplex$new()
ot$fit( muX , muY )
print( sum(ot$plan) ) ## Must be equal to 1
print( ot$success ) ## If solve is success
print( sqrt(sum(ot$plan * ot$C)) ) ## Cost of plan