1 REM BAYES  
10 CLS:PRINT  TAB(10); "BAYES PROBABILITIES":PRINT   
20 PRINT"THIS THEOREM USES BAYES THEOREM TO REVISE ESTIMATES OF  
25 PRINT "THE PROBABILITIES OF THE OCCURRENCE OF THE VARIOUS STATES OF   
30 PRINT "NATURE. INPUT TO THIS PROGRAM ARE THE PROBABILITIES OF A  
35 PRINT "A FINITE AND USER SELECTABLE NUMBER OF STATES OF NATURE,   
40 PRINT "THESE PROBABILITIES MUST SUM UP TO 1. IN ADDITION,  
45 PRINT "THERE MUST BE INPUT FOR EACH STATE OF NATURE THE PROBABILITY  
50 PRINT "OF A CERTAIN EVENT,SAY B, OCCURRING GIVEN THAT STATE OF  
55 PRINT "IS THE TRUE STATE OF NATURE. THEN THE PROGRAM WILL COMPUTE  
60 PRINT "THE CONDITIONAL PROBAILITIES OF EACH OF THE STATES OF NATURE  
70 PRINT "BEING TRUE GIVEN THAT EVENT B OCCURS. THESE ARE CALLED  
75 PRINT "POSTERIOR PROBABILITIES AND MAY BE USED IN DECISION MAKING  
90 PRINT :INPUT "PRESS ENTER TO BEGIN";Z9$  
95 CLEAR  1000  
100 DIM  AB(100),BA(100),A(100)  
110 CLS  
120 N=0  
130 PRINT "ENTER PROBABILITIES OF POSSIBLE STATES OF NATURE 1 BY 1.  
135 PRINT "THESE PROBABILITIES SHOULD ADD TO 1.":PRINT   
140 PRINT  "ENTER PROB. ST. OF NATURE";N+1;"(-1 TO END)";:INPUT  A(N+1)  
150 IF A(N+1)=-1 THEN GOTO 500 ' REM ALL OVER  
160 N=N+1:P=P+A(N)  
170 GOTO  140  
500 REM END OF COMPUTATION  
510 IF  P=1  THEN  GOTO  550  
520 CLS:PRINT "PROBABILITIES SUM TO";P;"THIS SHOULD BE STANDARDIZED  
530 PRINT "TO SUM TO 1. ENTER 1 TO STANDARDIZE, 0 TO END";:INPUT  Z9  
540 IF  Z9<>1  AND  Z9<>0  THEN  GOSUB  10000:GOTO  530  
550 IF  Z9=0  THEN  END  
560 FOR  I=1 TO N:A(I)=A(I)/P:NEXT :P=1  
570 CLS  
580 FOR  I=1  TO  N  
590 PRINT "ENTER COND.PROB. OF EVENT B GIVEN ST.OF.NATURE";I;:INPUT  BA(I)  
600 NEXT  I  
610 PB=0  
620 FOR I=1 TO N:PB=PB+A(I)*BA(I):NEXT:REM PB=PROBABILITY OF B  
625 IF  PB>1  THEN  PRINT "PROBABILITY OF B IS GREATER THAN 1. PROGRAM WILL ABORT":END  
630 FOR  I=1 TO N:AB(I)=BA(I)*A(I)/PB:NEXT  I  
700  F$(1)="S OF N    ORIG.      PROB B       POSTERIOR PROB"  
710 F$(2)="          PROB.   GIVEN S OF N    S OF N GIVEN B"  
720 F$(3)=" ###      #.###      #.###            #.###"  
750 INPUT "IS LINE PRINTER OUTPUT DESIRED(Y/N)";Z2$  
760 IF  Z2$<>"Y"  AND  Z2$<>"N"  THEN  GOSUB  10000:GOTO  750  
800 CLS:PRINT  F$(1):PRINT  F$(2):IF  Z2$="Y"  THEN  LPRINT  F$(1):LPRINT  F$(2):LPRINT " "  
810 FOR  I=1  TO  N  
820 PRINT USING  F$(3);I,A(I),BA(I),AB(I)  
830 IF  Z2$="Y"  THEN  LPRINT  USING  F$(3);I,A(I),BA(I),AB(I)  
840 NEXT   
890 INPUT "PRESS ENTER FOR ANOTHER COMPUTATION";Z9$  
892 IF Z9$ = "0" THEN END
895 GOTO  95  
10000 PRINT "INPUT ERROR!TRY AGAIN!":FOR  Q=1 TO 300:NEXT :RETURN   
10100 INPUT "PRESS ENTER TO CONTINUE";Z9$:RETURN   

