home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / persim / part01 / show.c < prev    next >
C/C++ Source or Header  |  1992-04-06  |  5KB  |  171 lines

  1. /*Copyright  (c)   1992  Adam  Stein.   All  Rights Reserved.   
  2.  
  3.   Permission to use,  copy,  modify  and  distribute  without
  4.   charge this software, documentation, images, etc. is grant-
  5.   ed, provided that this copyright and the author's  name  is  
  6.   retained.   
  7.   
  8.   A fee may be charged for this program ONLY to recover costs   
  9.   for distribution (i.e. media costs).  No profit can be made            
  10.   on this program.   
  11.    
  12.   The author assumes no responsibility for disasters (natural   
  13.   or otherwise) as a consequence of use of this software.      
  14.    
  15.   Adam Stein (stein.wbst129@xerox.com)         
  16. */ 
  17.  
  18. #include <stdio.h>
  19. #include <math.h>
  20. #include "persim.h"
  21.  
  22. /*This routine will show the values of different variables.
  23.  
  24.   Inputs:  var        - which variable to display
  25.        whichnode  - in the case of output node attributes, which node
  26.   Outputs: none
  27.   Locals:  loop       - loop through variable elements
  28.        loop2      - loop through variable elements (for 2D arrays)
  29.   Globals: desired    - desired output values
  30.        input      - intput values
  31.        output     - output values
  32.        node_attr  - node attributes (function, threshold)
  33.        print_line - flag indicating if commands are from a batch file
  34.        ranges     - max and min values (only for step function right now)
  35.        state      - system variables
  36.        weights    - perceptron weights
  37.        ALPHA      - show alpha
  38.        AMBIGUOUS  - ambiguous variable specified
  39.        DESIRED    - show desired output values
  40.        NULL       - 0
  41.        INODES     - show number of input nodes
  42.        INPUT      - show input values
  43.        NODE       - show node attributes
  44.        ONODES     - show number of output nodes
  45.        OUTPUT     - show output values
  46.        RANGE      - show ranges
  47.        SYS_VARS   - show system variables
  48.        UNKNOWN    - variable isn't set
  49.        TRAINING   - show status of training mode
  50.        WEIGHTS    - show perceptron weights
  51. */
  52. show(var,whichnode)
  53. register int var,whichnode;
  54. {
  55.     register int loop,loop2;
  56.     extern int print_line;
  57.     extern double *input,*output,*desired,**weights,ranges[1][2];
  58.     extern NODE_ATTR *node_attr;
  59.     extern STATE state;
  60.  
  61.     switch(var) {
  62.       case ALPHA:
  63.         printf("Alpha is currently set to %lf\n",state.alpha);
  64.         break;
  65.       case AMBIGUOUS:
  66.         puts("*** ambiguous variable to show ***");
  67.         break;
  68.       case DESIRED:
  69.         if(desired == (double *) NULL)
  70.           puts("no desired output data points have been loaded");
  71.         else
  72.           for(loop = 0;loop < state.onodes;++loop)
  73.             printf("Desired Output Data Point #%d = %lf\n",loop+1,desired[loop]);
  74.         break;
  75.       case INODES:
  76.         if(state.inodes == UNKNOWN)
  77.           puts("The number of input nodes has not been set");
  78.         else
  79.           printf("The number of input nodes is currently set to %d\n",
  80.              state.inodes);
  81.         break;
  82.       case INPUT:
  83.         if(input == (double *) NULL)
  84.           puts("no input data points have been loaded");
  85.         else
  86.           for(loop = 0;loop < state.inodes;++loop)
  87.             printf("Input Data Point #%d = %lf\n",loop+1,input[loop]);
  88.         break;
  89.       case NODE:
  90.         if(node_attr == (NODE_ATTR *) NULL)
  91.           puts("no node attributes have been set");
  92.         else if(whichnode == -1)
  93.                for(loop = 0;loop < state.onodes;++loop)
  94.              show_node(loop+1,node_attr[loop]);
  95.              else show_node(whichnode,node_attr[whichnode-1]);
  96.         break;
  97.       case ONODES:
  98.         if(state.onodes == UNKNOWN)
  99.           puts("The number of output nodes has not been set");
  100.         else
  101.           printf("The number of output nodes is currently set to %d\n",
  102.              state.onodes);
  103.         break;
  104.       case OUTPUT:
  105.         if(output == (double *) NULL)
  106.           puts("no output data points have generated");
  107.         else
  108.           for(loop = 0;loop < state.onodes;++loop)
  109.             printf("Output Data Point #%d = %lf\n",loop+1,output[loop]);
  110.         break;
  111.       case RANGE:
  112.         puts("Step Function:");
  113.         printf("  min: %lf, max: %lf\n",ranges[0][0],ranges[0][1]);
  114.         break;
  115.       case SYS_VARS:
  116.         puts("System Variables:");
  117.         printf("  alpha = %lf\n",state.alpha);
  118.  
  119.         printf("  inodes = ");
  120.         if(state.inodes == UNKNOWN) puts("NOT SET");
  121.         else printf("%d\n",state.inodes);
  122.  
  123.         printf("  onodes = ");
  124.         if(state.onodes == UNKNOWN) puts("NOT SET");
  125.         else printf("%d\n",state.onodes);
  126.  
  127.         printf("  training mode is ");
  128.         if(state.training) puts("ON");
  129.         else puts("OFF");
  130.         break;
  131.       case TRAINING:
  132.         printf("training mode is ");
  133.         if(state.training) puts("ON");
  134.         else puts("OFF");
  135.         break;
  136.       case WEIGHTS:
  137.         if(weights == (double **) NULL)
  138.           puts("no weights have been loaded");
  139.         else
  140.           for(loop = 0;loop < state.inodes;++loop)
  141.             for(loop2 = 0;loop2 < state.onodes;++loop2)
  142.               if(weights[loop][loop2] != 0.0)
  143.             printf("From Input Node #%d, To Output Node #%d, Weight = %lf\n",
  144.                    loop+1,loop2+1,weights[loop][loop2]);
  145.         break;
  146.     }
  147. }
  148.  
  149. /*This routine will show the attributes of an output node.
  150.  
  151.   Inputs:  node      - node attributes
  152.        whichnode - which node to display information about
  153.   Outputs: none
  154.   Locals:  none
  155.   Globals: none
  156. */
  157. show_node(whichnode,node)
  158. register int whichnode;
  159. NODE_ATTR node;
  160. {
  161.     double step();
  162.  
  163.     printf("Output Node #%d: threshold = %lf, function = ",whichnode,
  164.                                    node.threshold);
  165.     
  166.     if(node.func == atan) puts("arctan");
  167.     else if(node.func == step) puts("step");
  168.          else  puts("NULL");
  169. }
  170.  
  171.