Library Reference

Generic API

Semirings.SemiringType
Semiring{T}

Abstract Semiring type. T is the type of the value wrapped by the semiring structure (e.g. Float32, Bool, ...).

source
Base.valtypeMethod
valtype(x::Semiring{T})
valtype(::Type{<:Semiring{T}}) where T

Return the type T of the value wrapped by the semiring.

source
Base.parseMethod
parse(S::Type{<:Semiring{T}}, str) where T

Return S(parse(T, str)).

source
Base.zeroMethod
zero(::Semiring)
zero(::Type{<:Semiring})

Return the additive neutral element of the semiring $\bar{0}$.

source
Base.oneMethod
one(::Semiring)
one(::Type{<:Semiring})

Return the multiplicative neutral element of the semiring $\bar{1}$.

source
Base.:+Method
+(x::S, y::S) where S<:Semiring
x + y

Return $x \oplus y$ for the semiring S.

source
Base.:*Method
*(x::S, y::S) where S<:Semiring
x + y

Return $x \otimes y$ for the semiring S.

source
Base.:*Method
*(n::Integer, x::Semiring)
n * x
x * n

Return the n-times repeated addition $x \oplus x \oplus ...$.

source
Base.invMethod
inv(x::Semiring)

If defined, return the multiplicative inverse of x. Not implemented for semiring type that does not support multiplicative inverse.

source

Automatic Differentiation API

Semirings.∂sumFunction
∂sum(u::S, x::S) where S<:Semiring

Compute $\frac{\partial u}{\partial x}$ where $u = x \oplus y \oplus z \oplus ...$.

Warning

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.

source
Semirings.∂rmulFunction
∂rmul(x::S, a::S) where S<:Semiring

Compute $\frac{\partial u}{\partial x}$ where $u = x \otimes a$.

source
Semirings.∂lmulFunction
∂lmul(a::S, x::S) where S<:Semiring

Compute $\frac{\partial u}{\partial x}$ where $u = a \otimes x$.

source

Concrete Semirings

Semirings.BoolSemiringType
BoolSemiring <: 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.

source
Semirings.ExpectationSemiringType
ExpectationSemiring{T<:AbstractFloat,F} <: Semiring{T}

Expectation semiring: $( (\mathbb{R}_+, \mathbb{R}), +, \cdot, (0, 0), (1, 0) )$.

source
Semirings.LogSemiringType
LogSemiring{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} ).\]

Info

The logarithmic semiring defined in OpenFst corresponds to LogSemiring{<:AbstractFloat,-1}.

source

Morphisms

Base.expMethod
exp(x::LogSemiring{T,1})::ProbSemiring{T}

Exponential morphism of the log-semiring.

See also Base.log.

source
Base.logMethod
log(x::ProbSemiring{T})::LogSemiring{T,1}

Logarithm morphism of the probaility semiring.

See also Base.exp.

source