maxent-learner-hw-0.2.0: Hayes and Wilson's maxent learning algorithm for phonotactic grammars.

Copyright© 2016-2017 George Steel and Peter Jurgec
LicenseGPL-2+
Maintainergeorge.steel@gmail.com
Safe HaskellNone
LanguageHaskell2010

Text.PhonotacticLearner.Util.Ring

Contents

Description

This module provides a hierarchy of typeclasses to describe rings and their substructures without all of the additional structure found in Num (which does not apply to most rings). Num instances are automatically Ring instances if no explicit instance is given, making Ring a drop-in replacenent for Num to make more generic functions.

A typeclass for algebraic modules (aka. vector spaces if over a field) is also included as well as a data type for the vector space ℝ[x]=ℝ∪ℝ²∪ℝ³∪… (usable for ℝⁿ although dimensions are not checked).

In order to not clash with Num or Arrow, this module uses the unicode circled operators '⊕', '⊖', '⊗', and '⊙'. If you are using XIM (Linux) or WinCompose, add the following lines to your .XCompose file:

<Multi_key> <r> <plus> : "⊕"
<Multi_key> <r> <period> : "⊙"
<Multi_key> <r> <asterisk> : "⊗"
<Multi_key> <r> <minus> : "⊖"

Synopsis

Rings

class Additive g where Source #

Monoids with additive syntax

Minimal complete definition

zero, (⊕)

Methods

zero :: g Source #

(⊕) :: g -> g -> g Source #

Instances

Additive Bool Source # 

Methods

zero :: Bool Source #

(⊕) :: Bool -> Bool -> Bool Source #

Additive () Source # 

Methods

zero :: () Source #

(⊕) :: () -> () -> () Source #

Num r => Additive r Source # 

Methods

zero :: r Source #

(⊕) :: r -> r -> r Source #

Additive Vec Source # 

Methods

zero :: Vec Source #

(⊕) :: Vec -> Vec -> Vec Source #

Additive r => Additive (RProd r) Source # 

Methods

zero :: RProd r Source #

(⊕) :: RProd r -> RProd r -> RProd r Source #

Additive r => Additive (RSum r) Source # 

Methods

zero :: RSum r Source #

(⊕) :: RSum r -> RSum r -> RSum r Source #

RingModule Double v => Additive (Expectation v) Source # 
(Additive r, Additive s) => Additive (r, s) Source # 

Methods

zero :: (r, s) Source #

(⊕) :: (r, s) -> (r, s) -> (r, s) Source #

class Additive g => AdditiveGroup g where Source #

Additive groups with inverses and suntraction

Minimal complete definition

addinv

Methods

addinv :: g -> g Source #

(⊖) :: g -> g -> g Source #

Instances

AdditiveGroup () Source # 

Methods

addinv :: () -> () Source #

(⊖) :: () -> () -> () Source #

Num r => AdditiveGroup r Source # 

Methods

addinv :: r -> r Source #

(⊖) :: r -> r -> r Source #

AdditiveGroup Vec Source # 

Methods

addinv :: Vec -> Vec Source #

(⊖) :: Vec -> Vec -> Vec Source #

AdditiveGroup r => AdditiveGroup (RProd r) Source # 

Methods

addinv :: RProd r -> RProd r Source #

(⊖) :: RProd r -> RProd r -> RProd r Source #

AdditiveGroup r => AdditiveGroup (RSum r) Source # 

Methods

addinv :: RSum r -> RSum r Source #

(⊖) :: RSum r -> RSum r -> RSum r Source #

(AdditiveGroup r, AdditiveGroup s) => AdditiveGroup (r, s) Source # 

Methods

addinv :: (r, s) -> (r, s) Source #

(⊖) :: (r, s) -> (r, s) -> (r, s) Source #

class Additive r => Semiring r where Source #

Semirings with addition and multiplication (but not subtraction).

Minimal complete definition

one, (⊗)

Methods

one :: r Source #

(⊗) :: r -> r -> r Source #

Instances

Semiring Bool Source # 

Methods

one :: Bool Source #

(⊗) :: Bool -> Bool -> Bool Source #

Semiring () Source # 

Methods

one :: () Source #

(⊗) :: () -> () -> () Source #

Num r => Semiring r Source # 

Methods

one :: r Source #

(⊗) :: r -> r -> r Source #

Semiring r => Semiring (RProd r) Source # 

Methods

one :: RProd r Source #

(⊗) :: RProd r -> RProd r -> RProd r Source #

Semiring r => Semiring (RSum r) Source # 

Methods

one :: RSum r Source #

(⊗) :: RSum r -> RSum r -> RSum r Source #

RingModule Double v => Semiring (Expectation v) Source # 
(Semiring r, Semiring s) => Semiring (r, s) Source # 

Methods

one :: (r, s) Source #

(⊗) :: (r, s) -> (r, s) -> (r, s) Source #

class (Semiring r, AdditiveGroup r) => Ring r Source #

Rings have both subtraction and multiplication

Instances

Ring () Source # 
Num r => Ring r Source # 
Ring r => Ring (RProd r) Source # 
Ring r => Ring (RSum r) Source # 
(Ring r, Ring s) => Ring (r, s) Source # 

newtype RSum r Source #

Monoid wrapper using addition, same as Sum

Constructors

RSum r 

Instances

Eq r => Eq (RSum r) Source # 

Methods

(==) :: RSum r -> RSum r -> Bool #

(/=) :: RSum r -> RSum r -> Bool #

Ord r => Ord (RSum r) Source # 

Methods

compare :: RSum r -> RSum r -> Ordering #

(<) :: RSum r -> RSum r -> Bool #

(<=) :: RSum r -> RSum r -> Bool #

(>) :: RSum r -> RSum r -> Bool #

(>=) :: RSum r -> RSum r -> Bool #

max :: RSum r -> RSum r -> RSum r #

min :: RSum r -> RSum r -> RSum r #

Show r => Show (RSum r) Source # 

Methods

showsPrec :: Int -> RSum r -> ShowS #

show :: RSum r -> String #

showList :: [RSum r] -> ShowS #

Additive r => Monoid (RSum r) Source # 

Methods

mempty :: RSum r #

mappend :: RSum r -> RSum r -> RSum r #

mconcat :: [RSum r] -> RSum r #

Ring r => Ring (RSum r) Source # 
Semiring r => Semiring (RSum r) Source # 

Methods

one :: RSum r Source #

(⊗) :: RSum r -> RSum r -> RSum r Source #

AdditiveGroup r => AdditiveGroup (RSum r) Source # 

Methods

addinv :: RSum r -> RSum r Source #

(⊖) :: RSum r -> RSum r -> RSum r Source #

Additive r => Additive (RSum r) Source # 

Methods

zero :: RSum r Source #

(⊕) :: RSum r -> RSum r -> RSum r Source #

newtype RProd r Source #

Monoid wrapper using multiplication, same as Product

Constructors

RProd r 

Instances

Eq r => Eq (RProd r) Source # 

Methods

(==) :: RProd r -> RProd r -> Bool #

(/=) :: RProd r -> RProd r -> Bool #

Ord r => Ord (RProd r) Source # 

Methods

compare :: RProd r -> RProd r -> Ordering #

(<) :: RProd r -> RProd r -> Bool #

(<=) :: RProd r -> RProd r -> Bool #

(>) :: RProd r -> RProd r -> Bool #

(>=) :: RProd r -> RProd r -> Bool #

max :: RProd r -> RProd r -> RProd r #

min :: RProd r -> RProd r -> RProd r #

Show r => Show (RProd r) Source # 

Methods

showsPrec :: Int -> RProd r -> ShowS #

show :: RProd r -> String #

showList :: [RProd r] -> ShowS #

Semiring r => Monoid (RProd r) Source # 

Methods

mempty :: RProd r #

mappend :: RProd r -> RProd r -> RProd r #

mconcat :: [RProd r] -> RProd r #

Ring r => Ring (RProd r) Source # 
Semiring r => Semiring (RProd r) Source # 

Methods

one :: RProd r Source #

(⊗) :: RProd r -> RProd r -> RProd r Source #

AdditiveGroup r => AdditiveGroup (RProd r) Source # 

Methods

addinv :: RProd r -> RProd r Source #

(⊖) :: RProd r -> RProd r -> RProd r Source #

Additive r => Additive (RProd r) Source # 

Methods

zero :: RProd r Source #

(⊕) :: RProd r -> RProd r -> RProd r Source #

sumR :: (Foldable f, Additive r) => f r -> r Source #

Fold using addition

productR :: (Foldable f, Semiring r) => f r -> r Source #

Fold using multiplication

Modules and vectors

class (Ring r, AdditiveGroup v) => RingModule r v where Source #

A module over a Ring r is an AdditiveGroup which can be multiplied by scalars in r.

Minimal complete definition

(⊙)

Methods

(⊙) :: r -> v -> v Source #

Instances

RingModule Double Vec Source # 

Methods

(⊙) :: Double -> Vec -> Vec Source #

RingModule Int Double Source #

Since ℝ is a module over ℤ, using scalar multiplication can save a lot of coersion noise.

Methods

(⊙) :: Int -> Double -> Double Source #

RingModule Int Vec Source # 

Methods

(⊙) :: Int -> Vec -> Vec Source #

Ring r => RingModule r r Source #

Every Ring is a module over itself.

Methods

(⊙) :: r -> r -> r Source #

(RingModule r v, RingModule r w) => RingModule r (v, w) Source # 

Methods

(⊙) :: r -> (v, w) -> (v, w) Source #

newtype Vec Source #

Implements variable-length vectors. Addition batween vectors of different lengths occurs by letting ℝ⊆ℝ²⊆ℝ³⊆… by embedding each length in the space op polynomials.

Constructors

Vec 

Fields

Instances

Eq Vec Source # 

Methods

(==) :: Vec -> Vec -> Bool #

(/=) :: Vec -> Vec -> Bool #

Read Vec Source # 
Show Vec Source # 

Methods

showsPrec :: Int -> Vec -> ShowS #

show :: Vec -> String #

showList :: [Vec] -> ShowS #

NFData Vec Source # 

Methods

rnf :: Vec -> () #

AdditiveGroup Vec Source # 

Methods

addinv :: Vec -> Vec Source #

(⊖) :: Vec -> Vec -> Vec Source #

Additive Vec Source # 

Methods

zero :: Vec Source #

(⊕) :: Vec -> Vec -> Vec Source #

RingModule Double Vec Source # 

Methods

(⊙) :: Double -> Vec -> Vec Source #

RingModule Int Vec Source # 

Methods

(⊙) :: Int -> Vec -> Vec Source #

PackedDFA ExpVecDFST (Expectation Vec) Source # 

Methods

numStates :: Ix sigma => ExpVecDFST sigma -> Int Source #

psegBounds :: Ix sigma => ExpVecDFST sigma -> (sigma, sigma) Source #

unpackDFA :: Ix sigma => ExpVecDFST sigma -> DFST Int sigma (Expectation Vec) Source #

packDFA :: Ix sigma => Int16 -> Int16 -> (sigma, sigma) -> ((Int16, sigma) -> Int16) -> ((Int16, sigma) -> Expectation Vec) -> (Int16 -> Expectation Vec) -> ExpVecDFST sigma Source #

coords :: Vec -> [Double] Source #

Returns a list of coordinates.

fromInts :: [Int] -> Vec Source #

Convert from a list of integers.

vec :: [Double] -> Vec Source #

Convert from a list of coordinates.

innerProd :: Vec -> Vec -> Double Source #

Standard inner product on ℝⁿ.

normVec :: Vec -> Double Source #

Calculate the euclidean norm of a vector.

normalizeVec :: Vec -> Vec Source #

Return a vector of unit length pointing in the same direction.

consVec :: Double -> Vec -> Vec Source #

Add a number to the begining of the list of coordinates.

l1Vec :: Vec -> Double Source #

Taxicab norm.

dl1Vec :: Vec -> Vec Source #

Gradient of taxicab norm.

showFVec :: Maybe Int -> Vec -> String Source #

Show a vector to a certain precision, equivalent of showFFloat.