6 Predicting the number of classes
In this section, we build a random sequence, on a given number of
classes, from a set of markovian models, and we use the probability
algorithm to predict the given number.
In this example, the model is in file lprop1.
-
We build a Partition, on
a virtual sequence of length 10000, in 23 segments, such that each
segment is at least 50 positions long.
nbcl=23 #for example
import lcompte
lp=lcompte.Lproportion(fic="lprop1")
import partition
p=partition.Partition()
p.build_random(10000,nbcl,ec=50)
- We attribute predictor numbers to the
Segments of the
Partition.
lnum=lp.num()
import random
numr=random.choice(lnum)
for s in p:
s.g_num([numr])
x=random.choice(lnum)
while x==numr:
x=random.choice(lnum)
numr=x
- Then we build a Sequence from
the Partition and the
Lproportion.
import sequence
s=sequence.Sequence()
s.read_Part(p,lp)
- We build a Matrice from the
predictions of the models.
import lexique
import matrice
lx=lexique.Lexique(Lprop=lp)
- We compute the segmentation log-likelihood, up to 100 classes.
lprob=lx.log_likelihood(s,100)
- We add the exponential a priori:
import math
lapost=[]
theta=0.514
for i in range(len(lprob)):
lapost.append(lprob[i]+(i+1)*math.log(theta))
print
- We select the maximum of the ratio.
nbc=lapost.index(max(lapost))+1
print nbc