-
Notifications
You must be signed in to change notification settings - Fork 1
/
demos.sim
3038 lines (2718 loc) · 87.9 KB
/
demos.sim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
comment removed by Henning Normann, IDB 14.9.86. options(/E);
comment use of reserved word Switch updated according to Standard SIMULA
by J|rn Viken, IDT 22.9.87.;
comment procedure Noreport added in class Tab to prevent report of
user-selected objects in the DEMOS report call. A boolean Zyqnoreport
is testet for each object in DEMOS-procedure "Report" near the end
of this file. Change made by Knut H. Smevold, 18.8.88.;
comment Tab class Tally: calculations in the standard deviation expression
are rearranged to be able to handle larger number of observations.
The change is simply to devide by Obs in both nominator and
denominator, which removes the factor Obs*(Obs-1)!
Change made by Poul E. Heegaard, IDT, 01.09.94 ;
comment REAL is extended to LONG REAL.
Change made by Poul E. Heegaard, IDT, 01.09.94 ;
comment Count are included in the REPLICATION report.
Change made by Poul E. Heegaard, IDT, 02.09.94 ;
comment Calculation of standard error of sample mean is
added standard reports
Change made by Poul E. Heegaard, IDT, 22.03.95 ;
comment New procedures:
1) Quantile - returns the quantile in a Student-T or Normal
distribution, depend on the number of observations,
2) ConfWidth - returns the confidence width given the
standard deviation and number of observations.
Change made by Poul E. Heegaard, IDT, 05.05.95 ;
comment New attribute functions made for TALLY:
Mean - returns the mean value of a TALLY
Sdev - returns the standard deviation of a TALLY
UpperConf(Alpha) - returns the upper alpha-conf. limit of a TALLY
LowerConf(Alpha) - returns the lover alpha-conf. limit of a TALLY
Changes made by Poul E. Heegaard, IDT, 13.10.95 ;
comment Rdist class Rayleigh: new class generating variates from the
Rayleigh distribution using the method of inverse-function is
included (as an example in course 45081 Diskrete event simulation.
A detailed describtion of all necessary chances are documented
in the postion in the code where the patch is included. All
comments regarding this changes are starting with "! 960917/peh".
Describtion:
RDIST CLASS RAYLEIGH(A) long real A
BEGIN
long real PROCEDURE SAMPLE
sigma = SQRT(2/pi)*A
END ***RAYLEIGH***
A call on sample returns a drawing from a RAYLEIGH distribution
with mean value A.
The old "demos.sim" without this change are saved as "demos0996.sim"
Changes made by Poul E. Heegaard, ITEM, 17.09.96 ;
comment Rdist class Pareto: new class generating variates from the
Pareto distribution using the method of inverse-function is
included. The method allows the user to define an upper limit
m of the generated variates. If m<=0, no upper limit exits (c=1).
A detailed describtion of all necessary chances are documented
in the postion in the code where the patch is included. All
comments regarding this changes are starting with "! 991021/peh".
Describtion:
Rdist class Pareto(k,alpha,m) INTEGER k long real alpha,m
BEGIN
REAL c
long real procedure Sample
BEGIN
Sample := k/(((1-Zyqsample*c))**(1.0/alpha))
END *** SAMPLE ***
END *** Pareto *** ;
comment Adaption to the CIM Simula compiler and linker:
All the virtual procedures in the TAB base class (right below)
now are completey declared with type as required by the CIM
compiler. In the cases where the procedure has no return
type, the procedure is given INTEGER type.
The procedure definitions in the TAB subclasses are also
updated.
Changes made by Idar Fagereng, ITEM 1999/12/07;
SIMSET class Demos;
begin
comment------------------ T A B ----------------------------;
class Tab(Title); value Title; text Title;
virtual :
procedure Reset IS INTEGER PROCEDURE Reset;;
procedure Report IS INTEGER PROCEDURE Report;;
procedure Rreport IS INTEGER PROCEDURE Rreport;;
procedure Rupdate IS INTEGER PROCEDURE Rupdate;;
procedure Sdev IS LONG REAL PROCEDURE Sdev;;
procedure RSdev IS LONG REAL PROCEDURE RSdev;;
procedure Mean IS LONG REAL PROCEDURE Mean;;
procedure RMean IS LONG REAL PROCEDURE RMean;;
procedure UpperConf IS LONG REAL PROCEDURE UpperConf(Alpha); REAL Alpha;;
procedure RUpperConf IS LONG REAL PROCEDURE RUpperConf(Alpha); REAL Alpha;;
procedure LowerConf IS LONG REAL PROCEDURE LowerConf(Alpha); REAL Alpha;;
procedure RLowerConf IS LONG REAL PROCEDURE RLowerConf(Alpha); REAL Alpha;;
procedure Resetextra IS INTEGER PROCEDURE Resetextra;;
begin
integer Obs;
long real Resetat;
ref(Tab)Next;
boolean Zyqnoreport;
procedure Join(R); ref(Reportq)R;
begin
if R == none then Error(18, none, this Tab, 0,
"T.JOIN(R); REF(TAB)T; REF(REPORTQ)R;") else
if R.FIRST == none
then R.FIRST :- R.LAST :- this Tab
else R.LAST :- R.LAST.Next :- this Tab;
end***JOIN***;
integer procedure report;
begin
Writetrn;
Outf.OUTIMAGE;
end***REPORT***;
procedure Noreport;
begin
Zyqnoreport := true;
end***NOREPORT***;
INTEGER procedure Reset;
begin
Obs := 0;
Resetat := Time;
end***RESET***;
procedure Writetrn;
begin
Outf.OUTTEXT(Title);
Outf.SETPOS(Outf.POS+(13-Title.LENGTH));
Printreal(Resetat);
Outf.OUTINT(Obs, 7);
end***REPORT TITLE, RESETAT AND READINGS***;
if Title.LENGTH > 12 then Title :- Title.SUB(1, 12);
Reset;
end***TAB***;
comment-------------------- T A L L Y -----------------------;
Tab class Tally;
begin
long real Sum, Sumsq, Min, Max;
integer Robs;
long real Rsum,Rsumsq;
! new procedures to access mean value, standard deviation, and
the confidence limits of the tab;
! calculate the mean value of TALLY;
long real procedure Mean;
begin
Mean := if Obs>0 then Sum/Obs else 0;
end *** Mean ***;
! calculate the standard deviation of TALLY;
long real procedure Sdev;
begin long real EN; EN := 1.0;
Sdev :=if Obs > 1
then SQRT(ABS(Sumsq-Sum**2/Obs)/(Obs-EN))
else 0;
end *** SdevValue ***;
! calculate the upper Alpha-limit of TALLY;
long real procedure UpperConf(Alpha);real Alpha;
begin
UpperConf := Mean + ConfWidth(Sdev,Alpha,Obs);
end *** UpperConf ***;
! calculate the lower Alpha-limit of TALLY;
long real procedure LowerConf(Alpha);real Alpha;
begin
LowerConf := Mean - ConfWidth(Sdev,Alpha,Obs);
end *** LowerConf ***;
integer procedure report;
begin long real EN; EN := 1.0;
Writetrn;
if Obs = 0 then Outf.OUTTEXT(Minuses.SUB(1, 40)) else
begin Printreal(Sum/Obs);
if Obs = 1 then
begin
Outf.OUTTEXT(Minuses.SUB(1, 10));
Outf.OUTTEXT(Minuses.SUB(1, 10));
end
else
begin
! 940109/peh: changed the calculation of st.dev.;
! Printreal(SQRT(ABS(Obs*Sumsq-Sum**2)/(Obs*(Obs-1))));
! 940109/peh: the long real variable EN convert the expression to long real;
! Sdev := SQRT(ABS(Sumsq-Sum**2/Obs)/((Obs-EN)));
Printreal(Sdev);
Printreal(Sdev/Sqrt(Obs));
end;
Printreal(Min);
Printreal(Max);
end;
Outf.OUTIMAGE;
end***REPORT***;
INTEGER procedure Reset;
begin Obs := 0;
Sum := Sumsq := Min := Max := 0.0;
Resetat := Time;
end***RESET***;
INTEGER procedure Resetextra;
begin
Resetat:=Time;
end *** RESETEXTRA ***;
procedure Update(V); long real V;
begin Obs := Obs + 1;
Sum := Sum + V;
Sumsq := Sumsq + V**2;
if Obs = 1 then Min := Max := V else
if V < Min then Min := V else
if V > Max then Max := V;
end*** UPDATE ***;
integer procedure rreport;
begin
Outf.OUTTEXT(Title);
Outf.SETPOS(Outf.POS+(13-Title.LENGTH));
Printreal(Resetat);
Outf.OUTINT(Robs,7);
if Robs=0 then Outf.OUTTEXT(Minuses.SUB(1,10))
else
begin
Printreal(RMean);
if Robs=1 then
begin
Outf.OUTTEXT(Minuses.SUB(1,10));
Outf.OUTTEXT(Minuses.SUB(1,10));
end
else
begin
Printreal(Sdaverage);
Printreal(Sdaverage/Sqrt(Robs));
end;
end;
Outf.OUTIMAGE;
end *** RREPORT ***;
integer procedure rupdate;
begin
if not Zyqantithetic then
begin
Robs:=Robs+1;
if Obs > 0 then
begin
Rsum:=Rsum+Sum/Obs;
Rsumsq:=Rsumsq+(Sum/Obs)**2;
end;
end;
end *** RUPDATE ***;
! new procedures to access mean value, standard deviation, and
the confidence limits after some replications of TALLY;
! calculate the mean value of TALLY;
long real procedure RMean;
begin
RMean := if RObs>0 then RSum/RObs else 0;
end *** RMean ***;
! calculate the standard deviation of TALLY;
long real procedure RSdev;
begin long real EN; EN := 1.0;
RSdev:=if Robs > 1
then SQRT(ABS(Rsumsq-Rsum**2/Robs)/(Robs-EN))
else 0;
end *** RSdev ***;
! calculate the upper Alpha-limit of TALLY;
long real procedure RUpperConf(Alpha);real Alpha;
begin
RUpperConf := RMean + ConfWidth(RSdev,Alpha,RObs);
end *** RUpperConf ***;
! calculate the lower Alpha-limit of TALLY;
long real procedure RLowerConf(Alpha);real Alpha;
begin
RLowerConf := RMean - ConfWidth(RSdev,Alpha,RObs);
end *** RLowerConf ***;
long real procedure Sdaverage;
begin
Sdaverage:=if Robs > 1
then SQRT(ABS(Robs*Rsumsq-Rsum**2)/(Robs*(Robs-1)))
else 0;
end *** SDAVERAGE ***;
if not(this Tally is Notally) then Join(Tallyq);
end*** TALLY ***;
comment NOTALLY IS USED IN HISTOGRAM. NOTALLY OBJECTS ARE
NOT ENTERED INTO TALLYQ;
Tally class Notally;;
comment------------------ C O U N T -------------------------;
Tab class Count;
begin
! 940902/peh: new variables to produce replicate report on COUNT;
long real Sum, Sumsq, Min, Max;
integer Robs;
long real Rsum,Rsumsq;
integer procedure report;
begin
Outf.SETPOS(21);
Writetrn;
Outf.OUTIMAGE;
end***REPORT***;
procedure Update(V); integer V;
begin
Obs := Obs + V;
end***UPDATE***;
INTEGER procedure Resetextra;
begin
Resetat := Time;
end *** RESETEXTRA ***;
integer procedure rreport;
begin
Outf.OUTTEXT(Title);
Outf.SETPOS(Outf.POS+(13-Title.LENGTH));
Printreal(Resetat);
Outf.OUTINT(Robs,7);
if Robs=0 then Outf.OUTTEXT(Minuses.SUB(1,10))
else
begin
Printreal(Rsum/Robs);
if Robs=1 then
begin
Outf.OUTTEXT(Minuses.SUB(1,10));
Outf.OUTTEXT(Minuses.SUB(1,10));
end
else
begin
Printreal(Sdaverage);
Printreal(Sdaverage/Sqrt(Robs));
end;
end;
Outf.OUTIMAGE;
end *** RREPORT ***;
integer procedure rupdate;
begin
if not Zyqantithetic then
begin
Robs:=Robs+1;
if Obs > 0 then
begin
Rsum:=Rsum+Obs;
Rsumsq:=Rsumsq+(1.0*Obs)**2;
end;
end;
end *** RUPDATE ***;
real procedure Sdaverage;
begin long real EN; EN := 1.0;
Sdaverage:=if Robs > 1
then SQRT(ABS(Rsumsq-Rsum**2/Robs)/(Robs-EN))
else 0;
end *** SDAVERAGE ***;
Join(Countq);
end***COUNT***;
comment-------------------- A C C U M U L A T E -------------;
Tab class Accumulate;
begin
long real Sumt, Sumsqt, Min, Max, Lasttime, Lastv, Prevspan;
integer procedure report;
begin long real Span, Avg, SDev, T;
Writetrn;
if Obs = 0 then Outf.OUTTEXT(Minuses.SUB(1, 40)) else
begin T := Time;
Span := Prevspan + T - Resetat; T := T - Lasttime;
if Span<Epsilon then Outf.OUTTEXT(Minuses.SUB(1,20)) else
begin Avg := (Sumt+Lastv*T)/Span;
Printreal(Avg);
SDev := SQRT(ABS((Sumsqt+Lastv**2*T)/Span-Avg**2));
Printreal(SDev);
Printreal(SDev/Sqrt(Obs));
end;
Printreal(Min);
Printreal(Max);
end;
Outf.OUTIMAGE;
end***REPORT***;
INTEGER procedure Reset;
begin Obs := 0;
Sumt := Sumsqt := 0.0;
Min := Max := 0.0;
Lasttime := Resetat := Time;
end***RESET***;
procedure Update(V); long real V;
begin long real Now, Span;
Obs := Obs + 1;
Now := Time;
Span := Now - Lasttime;
Lasttime := Now;
Sumt := Sumt + Lastv*Span;
Sumsqt := Sumsqt + Lastv**2*Span;
Lastv := V;
if Obs = 1 then Min := Max := V else
if V < Min then Min := V else
if V > Max then Max := V;
end*** UPDATE ***;
integer procedure rupdate;
begin
long real T,Span; T:=Time; Span:=T-Lasttime;
if Zyqantithetic then
begin
Sumt := Sumt + Lastv *Span;
Sumsqt := Sumsqt + Lastv**2*Span;
Lastv := 0; Prevspan := T - Resetat;
end;
end *** RUPDATE ***;
INTEGER procedure Resetextra;
begin
Resetat := Lasttime := Time;
if not Zyqantithetic then Prevspan:=0;
end *** RESETEXTRA ***;
Join(Accumq);
end***ACCUMULATE***;
comment-------------------- H I S T O G R A M ---------------;
Tab class Histogram(Lower, Upper, Ncells); long real Lower, Upper;
integer Ncells;
begin
integer array Table(0 : Ncells + 1);
ref(Notally)Myt;
integer Limit;
long real Width;
integer procedure report;
begin text T;
integer I, Next, A, Occ;
long real R, F, Scale, Sum, Freq;
integer procedure Maximumelement;
begin integer K, J;
if Obs > 0 then
begin K := Table(0);
for J := 1 step 1 until Limit do
if Table(J) > K then K := Table(J);
Maximumelement := K;
end;
end*** MAXIMUM ELEMENT ***;
A := 40;
Outf.SETPOS(29);
Outf.OUTTEXT("S U M M A R Y");
Outf.OUTIMAGE; Outf.OUTIMAGE;
Outf.OUTTEXT(Headingrtn);
Outf.OUTTEXT(Tallyheading);
Outf.OUTIMAGE;
Myt.Report;
Outf.OUTIMAGE;
if Obs = 0 then
begin
Outf.SETPOS(21);
Outf.OUTTEXT("***NO ENTRIES RECORDED***");
end else
begin Scale := 30 / Maximumelement;
Outf.OUTTEXT("CELL/LOWER LIM/ N/ FREQ/ CUM :");
Outf.OUTIMAGE;
Outf.SETPOS(A); Outf.OUTCHAR('I');
Outf.OUTTEXT(Minuses.SUB(1, 30)); Outf.OUTIMAGE;
F := 1/Obs;
R := Lower - Width;
for I := 0 step 1 until Limit do
begin Outf.OUTINT(I, 4);
if I = 0 then Outf.OUTTEXT(" -INFINITY")
else Printreal(R);
Next := Table(I); Outf.OUTINT(Next, 6);
Freq := Next*F; Outf.OUTFIX(Freq, 2, 8);
Sum := Sum + Freq*100.0; Outf.OUTFIX(Sum , 2, 8);
Outf.SETPOS(A); Outf.OUTCHAR('I');
if Next > 0 then
begin T :- Stars.SUB(1, Scale*Next);
if T == notext then Outf.OUTCHAR('.')
else Outf.OUTTEXT(T);
end;
Outf.OUTIMAGE;
Anymoretoprint:
Occ := Occ+Next;
if Occ = Obs and I+3 < Limit then
begin
Outf.OUTIMAGE;
Outf.SETPOS(A+6);
Outf.OUTTEXT("**REST OF TABLE EMPTY**");
Outf.OUTIMAGE;
Outf.OUTIMAGE;
goto Finish;
end;
R := R + Width;
end;
Finish:
Outf.SETPOS(A); Outf.OUTCHAR('I');
Outf.OUTTEXT(Minuses.SUB(1, 30)); Outf.OUTIMAGE;
end;
Outf.OUTIMAGE; Outf.OUTIMAGE;
end***REPORT***;
INTEGER procedure Reset;
begin integer K;
Obs := 0;
for K := 0 step 1 until Limit do
Table(K) := 0;
Resetat := Time;
if Myt =/= none then Myt.Reset;
end***RESET***;
INTEGER procedure Resetextra;
begin
Resetat := Time;
end *** RESETEXTRA ***;
procedure Update(V); long real V;
begin integer Cell;
Obs := Obs + 1;
Myt.Update(V);
V := V - Lower;
if V < 0.0 then Cell := 0 else
begin Cell := ENTIER(V/Width) + 1;
if Cell > Limit then Cell := Limit;
end;
Table(Cell) := Table(Cell) + 1;
end*** UPDATE ***;
if Upper <= Lower or Ncells < 1 then
begin
Error(19, none, this Tab, 0, "NEW HISTOGRAM(T,L,U,N);");
if Ncells < 1 then Ncells := 10;
if Lower >= Upper then
begin
Lower := 0.0;
Upper := 100.0;
end;
end;
Width := (Upper - Lower)/Ncells ;
Limit := Ncells + 1;
Myt :- new Notally(Title);
Join(Histoq);
end***HISTOGRAM***;
comment----------R E G R E S S I O N S--------------;
Tab class Regression(Title2); value Title2; text Title2;
begin
long real X, Y, Xx, Xy, Yy;
procedure Update(Vx, Vy); long real Vx, Vy;
begin
Obs := Obs + 1;
X := X + Vx;
Y := Y + Vy;
Xx := Vx**2 + Xx;
Xy := Vx*Vy + Xy;
Yy := Vy**2 + Yy;
end***UPDATE***;
integer procedure reset;
begin
Obs := 0;
Resetat := Time;
X := Y := Xx := Xy := Yy := 0.0;
end***RESET***;
INTEGER procedure Resetextra;
begin
Resetat := Time;
end *** RESETEXTRA ***;
integer procedure report;
begin
long real Dx, Dy, A0, A1, Sd, R2;
Outf.SETPOS((52-Title.LENGTH-Title2.LENGTH)//2);
Outf.OUTTEXT("REGRESSION OF '");
Outf.OUTTEXT(Title2);
Outf.OUTTEXT("' UPON '");
Outf.OUTTEXT(Title);
Outf.OUTCHAR(''');
Outf.OUTIMAGE; Outf.OUTIMAGE;
Outf.SETPOS(17);
Outf.OUTTEXT(" (RE)SET/ OBS/ XBAR/ YBAR");
Outf.OUTIMAGE;
Outf.SETPOS(17);
Printreal(Resetat);
Outf.OUTINT(Obs, 8);
if Obs > 0 then
begin
Printreal(X/Obs);
Printreal(Y/Obs);
end;
Outf.OUTIMAGE; Outf.OUTIMAGE;
if Obs <= 5 then
begin
Outf.SETPOS(24);
Outf.OUTTEXT("*** INSUFFICIENT DATA ***");
end else
begin
Dx := ABS(Obs*Xx - X**2);
Dy := ABS(Obs*Yy - Y**2);
if Dx < 0.00001 or Dy < 0.00001 then
begin
Outf.SETPOS(27);
Outf.OUTTEXT("***DEGENERATE DATA***");
Outf.OUTIMAGE;
if Dx < 0.00001 then
begin
Outf.SETPOS(25);
Outf.OUTTEXT("X = CONSTANT = ");
Printreal(X/Obs);
Outf.OUTIMAGE;
end;
if Dy < 0.00001 then
begin
Outf.SETPOS(25);
Outf.OUTTEXT("Y = CONSTANT = ");
Printreal(Y/Obs);
Outf.OUTIMAGE;
end;
end***DEGENERATE CASE***else
begin
A1 := (Obs*Xy - X*Y)/Dx;
A0 := (Y*Xx - X*Xy)/Dx;
Sd := SQRT((Yy - A0*Y - A1*Xy)/(Obs-2));
R2 := (Obs*Xy - X*Y)**2/(Dx*Dy);
Outf.OUTTEXT(" RES.ST.DEV/ EST.REG.COEFF/ INTERCEPT/");
Outf.OUTTEXT(" ST.DEV.REG.COEFF/ CORR.COEFF");
Outf.OUTIMAGE;
Outf.SETPOS( 3); Printreal(Sd);
Outf.SETPOS(18); Printreal(A1);
Outf.SETPOS(29); Printreal(A0);
Outf.SETPOS(47); Printreal(Obs*Sd/SQRT((Obs-2)*Dx));
Outf.SETPOS(59); Printreal(SQRT(R2));
Outf.OUTIMAGE;
end;
end;
Outf.OUTIMAGE;
Outf.OUTIMAGE;
end***REPORT***;
if Title2.LENGTH > 12 then Title2 :- Title2.SUB(1, 12);
end***REGRESSION***;
comment----------------SEED GENERATOR-------------------;
integer procedure Zyqnextseed;
begin integer K;
for K := 7, 13, 15, 27 do
begin Zyqseed := Zyqseed*K;
if Zyqseed >= Zyqmodulo then
Zyqseed := Zyqseed - Zyqseed//Zyqmodulo*Zyqmodulo;
end;
Zyqnextseed := Zyqseed;
end***ZYQNEXTSEED***;
procedure Setseed(N); integer N;
begin
if N < 0 then N := -N;
if N >= Zyqmodulo then N := N-N//Zyqmodulo*Zyqmodulo;
if N = 0 then N := Zyqmodulo//2;
Zyqseed := N;
end***SETSEED***;
comment-------------D I S T R I B U T I O N S---------------;
Tab class Dist;
begin integer U, Ustart, Type;
boolean Antithetic;
long real procedure Zyqsample;
begin integer K;
for K := 32, 32, 8 do
begin U := K*U;
if U >= Zyqmodulo then U := U - U//Zyqmodulo*Zyqmodulo;
end;
Zyqsample := if Antithetic then 1.0 - U/Zyqmodulo
else U/Zyqmodulo;
Obs := Obs+1;
end***ZYQSAMPLE***;
procedure Setseed(N); integer N;
begin
if N < 0 then N := -N;
if N >= Zyqmodulo then N := N-N//Zyqmodulo*Zyqmodulo;
if N = 0 then N := Zyqmodulo//2;
if this Dist in NORMAL then
this Dist qua NORMAL.Zyqeven := false;
U := N;
end***SETSEED***;
procedure Zyqfail(T1,T2,X,Y);value T1,T2;text T1,T2;real X,Y;
begin
switch Case:=Normall, Uniforml, Erlangl,
Randintl, Negexpl, Poissonl;
OUTTEXT("**ERROR IN CREATION OF ");
OUTTEXT(Disttype(Type));
OUTTEXT("DIST '");
OUTTEXT(Title);
OUTCHAR('''); OUTCHAR('.');
OUTIMAGE;
OUTTEXT(Zyqreason); OUTTEXT(T1); OUTIMAGE;
OUTTEXT(Zyqrecvry); OUTTEXT(T2);
if type>=1 and then type<=6 then goto Case(Type);
goto Join;
Normall:
Erlangl:
Negexpl:
Poissonl: OUTREAL(X, 5, 12);
goto Join;
Uniforml: OUTREAL(X, 5, 12);
OUTTEXT(", B =");
OUTREAL(Y, 5, 12);
goto Join;
Randintl: OUTINT(this Dist qua RANDINT.A, 10);
OUTTEXT(", B =");
OUTINT(this Dist qua RANDINT.B, 10);
Join: OUTCHAR('.'); OUTIMAGE; OUTIMAGE;
end***ZYQFAIL***;
integer procedure report;
! 960917/peh: new label included at position Type=9;
! 991021/peh: new label included at position Type=10;
begin switch Case := Normall, Uniforml, Erlangl, Randintl,
Negexpl, Poissonl, Drawl, Constantl, Rayleighl, Paretol;
Writetrn;
Outf.OUTCHAR(' ');
Outf.OUTTEXT(Disttype(Type));
Outf.SETPOS(41);
! 960917/peh: the upper limit is increased by 1,Type<=9;
! 991021/peh: the upper limit is increased by 1,Type<=10;
if Type>=1 and then Type<=10 then goto Case(Type);
goto Skipall;
Normall: Printreal(this Dist qua NORMAL.A);
Printreal(this Dist qua NORMAL.B);
goto Exit;
Uniforml: Printreal(this Dist qua UNIFORM.A);
Printreal(this Dist qua UNIFORM.B);
goto Exit;
Erlangl: Printreal(this Dist qua ERLANG.A);
Outf.OUTINT(this Dist qua ERLANG.B, 10);
goto Exit;
Randintl: Outf.OUTINT(this Dist qua RANDINT.A, 10);
Outf.OUTINT(this Dist qua RANDINT.B, 10);
goto Exit;
Negexpl: Printreal(this Dist qua NEGEXP.A);
goto Skip;
Poissonl: Printreal(this Dist qua POISSON.A);
goto Skip;
Drawl: Printreal(this Dist qua DRAW.A);
goto Skip;
Constantl: Printreal(this Dist qua Constant.A);
goto Skipall;
! 960917/peh: new label describtion;
Rayleighl: Printreal(this Dist qua RAYLEIGH.A);
goto Skip;
Paretol: Outf.OUTINT(this Dist qua Pareto.k, 10);
Printreal(this Dist QUA Pareto.alpha);
goto Exit;
Skip: Outf.SETPOS(61);
Exit: Outf.OUTINT(Ustart, 10);
Skipall: Outf.OUTIMAGE;
end***REPORT***;
integer procedure resetextra;
begin
if Zyqantithetic then
begin
Resetat := Time;
U := Ustart;
Antithetic := true;
end
else
begin
U:=Ustart:=Zyqnextseed;
Antithetic:=false;
end;
end *** RESETEXTRA ***;
U := Ustart := Zyqnextseed;
if this Dist in Empirical then Join(Empq)
else Join(Distq);
end***DIST***;
comment--------------------R D I S T S-------------------;
Dist class Rdist;
virtual:
PROCEDURE Sample IS long real procedure Sample;;
;
Rdist class Constant(A); long real A;
begin
long real procedure Sample;
begin Obs := Obs + 1;
Sample := A;
end***SAMPLE***;
Type := 8;
end***CONSTANT***;
Rdist class NORMAL(A, B); long real A, B;
begin long real Zyqu, Zyqv; boolean Zyqeven;
integer procedure reset;
begin
Obs := 0;
Zyqeven := false;
Resetat := Time;
end***RESET***;
long real procedure Sample;
begin long real Z;
if Zyqeven then
begin Zyqeven := false;
Z := Zyqu*COS(Zyqv);
Obs := Obs + 1;
end else
begin Zyqeven := true;
Zyqu := SQRT(-2.0*LN(Zyqsample));
Zyqv := 6.28318530717959*Zyqsample;
Z := Zyqu*SIN(Zyqv);
Obs := Obs - 1;
end;
Sample := Z*B+A;
end***SAMPLE***;
Type := 1;
if B < 0.0 then
begin B := -B;
Zyqfail("ST. DEV. 'B' < 0.0.",
"ABSOLUTE VALUE ]B] TAKEN. B IS NOW", B, 0.0);
end;
end***NORMAL***;
Rdist class NEGEXP(A); long real A;
begin
long real procedure Sample;
begin
Sample := -LN(Zyqsample)/A;
end***SAMPLE***;
Type := 5;
if A <= 0.0 then
begin A := if A < 0.0 then -A else 0.001;
Zyqfail("NON-POSITIVE VALUE FOR 'A' (=ARRIVAL RATE).",
"A RESET TO", A, 0.0);
end;
end***NEGEXP***;
Rdist class UNIFORM(A, B); long real A, B;
begin long real Zyqspan;
long real procedure Sample;
begin
Sample := Zyqspan*Zyqsample + A;
end***SAMPLE***;
Type := 2;
if A > B then
begin long real Q;
Q := A; A := B; B := Q;
Zyqfail("LOWER BOUND 'A' > UPPER BOUND 'B'.",
"BOUNDS SWAPPED. NOW, A =", A, B);
end;
Zyqspan := B-A;
end***UNIFORM***;
Rdist class ERLANG(A, B); long real A; integer B;
begin long real Zyqab;
long real procedure Sample;
begin integer K, M; long real Prod;
M := Obs;
Prod := Zyqsample;
for K := 2 step 1 until B do
Prod := Prod * Zyqsample;
Obs := M+1;
Sample := -LN(Prod)*Zyqab;
end***SAMPLE***;
Type := 3;
if A <= 0.0 then
begin A := if A < 0.0 then -A else 0.01;
Zyqfail("'A' (=1/MEAN) <= 0.0.",
"A RESET TO", A, 0.0);
end;
if B < 0 then
begin B := if B < 0 then -B else 1;
Zyqfail("'B' (ERLANG ST. DEV.) <= 0.",
"B RESET TO", B, 1);
end;
Zyqab := A/B;
end***ERLANG***;
comment--------P A R E T O --------;
Rdist class Pareto(k,alpha,m); INTEGER k;long real alpha,m;
! 991021/peh: Class for the Pareto variate;
! The Pareto distribution is truncated at m if m>0;
BEGIN
REAL c;
long real procedure Sample;
BEGIN
Sample := k/(((1-Zyqsample*c))**(1.0/alpha));
END *** SAMPLE ***;
! 991021/peh: Pareto is assigned Type=10;
Type := 10;
IF m>0 then
! calculate truncation quantile, m=max value;
c := 1-(k*1.0/m)**alpha
ELSE
! not truncated, set c=1;
c := 1;
END *** Pareto ***;
comment--------R A Y L E I G H --------;
Rdist class Rayleigh(A);long real A;
! 960917/peh: Class for the Rayleigh variate;
begin
long real phi, sigma;
long real procedure sample;
begin Obs := Obs + 1;
sample := sigma*sqrt(LN(1/Zyqsample**2));
end *** sample ***;
! 960917/peh: Rayleigh is assigned Type=9;
Type := 9;
phi := arctan(1)*4;
sigma := sqrt(2/phi)*A;
end *** Rayleigh ***;
comment--------E M P I R I C A L-------;
Rdist class Empirical(Size); integer Size;
begin long real array X, P(1 : Size);
long real procedure Sample;
begin long real Q; integer K;
Q := Zyqsample;
K := 2;
while P(K) < Q do
K := K + 1;
Sample := X(K-1) + (X(K)-X(K-1))*(Q-P(K-1))/(P(K)-P(K-1));
end***SAMPLE***;
integer procedure report;
begin integer K;
Outf.SETPOS(16);
Outf.OUTTEXT(Headingrtn); Outf.OUTTEXT("/ SEED");
Outf.OUTIMAGE;
Outf.SETPOS(16);
Writetrn;
Outf.OUTINT(Ustart, 10);
Outf.OUTIMAGE; Outf.OUTIMAGE;
Outf.SETPOS(16);
Outf.OUTTEXT(" K/ DIST. X(K)/ PROB. P(K)");
Outf.OUTIMAGE;
for K := 1 step 1 until Size do
begin
Outf.SETPOS(16);
Outf.OUTINT(K, 8);