Library Reference
Generic API
Semirings.Semiring
— TypeSemiring{T}
Abstract Semiring type. T
is the type of the value wrapped by the semiring structure (e.g. Float32, Bool, ...).
Semirings.val
— Functionval(x::Semiring)
Return the value wrapped by the semiring type
Base.valtype
— Methodvaltype(x::Semiring{T})
valtype(::Type{<:Semiring{T}}) where T
Return the type T
of the value wrapped by the semiring.
Base.parse
— Methodparse(S::Type{<:Semiring{T}}, str) where T
Return S(parse(T, str))
.
Base.zero
— Methodzero(::Semiring)
zero(::Type{<:Semiring})
Return the additive neutral element of the semiring $\bar{0}$.
Base.one
— Methodone(::Semiring)
one(::Type{<:Semiring})
Return the multiplicative neutral element of the semiring $\bar{1}$.
Base.:+
— Method+(x::S, y::S) where S<:Semiring
x + y
Return $x \oplus y$ for the semiring S
.
Base.:*
— Method*(x::S, y::S) where S<:Semiring
x + y
Return $x \otimes y$ for the semiring S
.
Base.:*
— Method*(n::Integer, x::Semiring)
n * x
x * n
Return the n
-times repeated addition $x \oplus x \oplus ...$.
Base.inv
— Methodinv(x::Semiring)
If defined, return the multiplicative inverse of x
. Not implemented for semiring type that does not support multiplicative inverse.
Automatic Differentiation API
Semirings.SemiringTangent
— TypeSemiringTangent{T} <: ChainRulesCore.AbstractTangent
Tangent type of semirings type.
Semirings.∂sum
— Function∂sum(u::S, x::S) where S<:Semiring
Compute $\frac{\partial u}{\partial x}$ where $u = x \oplus y \oplus z \oplus ...$.
This method is implemented only for semirings for which there is a morphism such that $\mu(u) = \mu(x) + \mu(y) + \mu(z) + ...$ where $+$ is the natural addition.
Semirings.∂rmul
— Function∂rmul(x::S, a::S) where S<:Semiring
Compute $\frac{\partial u}{\partial x}$ where $u = x \otimes a$.
Semirings.∂lmul
— Function∂lmul(a::S, x::S) where S<:Semiring
Compute $\frac{\partial u}{\partial x}$ where $u = a \otimes x$.
Concrete Semirings
Semirings.ArcticSemiring
— TypeArcticSemiring{T<:AbstractFloat} <: Semiring{T}
Arctic semiring: $( \mathbb{R} \cup \{\infty \}, \max, +, -\infty, 0 )$.
See also LogSemiring
and TropicalSemiring
.
Semirings.BoolSemiring
— TypeBoolSemiring <: Semiring{Bool}
Boolean semiring: $(\{\text{false}, \text{true} \}, \lor, \land, \text{false}, \text{true} )$ where $\lor$ and $\land$ are the logical "or" and logical "and operators.
Semirings.ExpectationSemiring
— TypeExpectationSemiring{T<:AbstractFloat,F} <: Semiring{T}
Expectation semiring: $( (\mathbb{R}_+, \mathbb{R}), +, \cdot, (0, 0), (1, 0) )$.
Semirings.LogSemiring
— TypeLogSemiring{T<:AbstractFloat,τ} <: Semiring{T}
Logarithmic semiring: $(\mathbb{R} \cup \{\text{sgn}(\tau) \cdot +\infty \}, \oplus_{\log}, +, -\infty, 0)$ where
\[x \oplus y = \frac{1}{\tau} \log ( e^{\tau x} + e^{\tau y} ).\]
The logarithmic semiring defined in OpenFst corresponds to LogSemiring{<:AbstractFloat,-1}
.
Semirings.TropicalSemiring
— TypeTropicalSemiring{T<:AbstractFloat} <: Semiring{T}
Tropical semiring: $(\mathbb{R} \cup \{- \infty \}, \min, +, \infty, 0)$.
See also LogSemiring
and ArcticSemiring
.
Morphisms
Base.exp
— Methodexp(x::LogSemiring{T,1})::ProbSemiring{T}
Exponential morphism of the log-semiring.
See also Base.log
.
Base.log
— Methodlog(x::ProbSemiring{T})::LogSemiring{T,1}
Logarithm morphism of the probaility semiring.
See also Base.exp
.