** Next:** 3.2 Binomial Distribution
** Up:** 3 The Basics
** Previous:** 3 The Basics

##

3.1 Uniform Distribution

Now that we know the basic commands and file types used in Alchemy Lite,
we want to
start with the simplest TML KB one can think of: one that models
the uniform distribution. Suppose we want
to consider the output of a coin flip.
Our TML KB consists of a class that represents a sequence of coin flips.
It has 10 different Flip subparts that each have an attribute `Side`
that can be `Heads` or `Tails`.
Our `.tml` file looks
like:
`
class FlipSequence {`

subparts Flip[10];

}

class Flip {

Side Heads 0.0, Tails 0.0;

}

There must be a declaration for every class, even if the class is empty.
However, if no information is known
about a class (or object), the lines in the declaration can be omitted (i.e., you do not have to leave empty ';' lines).

The `.db` file will only contain the name of the Top Object
(i.e, the singular object that is of the Top Class):

`
FlipSequence Coin {`

}

We can perform probabilistic inference to result in a uniform distribution:

al -i uniform_coin.tml -o uniform_coin.result -e coin.db -q Side(Flip)

(Note: Quotation marks may be required around the query on your system
due to the parentheses.)
The query asks what is the probability of each possible value of `Side` is
for each `Flip` object in the knowledge base.

The resulting file `uniform.result` shows the marginals
given no other evidence:

`
P[Side(Coin.Flip[1],Heads)] = 0.500000`

P[Side(Coin.Flip[1],Tails)] = 0.500000

P[Side(Coin.Flip[2],Heads)] = 0.500000

P[Side(Coin.Flip[2],Tails)] = 0.500000

P[Side(Coin.Flip[3],Heads)] = 0.500000

P[Side(Coin.Flip[3],Tails)] = 0.500000

P[Side(Coin.Flip[4],Heads)] = 0.500000

P[Side(Coin.Flip[4],Tails)] = 0.500000

P[Side(Coin.Flip[5],Heads)] = 0.500000

P[Side(Coin.Flip[5],Tails)] = 0.500000

...

The command

al -i uniform.mln -o uniform.result -e uniform.db -q Side(Flip,Heads)

will find the marginal probability of `Heads` for each `Flip` object:

`
P[Side(Coin.Flip[1],Heads)] = 0.500000`

P[Side(Coin.Flip[2],Heads)] = 0.500000

P[Side(Coin.Flip[3],Heads)] = 0.500000

P[Side(Coin.Flip[4],Heads)] = 0.500000

P[Side(Coin.Flip[5],Heads)] = 0.500000

...

** Next:** 3.2 Binomial Distribution
** Up:** 3 The Basics
** Previous:** 3 The Basics

Chloe Kiddon
2013-04-01
Chloe Kiddon
2013-04-01