## 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.

1. 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)
2. 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
3. Then we build a Sequence from the Partition and the Lproportion.
import sequence s=sequence.Sequence() s.read_Part(p,lp)
4. We build a Matrice from the predictions of the models.
import lexique import matrice lx=lexique.Lexique(Lprop=lp)
5. We compute the segmentation log-likelihood, up to 100 classes.
lprob=lx.log_likelihood(s,100)
6. 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
7. We select the maximum of the ratio.
nbc=lapost.index(max(lapost))+1 print nbc