home *** CD-ROM | disk | FTP | other *** search
/ CICA 1994 September / CICA_Shareware_for_Windows_Walnut_Creek_September_1994.iso / win3 / programr / atre27.exe / ATREE_27 / MOSQWIN / EASYMOSQ.C next >
C/C++ Source or Header  |  1992-08-01  |  6KB  |  172 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** easymosq.c                                                          ****
  4.  **** atree release 2.7 for Windows                                       ****
  5.  **** Adaptive Logic Network (ALN) simulation program.                    ****
  6.  **** Copyright (C) A. Dwelly, R. Manderscheid, M. Thomas, W.W. Armstrong ****
  7.  ****               1991, 1992                                            ****
  8.  **** License:                                                            ****
  9.  **** A royalty-free license is granted for the use of this software for  ****
  10.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  11.  **** modified provided this notice appears in its entirety and unchanged ****
  12.  **** in all derived source programs.  Persons modifying the code are     ****
  13.  **** requested to state the date, the changes made and who made them     ****
  14.  **** in the modification history.                                        ****
  15.  ****                                                                     ****
  16.  **** Patent License:                                                     ****
  17.  **** The use of a digital circuit which transmits a signal indicating    ****
  18.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  19.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  20.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  21.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES to    ****
  22.  **** adapt logic trees using this program and its modifications.         ****
  23.  ****                                                                     ****
  24.  **** Limited Warranty:                                                   ****
  25.  **** This software is provided "as is" without warranty of any kind,     ****
  26.  **** either expressed or implied, including, but not limited to, the     ****
  27.  **** implied warrantees of merchantability and fitness for a particular  ****
  28.  **** purpose.  The entire risk as to the quality and performance of the  ****
  29.  **** program is with the user.  Neither the authors, nor the             ****
  30.  **** University of Alberta, its officers, agents, servants or employees  ****
  31.  **** shall be liable or responsible in any way for any damage to         ****
  32.  **** property or direct personal or consequential injury of any nature   ****
  33.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  34.  **** or any other party as a consequence of the use or disposition of    ****
  35.  **** this software.                                                      ****
  36.  ****                                                                     ****
  37.  **** Modification history:                                               ****
  38.  ****                                                                     ****
  39.  **** 5.9.90 Initial implementation, A.Dwelly                             ****
  40.  **** 31.5.91 Windows Port & Windows Extensions, M. Thomas                ****
  41.  **** 91.07.17 atree v2.0 for Windows, M. Thomas                          ****
  42.  **** 92.04.28 atree v2.5 for Windows, M. Thomas                          ****
  43.  **** 92.03.07 Release 2.6, Monroe Thomas                                 ****
  44.  **** 92.01.08 Release 2.7, Monroe Thomas                                 ****
  45.  ****                                                                     ****
  46.  *****************************************************************************/
  47.  
  48. #include <windows.h>
  49. #include "atree.h"
  50.  
  51. extern unsigned _hInstance;
  52.  
  53. #define VERBOSITY 0
  54. #define TRAINSETSIZE 500
  55. #define WIDTH 80
  56. #define TREESIZE 256
  57. #define TESTSIZE 500
  58.  
  59. #define BITTEN 1
  60. #define QUININE 7
  61. #define ANEMIA 12
  62.  
  63. char mosquito(v)
  64.  
  65. char *v;
  66.  
  67. {
  68.     return(v[BITTEN] && (!v[QUININE]) && (!v[ANEMIA]));
  69. }
  70.  
  71. void main()
  72.  
  73. {
  74.     int i;
  75.     int j;
  76.     int malaria = 0;
  77.     int healthy = 0;
  78.     char vec[WIDTH];
  79.     char ui[1];
  80.     int correct = 0;
  81.     LPBIT_VEC training_set;
  82.     LPBIT_VEC icres;
  83.     LPBIT_VEC test;
  84.     LPATREE tree;
  85.  
  86.     /* Initialise */
  87.  
  88.     training_set = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
  89.     MEMCHECK(training_set);
  90.  
  91.     icres = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
  92.     MEMCHECK(icres);
  93.  
  94.     atree_init(_hInstance, NULL);
  95.  
  96.     /* Create the test data */
  97.  
  98.     printf("Creating training data\n");
  99.  
  100.     for (i = 0; i < TRAINSETSIZE; i++)
  101.     {
  102.         /* allow multitasking during long loop! */
  103.         Windows_Interrupt(1500);
  104.  
  105.         for (j = 0; j < WIDTH; j++)
  106.         {
  107.             vec[j] = (char)RANDOM(2);
  108.         }
  109.         training_set[i] = *(bv_pack(vec, WIDTH));
  110.         ui[0] = mosquito(vec);
  111.         if (ui[0])
  112.         {
  113.             malaria++;
  114.         }
  115.         else
  116.         {
  117.             healthy++;
  118.         }
  119.         icres[i] = *(bv_pack(ui,1));
  120.     }
  121.  
  122.     printf("There are %d patients with malaria, and %d healthy in the training set\n",malaria,healthy);
  123.  
  124.     /* Create a tree and train it */
  125.  
  126.     printf("Training tree\n");
  127.  
  128.     tree = atree_create(WIDTH,TREESIZE);
  129.     (void) atree_train(tree,training_set,icres,0,TRAINSETSIZE,
  130.                        TRAINSETSIZE-1,10,1);
  131.  
  132.    /* Test the trained tree */
  133.  
  134.     printf("Testing the tree\n");
  135.  
  136.     for (i = 0; i < TESTSIZE; i++)
  137.     {
  138.         /* allow multitasking during long loop! */
  139.         Windows_Interrupt(1500);
  140.  
  141.         for (j = 0; j < WIDTH; j++)
  142.         {
  143.             vec[j] = RANDOM(2);
  144.         }
  145.         test = bv_pack(vec,WIDTH);
  146.         if (atree_eval(tree,test) == mosquito(vec))
  147.         {
  148.             correct++;
  149.         }
  150.         bv_free(test);
  151.     }
  152.  
  153.     printf("%d correct out of %d in final test\n",correct,TESTSIZE);
  154.  
  155.     /* Discard training set */
  156.  
  157.     for (i = 0; i < TRAINSETSIZE; i++)
  158.     {
  159.         Free(training_set[i].bv);
  160.         Free(icres[i].bv);
  161.     }
  162.  
  163.     Free(training_set);
  164.     Free(icres);
  165.  
  166.     /* Discard tree */
  167.     atree_free(tree);
  168.     atree_quit();
  169.  
  170.     printf("\nDouble click on the control menu to exit");
  171. }
  172.