Safe Haskell | Safe-Infered |
---|

Conditional probability table

Conditional Probability Tables and Probability tables

- class FactorPrivate f => Factor f where
- isScalarFactor :: f -> Bool
- emptyFactor :: f
- containsVariable :: f -> DV -> Bool
- factorVariables :: f -> DVSet
- factorMainVariable :: f -> DV
- factorWithVariables :: DVSet -> [Double] -> Maybe f
- factorValue :: f -> DVISet Int -> Double
- variablePosition :: f -> DV -> Maybe Int
- factorDimension :: f -> Int
- factorNorm :: f -> Double
- factorScale :: Double -> f -> f
- factorFromScalar :: Double -> f
- evidenceFrom :: DVISet Int -> Maybe f
- factorDivide :: f -> Double -> f
- factorProduct :: [f] -> f
- factorProjectOut :: DVSet -> f -> f
- factorProjectTo :: DVSet -> f -> f

- isomorphicFactor :: Factor f => f -> f -> Bool
- normedFactor :: Factor f => f -> f
- class Set s where
- emptySet :: s a
- union :: Eq a => s a -> s a -> s a
- intersection :: Eq a => s a -> s a -> s a
- difference :: Eq a => s a -> s a -> s a
- isEmpty :: s a -> Bool
- isElem :: Eq a => a -> s a -> Bool
- addElem :: Eq a => a -> s a -> s a
- nbElements :: s a -> Int
- subset :: Eq a => s a -> s a -> Bool
- equal :: Eq a => s a -> s a -> Bool

- class BayesianDiscreteVariable v where
- newtype Vertex = Vertex {}
- data DV = DV !Vertex !Int
- type DVSet = [DV]
- data DVI a
- type DVISet a = [DVI a]
- setDVValue :: DV -> a -> DVI a
- instantiationValue :: DVI t -> t
- instantiationVariable :: DVI t -> DV
- variableVertex :: LabeledVertex l => l -> Vertex
- (=:) :: (Bounded b, Enum b) => DV -> b -> DVI Int
- forAllInstantiations :: DVSet -> [DVISet Int]
- factorFromInstantiation :: Factor f => DVI Int -> f
- changeVariableOrder :: DVSet -> DVSet -> [Double] -> [Double]
- data CPT
- testProductProject_prop :: CPT -> CPT -> Property
- testScale_prop :: Double -> CPT -> Bool
- testProjectCommut_prop :: CPT -> Property
- testScalarProduct_prop :: Double -> CPT -> Bool
- testProjectionToScalar_prop :: CPT -> Bool

# Factor

class FactorPrivate f => Factor f whereSource

A factor as used in graphical model It may or not be a probability distribution. So it has no reason to be normalized to 1

isScalarFactor :: f -> BoolSource

When all variables of a factor have been summed out, we have a scalar

emptyFactor :: fSource

An empty factor with no variable and no values

containsVariable :: f -> DV -> BoolSource

Check if a given discrete variable is contained in a factor

factorVariables :: f -> DVSetSource

Give the set of discrete variables used by the factor

factorMainVariable :: f -> DVSource

Return A in P(A | C D ...). It is making sense only if the factor is a conditional propbability table. It must always be in the vertex corresponding to A in the bayesian graph

factorWithVariables :: DVSet -> [Double] -> Maybe fSource

Create a new factors with given set of variables and a list of value for initialization. The creation may fail if the number of values is not coherent with the variables and their levels. For boolean variables ABC, the value must be given in order FFF, FFT, FTF, FTT ...

factorValue :: f -> DVISet Int -> DoubleSource

Value of factor for a given set of variable instantitation. The variable instantion is like a multi-dimensional index.

variablePosition :: f -> DV -> Maybe IntSource

Position of a discrete variable in te factor (p(AB) is differennt from p(BA) since values are not organized in same order in memory)

factorDimension :: f -> IntSource

Dimension of the factor (number of floating point values)

factorNorm :: f -> DoubleSource

Norm of the factor = sum of its values

factorScale :: Double -> f -> fSource

Scale the factor values by a given scaling factor

factorFromScalar :: Double -> fSource

Create a scalar factor with no variables

evidenceFrom :: DVISet Int -> Maybe fSource

Create an evidence factor from an instantiation. If the instantiation is empty then we get nothing

factorDivide :: f -> Double -> fSource

Divide all the factor values

factorProduct :: [f] -> fSource

Multiply factors.

factorProjectOut :: DVSet -> f -> fSource

Project out a factor. The variable in the DVSet are summed out

factorProjectTo :: DVSet -> f -> fSource

Project to. The variable are kept and other variables are removed

isomorphicFactor :: Factor f => f -> f -> BoolSource

Test equality of two factors taking into account the fact that the variables may be in a different order. In case there is a distinction between conditionned variable and conditionning variables (imposed from the exterior) then this comparison may not make sense. It is a comparison of function of several variables which no special interpretation of the meaning of the variables according to their position.

normedFactor :: Factor f => f -> fSource

Norm the factor

# Set of variables

A Set of variables used in a factor. s is the set and a the variable

Empty set

union :: Eq a => s a -> s a -> s aSource

Union of two sets

intersection :: Eq a => s a -> s a -> s aSource

Intersection of two sets

difference :: Eq a => s a -> s a -> s aSource

Difference of two sets

Check if the set is empty

isElem :: Eq a => a -> s a -> BoolSource

Check if an element is member of the set

addElem :: Eq a => a -> s a -> s aSource

Add an element to the set

nbElements :: s a -> IntSource

Number of elements in the set

subset :: Eq a => s a -> s a -> BoolSource

Check if a set is subset of another one

equal :: Eq a => s a -> s a -> BoolSource

Check set equality

Set [] |

class BayesianDiscreteVariable v whereSource

A discrete variable has a number of levels which is required to size the factors

# Implementation

Vertex type used to identify a vertex in a graph

## Discrete variables and instantiations

A discrete variable

Discrete Variable instantiation. A variable and its value

setDVValue :: DV -> a -> DVI aSource

Create a discrete variable instantiation for a given discrete variable

instantiationValue :: DVI t -> tSource

Extract value of the instantiation

instantiationVariable :: DVI t -> DVSource

Discrete variable from the instantiation

variableVertex :: LabeledVertex l => l -> VertexSource

(=:) :: (Bounded b, Enum b) => DV -> b -> DVI IntSource

Create a variable instantiation using values from an enumeration

forAllInstantiations :: DVSet -> [DVISet Int]Source

Generate all instantiations of variables

factorFromInstantiation :: Factor f => DVI Int -> fSource

Convert a variable instantation to a factor Useful to create evidence factors

Change the layout of values in the factor to correspond to a new variable order

## Factor

Mainly used for conditional probability table like p(A B | C D E) but the normalization to 1 is not imposed. And the conditionned variables are not different from the conditionning ones. The dimensions for each variables are listed. The variables on the left or right of the condition bar are not tracked. What's matter is that it is encoding a function of several variables. Marginalization of variables will be computed from the bayesian graph where the knowledge of the dependencies is. So, this same structure is used for a probability too (conditioned on nothing)

# Tests

testProductProject_prop :: CPT -> CPT -> PropertySource

testScale_prop :: Double -> CPT -> BoolSource

testScalarProduct_prop :: Double -> CPT -> BoolSource