/* example of external use of functions */void demo_cake2(void) { char atomfile[] = "ATOMS.DAT", knowfile[] = "KNOWS.DAT"; int numglobtimes = 30; FILE *knowfp;
if((knowfp = fopen(knowfile, "w")) == NULL) exit(1); fprintf(knowfp, "cond(and(cake,eat),happy)):1\n"); fprintf(knowfp, "cond(and(now,cake),rotten):0\n"); fprintf(knowfp, "cond(and(and(now,cake),eat),and(tomorrow,cake)):0\n"); fprintf(knowfp, "cond(and(and(now,cake),not(eat)),and(tomorrow,cake)):1\n"); fprintf(knowfp, "cond(and(tomorrow,cake),rotten):0.8\n"); fprintf(knowfp, "and(and(cake,rotten),eat):0\n"); fprintf(knowfp, "cond(and(cake,not(eat)),happy):0\n"); fclose(knowfp);
printf("OPTIMIZING TRUTH VALUES OF ATOMS"); optatoms(atomfile, knowfile, numglobtimes, OFF); evalgap(atomfile, knowfile, ON);
printf("\nATOMS\n"); prtatoms("ATOMS.DAT");
printf("\nINFERENCES\n"); lvtotv(evalform(atomfile, "cond(and(now,cake),and(now,eat))", ON)); lvtotv(evalform(atomfile, "cond(and(now,cake),and(now,happy))", ON)); lvtotv(evalform(atomfile, "cond(and(tomorrow,cake),and(tomorrow,happy))", ON)); lvtotv(evalform(atomfile, "cond(and(tomorrow,cake),and(tomorrow,eat))", ON)); printf("\n");
return;}
/* samples of demo_cake2----------------1st sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.0010101000000010 (0.1640930175781250)eat: 0.0010000100010000 (0.1291503906250000)happy: 0.0011000111011100 (0.1947631835937500)now: 0.1010011001100000 (0.6499023437500000)rotten: 0.1001100011001111 (0.5969085693359375)tomorrow: 0.1000101111011100 (0.5463256835937500)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1111000011110001 (0.9411773681640625)cond(and(now,cake),and(now,happy)): 0.1111000011110001 (0.9411773681640625)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------2nd sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0019531250000000 = 0.0000000000000000+0.0019531250000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0007382578179295; MAX ABSOL GAP: 0.0019531250000000
ATOMScake: 0.0101001000101010 (0.3209533691406250)eat: 0.1001010110100111 (0.5845794677734375)happy: 0.0001010100110110 (0.0828552246093750)now: 0.1011000101011000 (0.6927490234375000)rotten: 0.0100111001011101 (0.3061065673828125)tomorrow: 0.0010110101011010 (0.1771545410156250)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1111111110000000 (0.9980468750000000)cond(and(now,cake),and(now,happy)): 0.1111111110000000 (0.9980468750000000)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0011001100110011 (0.1999969482421875)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0011001100110011 (0.1999969482421875)
----------------3rd sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8028564453125000 = 0.8000000000000000+0.0028564453125000[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0003051757812500 = 0.0000000000000000+0.0003051757812500GAP DEV: 0.0010858096217012; MAX ABSOL GAP: 0.0028564453125000
ATOMScake: 0.1001111101101110 (0.6227722167968750)eat: 0.0110100001100000 (0.4077148437500000)happy: 0.0110100011101100 (0.4098510742187500)now: 0.0011010110011001 (0.2093658447265625)rotten: 0.1110000000010001 (0.8752593994140625)tomorrow: 0.1011111101111110 (0.7480163574218750)
INFERENCEScond(and(now,cake),and(now,eat)): 0.0000000000000000 (0.0000000000000000)cond(and(now,cake),and(now,happy)): 0.0000000001100001 (0.0014801025390625)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000110110000110 (0.0528259277343750)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000110101110011 (0.0525360107421875)
----------------4th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.0000010101000000 (0.0205078125000000)eat: 0.0110110010011011 (0.4242401123046875)happy: 0.1010111000011001 (0.6800689697265625)now: 0.1010111001001110 (0.6808776855468750)rotten: 0.0101101100001100 (0.3556518554687500)tomorrow: 0.1111101111001010 (0.9835510253906250)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1111000011110001 (0.9411773681640625)cond(and(now,cake),and(now,happy)): 0.1111000011110001 (0.9411773681640625)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------5th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.0101100000000000 (0.3437500000000000)eat: 0.0010100010010111 (0.1585540771484375)happy: 0.0010111011110010 (0.1833801269531250)now: 0.1001110010101110 (0.6120300292968750)rotten: 0.1100011100001100 (0.7775268554687500)tomorrow: 0.1111010010100110 (0.9556579589843750)
INFERENCEScond(and(now,cake),and(now,eat)): 0.0101010101010101 (0.3333282470703125)cond(and(now,cake),and(now,happy)): 0.0101010101010101 (0.3333282470703125)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------6th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.1000011110001000 (0.5294189453125000)eat: 0.1001000001001111 (0.5637054443359375)happy: 0.1111000000011001 (0.9378814697265625)now: 0.1100100010100110 (0.7837829589843750)rotten: 0.0111011001100111 (0.4625091552734375)tomorrow: 0.0000111110110010 (0.0613098144531250)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1111111100000001 (0.9961090087890625)cond(and(now,cake),and(now,happy)): 0.1111111100000001 (0.9961090087890625)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------7th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.0100101100000000 (0.2929687500000000)eat: 0.1101010000011010 (0.8285217285156250)happy: 0.0101010011010111 (0.3314056396484375)now: 0.0101011001100111 (0.3375091552734375)rotten: 0.0010100110001011 (0.1622772216796875)tomorrow: 0.0001101011001110 (0.1047058105468750)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1111100000111110 (0.9696960449218750)cond(and(now,cake),and(now,happy)): 0.1111100000111110 (0.9696960449218750)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------8th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9995574951171875 = 1.0000000000000000-0.0004425048828125[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8013305664062500 = 0.8000000000000000+0.0013305664062500[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0005300202642214; MAX ABSOL GAP: 0.0013305664062500
ATOMScake: 0.1010011111101111 (0.6559906005859375)eat: 0.1101001010011111 (0.8227386474609375)happy: 0.1000001010000000 (0.5097656250000000)now: 0.0100110100110000 (0.3015136718750000)rotten: 0.0111000000000000 (0.4375000000000000)tomorrow: 0.0110111111111111 (0.4374847412109375)
INFERENCEScond(and(now,cake),and(now,eat)): 0.0000000000000000 (0.0000000000000000)cond(and(now,cake),and(now,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0001000000000111 (0.0626068115234375)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0001000001100111 (0.0640716552734375)
----------------9th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.7998504638671875 = 0.8000000000000000-0.0001495361328125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000571048112857; MAX ABSOL GAP: 0.0001495361328125
ATOMScake: 0.0101011000110001 (0.3366851806640625)eat: 0.0010010111100100 (0.1480102539062500)happy: 0.0000110101101100 (0.0524291992187500)now: 0.0000000010001111 (0.0021820068359375)rotten: 0.0101001011000000 (0.3232421875000000)tomorrow: 0.1011010111001001 (0.7100982666015625)
INFERENCEScond(and(now,cake),and(now,eat)): 0.0000000000000000 (0.0000000000000000)cond(and(now,cake),and(now,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0011001100110001 (0.1999664306640625)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0011001100110001 (0.1999664306640625)
----------------10th sample
OPTIMIZING TRUTH VALUES OF ATOMS..........[1] cond(and(cake,eat),happy)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[2] cond(and(now,cake),rotten): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[3] cond(and(and(now,cake),eat),and(tomorrow,cake)): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[4] cond(and(and(now,cake),not(eat)),and(tomorrow,cake)): 0.9999847412109375 = 1.0000000000000000-0.0000152587890625[5] cond(and(tomorrow,cake),rotten): 0.8000030517578125 = 0.8000000000000000+0.0000030517578125[6] and(and(cake,rotten),eat): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000[7] cond(and(cake,not(eat)),happy): 0.0000000000000000 = 0.0000000000000000+0.0000000000000000GAP DEV: 0.0000082373237077; MAX ABSOL GAP: 0.0000152587890625
ATOMScake: 0.1101000000100000 (0.8129882812500000)eat: 0.1000001101010001 (0.5129547119140625)happy: 0.1000000011010011 (0.5032196044921875)now: 0.1001001011000010 (0.5732727050781250)rotten: 0.0110110000001111 (0.4221038818359375)tomorrow: 0.0111110110011111 (0.4907073974609375)
INFERENCEScond(and(now,cake),and(now,eat)): 0.1110001110001110 (0.8888854980468750)cond(and(now,cake),and(now,happy)): 0.1110001110001110 (0.8888854980468750)cond(and(tomorrow,cake),and(tomorrow,happy)): 0.0000000000000000 (0.0000000000000000)cond(and(tomorrow,cake),and(tomorrow,eat)): 0.0000000000000000 (0.0000000000000000)
----------------*/