trplearn.trpalg module#

class trplearn.trpalg.Manipulation(data)[source]#

Bases: object

Basic common manipulation for TropicalAlgebra classes.

property T#

Getting the transposed array.

property ndim#

Number of array dimensions.

to_list()[source]#

Convert to the python native list.

to_numpy()[source]#

Convert to the numpy array.

class trplearn.trpalg.MaxPlus(data)[source]#

Bases: TropicalAlgebra, Manipulation

Max-plus double semiring.

Max-plus double semiring is the following algebraic system: \((\mathbb{R}\cup{\pm\infty},-\infty,0,\max,+, +\infty,0,\min,+,-a)\), where set, zero, unit, add, mult, dualzero, dualunit, dualadd, dualmult, conjugate, from left to right.

Parameters:

data (array-like) – An array.

property C#

Getting the conjugation array.

Returns:

The conjugate of the current MaxPlus object.

Return type:

MaxPlus

property H#

Getting the Hermitian array.

Returns:

The Hermitian of the current MaxPlus object.

Return type:

MaxPlus

add(other)[source]#

Max-plus addition defined by \(a\oplus b=\max(a,b)\).

Parameters:

other (int, float, MaxPlus) – Addition.

Returns:

Result of max-plus addition by other.

Return type:

MaxPlus

Examples

>>> a = MaxPlus(3)
>>> b = MaxPlus(5)
>>> a.add(b)
MaxPlus(5)
>>> c = MaxPlus([1, 5, 3])
>>> d = MaxPlus([4, 2, 6])
>>> c.add(d)
MaxPlus([4 5 6])
>>> A = MaxPlus([[1, 3], [5, 7]])
>>> B = MaxPlus([[2, 6], [4, 8]])
>>> A.add(B)
MaxPlus([[2 6]
         [5 8]])
dot(other)[source]#

Max-plus matrix multiplication.

Parameters:

other (MaxPlus) – The matrix to multiply with.

Returns:

Result of max-plus matrix multiplication.

Return type:

MaxPlus

dualadd(other)[source]#

Max-plus dual-addition defined by \(a\ominus b=\min(a,b)\).

Parameters:

other (int, float, MaxPlus) – Dual-addition.

Returns:

Result of max-plus dual-addition by other.

Return type:

MaxPlus

dualdot(other)[source]#

Max-plus dual matrix multiplication.

Parameters:

other (MaxPlus) – The matrix to multiply with.

Returns:

Result of max-plus dual matrix multiplication.

Return type:

MaxPlus

dualmult(other)[source]#

Max-plus dual-multiplication (same as multiplication).

Parameters:

other (int, float, MaxPlus) – Dual-multiplication.

Returns:

Result of max-plus dual-multiplication by other.

Return type:

MaxPlus

dualpow(n)[source]#

Max-plus dual matrix power.

Parameters:

n (int) – The power to raise the matrix to.

Returns:

Result of max-plus dual matrix power.

Return type:

MaxPlus

Raises:

ValueError – If n is negative.

mult(other)[source]#

Max-plus multiplication defined by \(a\otimes b=a+b\).

Parameters:

other (int, float, MaxPlus) – Multiplication.

Returns:

Result of max-plus multiplication by other.

Return type:

MaxPlus

pow(n)[source]#

Max-plus matrix power.

Parameters:

n (int) – The power to raise the matrix to.

Returns:

Result of max-plus matrix power.

Return type:

MaxPlus

Raises:

ValueError – If n is negative.

star()[source]#

Compute the Kleene star (closure) of the matrix. For MaxPlus, this represents the all-pairs longest path matrix.

Returns:

The Kleene star of the current matrix.

Return type:

MaxPlus

class trplearn.trpalg.MinPlus(data)[source]#

Bases: TropicalAlgebra, Manipulation

Min-plus double semiring.

Min-plus double semiring is the following algebraic system: \((\mathbb{R}\cup{\pm\infty},+\infty,0,\min,+, -\infty,0,\max,+,-a)\), where set, zero, unit, add, mult, dualzero, dualunit, dualadd, dualmult, conjugate, from left to right.

Parameters:

data (array-like) – An array.

property C#

Getting the conjugation array.

Returns:

The conjugate of the current MinPlus object.

Return type:

MinPlus

property H#

Getting the Hermitian array.

Returns:

The Hermitian of the current MinPlus object.

Return type:

MinPlus

add(other)[source]#

Min-plus addition defined by \(a\oplus b=\min(a,b)\).

Parameters:

other (int, float, MinPlus) – Addition.

Returns:

Result of min-plus addition by other.

Return type:

MinPlus

Examples

>>> a = MinPlus(3)
>>> b = MinPlus(5)
>>> a.add(b)
MinPlus(3)
>>> c = MinPlus([1, 5, 3])
>>> d = MinPlus([4, 2, 6])
>>> c.add(d)
MinPlus([1 2 3])
>>> A = MinPlus([[1, 3], [5, 7]])
>>> B = MinPlus([[2, 6], [4, 8]])
>>> A.add(B)
MinPlus([[1 3]
         [4 7]])
dot(other)[source]#

Min-plus matrix multiplication.

Parameters:

other (MinPlus) – The matrix to multiply with.

Returns:

Result of min-plus matrix multiplication.

Return type:

MinPlus

dualadd(other)[source]#

Min-plus dual-addition defined by \(a\ominus b=\max(a,b)\).

Parameters:

other (int, float, MinPlus) – Dual-addition.

Returns:

Result of min-plus dual-addition by other.

Return type:

MinPlus

dualdot(other)[source]#

Min-plus dual matrix multiplication.

Parameters:

other (MinPlus) – The matrix to multiply with.

Returns:

Result of min-plus dual matrix multiplication.

Return type:

MinPlus

dualmult(other)[source]#

Min-plus dual-multiplication (same as multiplication).

Parameters:

other (int, float, MinPlus) – Dual-multiplication.

Returns:

Result of min-plus dual-multiplication by other.

Return type:

MinPlus

dualpow(n)[source]#

Min-plus dual matrix power.

Parameters:

n (int) – The power to raise the matrix to.

Returns:

Result of min-plus dual matrix power.

Return type:

MinPlus

Raises:

ValueError – If n is negative.

mult(other)[source]#

Min-plus multiplication defined by \(a\otimes b=a+b\).

Parameters:

other (int, float, MinPlus) – Multiplication.

Returns:

Result of min-plus multiplication by other.

Return type:

MinPlus

pow(n)[source]#

Min-plus matrix power.

Parameters:

n (int) – The power to raise the matrix to.

Returns:

Result of min-plus matrix power.

Return type:

MinPlus

Raises:

ValueError – If n is negative.

star()[source]#

Compute the Kleene star (closure) of the matrix. For MinPlus, this represents the all-pairs shortest path matrix.

Returns:

The Kleene star of the current matrix.

Return type:

MinPlus

class trplearn.trpalg.TropicalAlgebra(data)[source]#

Bases: ABC

Tropical algebra abstract base class.

abstract property C#
abstract property H#
abstractmethod add(other)[source]#
abstractmethod dot(other)[source]#
abstractmethod dualadd(other)[source]#
abstractmethod dualdot(other)[source]#
abstractmethod dualmult(other)[source]#
abstractmethod dualpow(n)[source]#
abstractmethod mult(other)[source]#
abstractmethod pow(n)[source]#