> restart:

E2 - Tests d'hypothèses

Evaluation du 06/12/2004

On charge quelques bibliothèques

Vérifier les numéros de version des bibliothèmes disponibles

> with(pldx); # il faut la version 24
ever_loaded;

`pldx v6-24  ;  author : <douillet@ensait.fr>  ;  l...

[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...
[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...
[Xtens, `convert/D2`, ever_loaded, isdiag, sinsin, ...

[` Diag`, ` Entries`, ` Evalm`, ` Matrice`, ` Tr`, ...
[` Diag`, ` Entries`, ` Evalm`, ` Matrice`, ` Tr`, ...

> with(simul); # il faut la version 16
ever_loaded;

`simul v6-16  ;  author : <douillet@ensait.fr>  ;  ...

Warning, the name ever_loaded has been redefined

[chi2_tst, ever_loaded, histo_arr, xcutn, xhisto, x...

[` Chi2`, ` Gauss`, ` IChi`, ` IGauss`, ` INorlaw`,...
[` Chi2`, ` Gauss`, ` IChi`, ` IGauss`, ` INorlaw`,...

> kernelopts(ASSERT=true):

Création du fichier

M, K:= 1200., 1.9;

ra:= stats[random, normald[ln(M), sqrt(ln(K))]];
n:= 1200; li:= map(exp, [ ra( n )]):

fich:= "F:/docs/Ensait/decis/decis_ds10/dat_ds_10.txt";
hdl:= fopen(fich, WRITE);
for i to n do fprintf(hdl,"%a\n", li[i]); od:
fclose(fich):

Commandes communes

> macro(moy= stats[describe, mean], var= stats[describe, variance],
ran= stats[describe, range], nmb= stats[describe, count] );

moy, var, ran, nmb

> macro(histo = xhisto );
xima:=proc(pl); op(1,pl) : convert(%,list): map(op,%): map2(op,2,%): max(op(%)): end:

moy, var, ran, nmb, histo

> macro(talto=stats[transform, tallyinto]);

moy, var, ran, nmb, histo, talto

> recode:= proc(item) global m; local a,b, c;
a,b,c:= op(op(1,item)), op(2, item);
Weight(a..b, c*(a+b)/2/m)
end :

>

>

Groupe A

A0-Lecture du fichier

Télécharger le fichier "www.douillet.info/~douillet/decis_ds10/dat_ds_10.txt"

Déclarer le nom de la copie locale du fichier

> fich:= "F:/docs/Ensait/decis/decis_ds10/dat_ds_10a.txt";

fich :=

On lit tous les nombres

> lire:= table(): tmp:= 'tmp':
hdl:= fopen(fich, READ);
for i to 5000 while tmp <> [ ] do
tmp:= fscanf(hdl,"%a");
lire[i]:= op (tmp);
od:
fclose(fich); n:= i-2 ; i:='i':

hdl := 0

n := 1200

On en fait une liste

> li:= [ seq(lire[k], k=1..n)]:

A1-Paramètres de dispersion

> m, s, vals, nn:= moy(li), sqrt(var(li)), ran(li), nmb(li); ASSERT(n=nn);

m, s, vals, nn := 1633.146712, 1520.878292, 99.9933...

Histogramme automatique

> kx:= 40: pl1:= histo(li, area=1, numbars=kx):

> yx:=xima(pl1) :
pl2:= plot([[m,y,y=0..yx], [m-s,y,y=0..yx], [m+s,y,y=0..yx]], color=red, linestyle=[24,8,8]):

> display(pl1, pl2);

[Maple Plot]

A2-Modèle lognormal

> M:='M': K:='K': m=M*sqrt(K), (s/m)^2 = K-1; solve({%});
assign(%);

1633.146712 = M*sqrt(K), .8672384418 = K-1

{K = 1.867238442, M = 1195.157967}

> pl5:= plot(norlaw(ln(M), sqrt(ln(K)), ln(x))/x, x=vals, color=blue, linestyle=16):

> display(pl1,pl2,pl5);

[Maple Plot]

> kx:=40;

kx := 40

> kz:= 13: deb, fin:= op(vals); pas:= (fin-deb)/kx: mid1:= deb+pas*15: mid2:= deb+pas*19:
les_interv_d:= seq(deb+pas*(k-1)..deb+pas*(k), k=1..kz):
les_interv_f := deb+pas*kz..mid1, mid1..mid2, mid2..fin+0.001:
les_interv := [les_interv_d, les_interv_f]:

deb, fin := 99.99331862, 15133.40883

> li2:= talto(li, les_interv);

li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...
li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...
li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...
li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...
li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...
li2 := [Weight(99.99331862 .. 475.8287064,156), Wei...

> map2(op,2,li2); [seq(`if`(%[k]>=10, NULL,k), k=1..nops(%))]: ASSERT(%=[ ], %=[ ]);

[156, 257, 225, 135, 113, 72, 63, 39, 31, 19, 15, 2...

> display(pl1, histo(li2, color=yellow), view= [DEFAULT, 0.. 0.0001]);

[Maple Plot]

> Law1:= unapply(Norlaw(ln(M), sqrt(ln(K)), ln(x)), x);

Law1 := proc (x) options operator, arrow; .50000000...

> proc(z) local a,b: a,b:= op(z); Weight(a..b, n*(Law1(b)-Law1(a))) end:
th2:= map(%, les_interv);

th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...
th2 := [Weight(99.99331862 .. 475.8287064,145.28543...

> display( histo(li2, color=yellow), histo(th2));

[Maple Plot]

> nu:= nops(li2)-3; add((op(2, th2[k])-op(2, li2[k]))^2/op(2, th2[k]), k=1..nops(li2));

nu := 13

12.73007244

A3-Loi "en masse"

> li3:= map(recode, li2);

li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...
li3 := [Weight(99.99331862 .. 475.8287064,27.501581...

> nmb(li3);

1217.792278

> m_, s_:= moy(li3), sqrt(var(li3));

m_, s_ := 3266.802416, 2866.003202

> pl23:=histo(li3, area=1):
yx:=xima(%) :
pl24:= plot([[m_,y,y=0..yx], [m_-s_,y,y=0..yx], [m_+s_,y,y=0..yx]], color=red, linestyle=[24,8,8]):

Modèle issu du modèle "en nombre"

> Law3:= unapply(Norlaw(ln(M*K), sqrt(ln(K)), ln(x)), x):
law3:= unapply(norlaw(ln(M*K), sqrt(ln(K)), ln(x))/x, x):
pl25:= plot(law3(x), x=vals, color=blue, linestyle=16):

> display( pl23, pl24,pl25);

[Maple Plot]

> m_; (s/m)^2+1; m*%;

3266.802416

1.867238442

3049.474322

> mk_th3:= proc(z) local a,b: a,b:= op(z); Weight(a..b, n*(Law3(b)-Law3(a))) end:
th30:= map(mk_th3, les_interv): n - nmb(th30);
subsop(2= op(2, th30[-1]) +%, th30[-1]): th3:= subsop(-1=%, th30):
ASSERT(nmb(th3)=n);

9.304712

Test du Chi2 sans correction

> nu:= nops(li3)-1; add((op(2, th30[k])-op(2, li3[k]))^2/op(2, th30[k]), k=1..nops(li3));
chi_red=(%-nu)/sqrt(2.*nu);

>

nu := 15

35.67030049

chi_red = 3.773863283

Test du Chi2

> nu:= nops(li3)-1; add((op(2, th3[k])-op(2, li3[k]))^2/op(2, th3[k]), k=1..nops(li3));
chi_red=(%-nu)/sqrt(2.*nu);

nu := 15

28.44075789

chi_red = 2.453935429

Test du Chi2 (sans le dernier intervalle)

> nu:= nops(li3)-2; add((op(2, th3[k])-op(2, li3[k]))^2/op(2, th3[k]), k=1..nops(li3)-1);
chi_red=(%-nu)/sqrt(2.*nu);

nu := 14

23.11693377

chi_red = 1.722938534

>

>

>

Tentative de détermination d'un modèle à partir de m_ et s_

> M_:='M_': K_:='K_': m_=M_*sqrt(K_), (s_/m_)^2 = K_-1; solve({%}); assign(%); M_/K_;

3266.802416 = M_*sqrt(K_), .7696754001 = K_-1

{K_ = 1.769675400, M_ = 2455.704246}

1387.658011

> pl27:= plot(norlaw(ln(M_), sqrt(ln(K_)), ln(x))/x, x=vals, color=red, linestyle=16):

> display( pl23, histo(th3, color=yellow), pl25, pl27, view=[0..fin, DEFAULT]);

[Maple Plot]

> m,s; m_, s_; m*K-m_; %/m_/sqrt(K-1); %*sqrt(n*1.);

1633.146712, 1520.878292

3266.802416, 2866.003202

-217.328094

-.7143708797e-1

-2.474653318

> evalf(%/(s_/sqrt(n)));

-.2991081989e-1

>

>

>

>

Groupe B

B0-Lecture du fichier

Télécharger le fichier "www.douillet.info/~douillet/decis_ds10/dat_ds_10.txt"

Déclarer le nom de la copie locale du fichier

> fich:= "F:/docs/Ensait/decis/decis_ds10/dat_ds_10b.txt";

fich :=

On lit tous les nombres

> lire:= table(): tmp:= 'tmp':
hdl:= fopen(fich, READ);
for i to 5000 while tmp <> [ ] do
tmp:= fscanf(hdl,"%a");
lire[i]:= op (tmp);
od:
fclose(fich); n:= i-2 ; i:='i':

hdl := 0

n := 1200

On en fait une liste

> li:= [ seq(lire[k], k=1..n)]:

B1-Paramètres de dispersion

> m, s, vals, nn:= moy(li), sqrt(var(li)), ran(li), nmb(li); ASSERT(n=nn);

m, s, vals, nn := 1858.238022, 1899.485263, 89.8752...

Histogramme automatique

> kx:= 40: pl1:= histo(li, area=1, numbars=kx):

> yx:=xima(pl1) :
pl2:= plot([[m,y,y=0..yx], [m-s,y,y=0..yx], [m+s,y,y=0..yx]], color=red, linestyle=[24,8,8]):

> display(pl1, pl2);

[Maple Plot]

B2-Modèle lognormal

> M:='M': K:='K': m=M*sqrt(K), (s/m)^2 = K-1; solve({%});
assign(%);

1858.238022 = M*sqrt(K), 1.044886632 = K-1

{K = 2.044886632, M = 1299.471396}

> pl5:= plot(norlaw(ln(M), sqrt(ln(K)), ln(x))/x, x=vals, color=blue, linestyle=16):

> display(pl1,pl2,pl5);

[Maple Plot]

> kx:=45;

kx := 45

> kz:= 12: deb, fin:= op(vals); pas:= (fin-deb)/kx: mid1:= deb+pas*(kz+2) : mid2:= deb+pas*(kz+5): mid3:= deb+pas*(kz+8):
les_interv_d:= seq(deb+pas*(k-1)..deb+pas*(k), k=1..kz):
les_interv_f := deb+pas*kz..mid1, mid1..mid2, mid2..mid3, mid3..fin+0.001:
les_interv := [les_interv_d, les_interv_f]:

deb, fin := 89.87520015, 19834.03273

> li2:= talto(li, les_interv);

li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...
li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...
li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...
li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...
li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...
li2 := [Weight(89.87520015 .. 528.6342564,182), Wei...

> map2(op,2,li2); [seq(`if`(%[k]>=10, NULL,k), k=1..nops(%))]: ASSERT(%=[ ], %=[ ]);

[182, 286, 193, 126, 111, 69, 57, 35, 28, 21, 14, 2...

> display(pl1, histo(li2, color=yellow), view= [DEFAULT, 0.. 0.0001]);

[Maple Plot]

> Law1:= unapply(Norlaw(ln(M), sqrt(ln(K)), ln(x)), x);

Law1 := proc (x) options operator, arrow; .50000000...

> proc(z) local a,b: a,b:= op(z); Weight(a..b, n*(Law1(b)-Law1(a))) end:
th2:= map(%, les_interv);

th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...
th2 := [Weight(89.87520015 .. 528.6342564,171.60379...

> display( histo(li2, color=yellow), histo(th2));

[Maple Plot]

> nu:= nops(li2)-3; add((op(2, th2[k])-op(2, li2[k]))^2/op(2, th2[k]), k=1..nops(li2));

nu := 13

14.21710683

B3-Loi "en masse"

> li3:= map(recode, li2);

li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...
li3 := [Weight(89.87520015 .. 528.6342564,30.289101...

> nmb(li3);

1217.248710

> m_, s_:= moy(li3), sqrt(var(li3));

m_, s_ := 4107.486377, 3841.450713

> pl23:=histo(li3, area=1):
yx:=xima(%) :
pl24:= plot([[m_,y,y=0..yx], [m_-s_,y,y=0..yx], [m_+s_,y,y=0..yx]], color=red, linestyle=[24,8,8]):

Modèle issu du modèle "en nombre"

> Law3:= unapply(Norlaw(ln(M*K), sqrt(ln(K)), ln(x)), x):
law3:= unapply(norlaw(ln(M*K), sqrt(ln(K)), ln(x))/x, x):
pl25:= plot(law3(x), x=vals, color=blue, linestyle=16):

> display( pl23, pl24,pl25);

[Maple Plot]

> m_; (s/m)^2+1; m*%;

4107.486377

2.044886632

3799.886090

> mk_th3:= proc(z) local a,b: a,b:= op(z); Weight(a..b, n*(Law3(b)-Law3(a))) end:
th30:= map(mk_th3, les_interv): n - nmb(th30);
subsop(2= op(2, th30[-1]) +%, th30[-1]): th3:= subsop(-1=%, th30):
ASSERT(nmb(th3)=n);

10.520462

Test du Chi2

> nu:= nops(li3)-1; add((op(2, th3[k])-op(2, li3[k]))^2/op(2, th3[k]), k=1..nops(li3));
chi_red=(%-nu)/sqrt(2.*nu);

nu := 15

29.19638252

chi_red = 2.591892980

Test du Chi2 sans correction

> nu:= nops(li3)-1; add((op(2, th30[k])-op(2, li3[k]))^2/op(2, th30[k]), k=1..nops(li3));
chi_red=(%-nu)/sqrt(2.*nu);

>

>

nu := 15

37.23991676

chi_red = 4.060434696

Test du Chi2 (sans le dernier intervalle)

> nu:= nops(li3)-2; add((op(2, th3[k])-op(2, li3[k]))^2/op(2, th3[k]), k=1..nops(li3)-1);
chi_red=(%-nu)/sqrt(2.*nu);

nu := 14

23.37769251

chi_red = 1.772217304

>

>

>

Tentative de détermination d'un modèle à partir de m_ et s_

> M_:='M_': K_:='K_': m_=M_*sqrt(K_), (s_/m_)^2 = K_-1; solve({%}); assign(%); M_/K_;

4107.486377 = M_*sqrt(K_), .8746579891 = K_-1

{K_ = 1.874657989, M_ = 2999.957542}

1600.269254

> pl27:= plot(norlaw(ln(M_), sqrt(ln(K_)), ln(x))/x, x=vals, color=red, linestyle=16):

> display( pl23, histo(th3, color=yellow), pl25, pl27, view=[0..fin, DEFAULT]);

[Maple Plot]

>

>

File d'attente

Procédure simul_wait (un seul serveur)

> _seed:= 11112003; lambda:= 5.5; mu:=8; N:=5000;

_seed := 11112003

lambda := 5.5

mu := 8

N := 5000

> with(stats): with(simul): macro(histo = xhisto, talto=stats[transform, tallyinto] ):
macro(moy= stats[describe, mean], var= stats[describe, variance], ran= stats[describe, range], nmb= stats[describe, count] );

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

`simul v6-16  ;  author : <douillet@ensait.fr>  ;  ...

histo, moy, var, ran, nmb, talto

>

> gx:= proc() global _seed; _seed := irem(427419669081*_seed, 999999999989);
-1/alpha*ln(evalf(_seed/999999999989)) end proc:
ga:= subs(alpha=lambda, eval(gx)): gb:= subs(alpha=mu, eval(gx)):

> simul_wait:= proc(N) global mem, ga, gb:
local load,k,ech,i,laps,event,n,gg,compar;
load:=0: k:=0: ech:=[[0,0,0]]: mem:= table():
compar:= (A,B)-> evalb(A[1]<B[1]);
for i to 2*N do
laps, event, n := op(ech[1]);
ech:= map(A->[A[1]-laps,A[2],A[3]], subsop(1=NULL, ech));
load:= `if`(load>0,load-laps,0);
if event=0 # arrivée
then n:= n+1; k:=k+1; gg:= gb();
load:= load+gg; mem[n]:= [load,gg,k];
ech:= sort([ [ga(),0,n],[load,1,n], op(ech) ], compar);
else # départ
k:=k-1;
fi;
od: end:

> compar_histo:= proc(ex, th) global mihis; local nn, mi; nn:= nops(th);
if nops(ex)<>nn then error `: les deux structures n'ont pas la même longueur` fi;
mihis:= [seq(Weight( op(1,th[j]), min(op(2,th[j]),op(2,ex[j]))), j=1..nn)];
display(histo(mihis, color=grey, area=count), histo(ex, color=cyan, area=count)
, histo(th, color=yellow, area=count));
end:

> stamp:= time(): simul_wait(N): print(time()-stamp);

4.695

Exploitation

> Matrix([seq(mem[j], j=1..10)]);

_rtable[33054252]

Séjour

> tmp:= sort([seq(mem[j][1],j=1..N)]):
law:= unapply((mu-lambda)*exp(-(mu-lambda)*t),t);
display(histo(tmp, area=1), plot(law(t), t=0..4));

law := proc (t) options operator, arrow; 2.5*exp(-2...

[Maple Plot]

> vals:= ran(tmp);

vals := .2826065691e-4 .. 2.230415511

> Law:= unapply(1- exp(t*(-mu+lambda)),t);

Law := proc (t) options operator, arrow; 1-exp(-2.5...

> nu:=9; seq(solve(k/(nu+1)=Law(t)), k=0..nu): boun:= %, 1.3*max(%[-1]*2, rhs(vals));
les_interv:= [seq(boun[j]..boun[j+1], j=1..nu+1)]: nops(%);

nu := 9

boun := 0., .4214420626e-1, .8925742052e-1, .142669...
boun := 0., .4214420626e-1, .8925742052e-1, .142669...

10

> exper:= talto(tmp, les_interv);

exper := [Weight(0. .. .4214420626e-1,516), Weight(...
exper := [Weight(0. .. .4214420626e-1,516), Weight(...
exper := [Weight(0. .. .4214420626e-1,516), Weight(...
exper := [Weight(0. .. .4214420626e-1,516), Weight(...
exper := [Weight(0. .. .4214420626e-1,516), Weight(...

> proc(z) local a,b: a,b:= op(z); Weight(a..b, N*(Law(b)-Law(a))) end:
theor:= map(%, les_interv);

theor := [Weight(0. .. .4214420626e-1,499.9999995),...
theor := [Weight(0. .. .4214420626e-1,499.9999995),...
theor := [Weight(0. .. .4214420626e-1,499.9999995),...
theor := [Weight(0. .. .4214420626e-1,499.9999995),...
theor := [Weight(0. .. .4214420626e-1,499.9999995),...

> display(compar_histo(exper, theor), plot(N*law(t), t=0..4), view=[0..2, DEFAULT]);

[Maple Plot]

> nops(theor); nu;

10

9

> add( (op(2,theor[j])-op(2,exper[j]))^2/op(2,theor[j]), j=1..nops(theor)-1);
(%-nu)/sqrt(2.*nu); (%%-nu-1)/sqrt(2.*(nu-1));

12.28800031

.7749891053

.5720000775

>

>

Hors sujet

Service

> tmp:= [seq(mem[j][2],j=1..N)]: histo(tmp, area=1, numbars=20):
display(%, plot(mu*exp(-mu*t), t=0..4), view=[0..2, DEFAULT]);

[Maple Plot]

Nb clients

> tmp:= [seq(mem[j][3],j=1..N)]: stats[transform, tally](%): jx:= (max@op@map2)(op,1,%):

> exper:= stats[transform, tallyinto](tmp, [seq(j-1/2..j+1/2, j=1..jx)]):
pl_nb:= xhisto(%, area=1): evalf([moy(tmp), var(tmp)]);

[3.435000000, 7.339775000]

> rho:= lambda/mu*1.; theor:= [seq(Weight(k+1/2..k+3/2, N*(1-rho)*rho^k), k=0..jx-1)]:

rho := .6875000000

> compar_histo(exper, theor);

[Maple Plot]

>

>