50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

SBCK (version 1.0.0)

OTNetworkSimplex: Optimal Transport Network Simplex solver

Description

Solve the optimal transport problem with the package 'transport'

Arguments

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


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.

Details

use the network simplex algorithm

References

Bazaraa, M. S., Jarvis, J. J., and Sherali, H. D.: Linear Programming and Network Flows, 4th edn., John Wiley & Sons, 2009.

Examples

Run this code
## 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

Run the code above in your browser using DataLab