home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / misc / b186_1 / Source / c / ia < prev    next >
Text File  |  1987-09-27  |  19KB  |  866 lines

  1. /*
  2.  
  3.        This file is part of the PDP software package.
  4.          
  5.        Copyright 1987 by James L. McClelland and David E. Rumelhart.
  6.        
  7.        Please refer to licensing information in the file license.txt,
  8.        which is in the same directory with this source file and is
  9.        included here by reference.
  10. */
  11.  
  12.  
  13. /*
  14.  
  15.     Guts if interactive activation model.
  16.  
  17.     Initial adaptation by Eliot Jaffe, 8-86 from the original
  18.     program of Rumelhart and McClelland.
  19.     
  20.     Date of last revision:  8-12-87/JLM.
  21.  
  22. */        
  23.  
  24. #include "ia.h"
  25. #include "io.h"
  26. #include <math.h>
  27. #include "general.h"
  28.  
  29. int nunits = NWORD+WLEN*(NLET+NFET*LLEN);
  30. int ninputs, noutputs;
  31. int System_Defined = 1;
  32.  
  33. char alphabet[26][2] = {"a","b","c","d","e","f","g","h","i","j",
  34.                 "k","l","m","n","o","p","q","r","s","t",
  35.                 "u","v","w","x","y","z"};
  36.  
  37. char uc_alphabet[26][2] = {"A","B","C","D","E","F","G","H","I","J",
  38.                 "K","L","M","N","O","P","Q","R","S","T",
  39.                 "U","V","W","X","Y","Z"};
  40.  
  41. float   a[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  42. float   g[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
  43. /* the default values are: */
  44. /* float   a[7] = { 0.0, 0.005, 0.0, 0.0, 0.07, 0.30, 0.0}; */
  45. /* float   g[7] = { 0,.15, 0, 0,.04, 0, .21 }; */
  46. /* for the sake of the exercises, we've put these in ia.par */
  47. float oscale[7] = { 0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 20.0};
  48. float   min[7] = { 0, 0, 0, -.2, 0, 0, -.2 };
  49. float   b[7] = { 0, 0, 0, .07, 0, 0, .07 };
  50. float   t[7] = { 0, 0, 0, 0, 0, 0, 0};
  51. float   rest[7] = { 0, 0, 0, 0, 0, 0, 0};
  52. float   max[7] =  { 0, 0, 0, 1, 0, 0, 1};
  53. float    dthresh[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
  54.  
  55. int     ftime[NFIELDS];
  56. float   fdprob[NFIELDS] = {   1, 1, 1, 1, 1, 1, 1};
  57. float   estr[WLEN] = { 1.0, 1.0, 1.0, 1.0};
  58. float   outrate = .05;
  59. float   fgain = .05;
  60.  
  61. char    *trial_history[NFIELDS];
  62. char    th[NFIELDS][10];
  63. char    field[NFIELDS][WLEN + 1];
  64.  
  65. char    fetbuf[NFET][WLEN][LLEN + 1] = {
  66.     "00000000000000", "00000000000000",
  67.     "00000000000000", "00000000000000",
  68.     "00000000000000", "00000000000000",
  69.     "00000000000000", "00000000000000"
  70. };
  71.  
  72. float   input[NFET][LLEN][WLEN];
  73. float   dinput[NFET][LLEN][WLEN];
  74. double  out[WLEN][NLET];
  75. double  wout[NWORD];
  76. float   blankin = .2;
  77. int     cycleno = 0;
  78. int     fieldno = 0;
  79. int     ncycles = 10;
  80. int    compute_resprob = 1;
  81. float   prsum, sum, sm[WLEN], prsm[WLEN];
  82.  
  83. int     tally, tal[WLEN];
  84. float   wa[NWORD],
  85.         wr[NWORD];
  86. float   ew[NWORD],
  87.         iw[NWORD];
  88. float  *wp,*wrp;
  89. float  *ewp,
  90.        *iwp;
  91. double *owp;
  92. float   l[WLEN][NLET],
  93.         el[WLEN][NLET],
  94.         il[WLEN][NLET];
  95. float   ss,
  96.         ssm[WLEN];
  97. int     numw = 0;
  98. int     numl[WLEN] = {0,0,0,0};
  99. int     wi[30];
  100. int li[WLEN][15];
  101. int    fc_defined;
  102. int    list_defined;
  103. int    fc_pos;
  104. int    fc_let[2];
  105. float    fc_max;
  106.  
  107. char    *disp_word_ptr[30];
  108. char    *disp_fc_ptr[2] = {"-", "-"};
  109. char    *disp_let_ptr[WLEN][15];
  110. float    disp_word_act[30];
  111. float    disp_fc_act[2];
  112. float   disp_let_act[WLEN][15];
  113. float    disp_word_rpr[30];
  114. float    disp_fc_rpr[2];
  115. float   disp_let_rpr[WLEN][15];
  116. int     cnw, cnl[WLEN];
  117.  
  118.  
  119. setinput() {
  120.     register int i,j,k;
  121.     if (getlet(field[fieldno]) == BREAK) return(BREAK);
  122.     for (k = 0; k < WLEN; k++) {
  123.     for (j = 0; j < LLEN; j++) {
  124.         for (i = 0; i < NFET; i++) {
  125.         dinput[i][j][k] = 0;
  126.         }
  127.         if (rnd() < fdprob[fieldno]) {
  128.         for (i = 0; i < NFET; i++) {
  129.             dinput[i][j][k] =
  130.             input[i][j][k];
  131.         }
  132.         }
  133.     }
  134.     }
  135.     fieldno++;
  136.     return(CONTINUE);
  137. }
  138.  
  139. cycle() {
  140.     register int    i,
  141.                     j,
  142.                     k;
  143.     int     tme;
  144.     for (tme = 0; tme < ncycles; tme++) {
  145.     cycleno++;
  146.     if (cycleno == ftime[fieldno]) {
  147.         if (setinput() == BREAK) {
  148.             update_out_values();
  149.             update_display();
  150.             return(BREAK);
  151.         }
  152.     }
  153.     interact();
  154.     wupdate();
  155.     lupdate();
  156.     if (step_size == CYCLE) {
  157.         update_out_values();
  158.         update_display();
  159.         if (single_flag) {
  160.         if (contin_test() == BREAK) return(BREAK);
  161.         }
  162.     }
  163.     if (Interrupt) {
  164.            Interrupt_flag = 0;
  165.        update_display();
  166.        if (contin_test() == BREAK) return(BREAK);
  167.     }
  168.     }
  169.     if (step_size > CYCLE) {
  170.     update_out_values();
  171.     update_display();
  172.     }
  173.     return(CONTINUE);
  174. }
  175.  
  176. interact() {
  177.     register int    i, j, k, m;
  178.     float out, eout, iout;
  179.     
  180. /* letter -> word */
  181.     for (i = 0; i < NLET; i++) {
  182.     for (j = 0; j < WLEN; j++) {
  183.         out = l[j][i] - t[L];
  184.         if (out > 0) {
  185.             eout = a[LU] * out;
  186.         iout = g[LU] * out;
  187.         for (k = 0; k < NWORD; k++) {
  188.             if (i == (word[k][j] - 'a'))
  189.             ew[k] += eout;
  190.             else
  191.             iw[k] += iout;
  192.         }
  193.         }
  194.     }
  195.     }
  196.     
  197. /* word -> letter */
  198.     for (k = 0; k < NWORD; k++) {
  199.     out = wa[k] - t[WD];
  200.     if (out > 0) {
  201.         eout = a[WD] * out;
  202.             for (j = 0; j < WLEN; j++) {
  203.         i = (word[k][j] - 'a');
  204.         el[j][i] += eout;
  205.         }
  206.     }
  207.     }
  208.     
  209. /* feature -> letter */
  210.     for (j = 0; j < WLEN; j++) {
  211.         for (k = 0; k < LLEN; k++) {
  212.         for (m = 0; m < NFET; m++) {
  213.         out = dinput[m][k][j];
  214.         if (out > 0) {
  215.             eout = estr[j] * a[FU] * out;
  216.             iout = estr[j] * g[FU] * out;
  217.             for (i = 0; i < NLET; i++) {
  218.             if (m == uc[i][k])
  219.                 el[j][i] += eout;
  220.             else
  221.                 il[j][i] += iout;
  222.             }
  223.         }
  224.         }
  225.     }
  226.     }
  227. }
  228.  
  229.  
  230. wupdate() {
  231.     int     i;
  232.     float net, effect;
  233.     ss = sum;
  234.     prsum = sum = 0;
  235.     tally = 0;
  236.  
  237.     /* pointers for efficiency */
  238.     for (wp = wa, wrp = wr,  ewp = ew, iwp = iw, owp = wout;
  239.      wp < wa + NWORD; 
  240.      wp++,wrp++,ewp++,iwp++,owp++) {
  241.     if (*wp > t[W])
  242.         *iwp += g[W] * (ss - (*wp - t[W]));
  243.     else
  244.         *iwp += g[W] * ss;
  245.     net = *ewp - *iwp;
  246.     if (net > 0)
  247.         effect = (max[W] - *wp) * (net);
  248.     else
  249.         effect = (*wp - min[W]) * (net);
  250.     *wp += effect - b[W]*(*wp - *wrp);
  251.     if (*wp > 0) {
  252.         if (*wp > max[W]) *wp = max[W];
  253.         tally++;
  254.         prsum += *wp;
  255.     }
  256.     else {
  257.         if (*wp < min[W]) *wp = min[W];
  258.     }
  259.     if (*wp > t[W])    sum += *wp - t[W];
  260.     if (compute_resprob == 2) {
  261.         *owp = *owp * (1 - outrate) + *wp * outrate;
  262.     }
  263.     *ewp = *iwp = 0;
  264.     }
  265. }
  266.  
  267. lupdate() {
  268.     register int    i,j;
  269.     float elv, ilv,lv;            
  270.     float net, effect;
  271.  
  272.     for (i = 0; i < WLEN; i++) {
  273.     ssm[i] = sm[i];
  274.     tal[i] = prsm[i] = sm[i] = 0;
  275.     }
  276.  
  277.     for (j = 0; j < WLEN; j++) {
  278.     for (i = 0; i < NLET; i++) {
  279.         lv = l[j][i];
  280.         elv = el[j][i];
  281.         ilv = il[j][i];
  282.         if (lv > t[L])
  283.         ilv += g[L] * (ssm[j] - (lv - t[L]));
  284.         else
  285.         ilv += g[L] * ssm[j];
  286.         net = elv - ilv;
  287.         if (net > 0)
  288.         effect = (max[L] - lv) * net;
  289.         else
  290.         effect = (lv - min[L]) * net;
  291.         lv += effect - b[L]*(lv - rest[L]);
  292.         if (lv > 0) {
  293.         if (lv > 1)
  294.             lv = 1;
  295.         tal[j]++;
  296.         if (lv > t[L])
  297.             sm[j] += lv - t[L];
  298.         prsm[j] += lv;
  299.         }
  300.         else
  301.         if (lv < min[L])
  302.             lv = min[L];
  303.         if (compute_resprob > 0) {
  304.         out[j][i] = out[j][i] * (1 - outrate) + lv * outrate;
  305.         }
  306.         l[j][i] = lv;
  307.         el[j][i] = il[j][i] = 0;
  308.     }
  309.     }
  310. }
  311.  
  312. putfet(pos) int pos; {
  313.     int     i;
  314.     char    *tinbf;
  315.  
  316.     tinbf = get_command("absent: ");
  317.     if (tinbf != NULL) {
  318.     (void)strcpy(fetbuf[0][pos], tinbf);
  319.     }
  320.     else {
  321.     (void)strcpy(fetbuf[0][pos], "00000000000000");
  322.     }
  323.     tinbf = get_command("present: ");
  324.     if (tinbf != NULL) {
  325.     (void)strcpy(fetbuf[1][pos], tinbf);
  326.     }
  327.     else {
  328.     (void)strcpy(fetbuf[1][pos], "00000000000000");
  329.     }
  330. }
  331.  
  332. getfet(pos) {
  333.     int i;
  334.     for (i = 0; i < LLEN; i++) {
  335.     input[0][i][pos] = fetbuf[0][pos][i] - '0';
  336.     }
  337.     for (i = 0; i < LLEN; i++) {
  338.     input[1][i][pos] = fetbuf[1][pos][i] - '0';
  339.     }
  340. }
  341.  
  342. mkkr(pos)
  343. int     pos;
  344. {
  345.     int     i;
  346.     char tstring[40];
  347.  
  348.     (void)strcpy(tstring, "00001100011001");
  349.     for (i = 0; i < LLEN; i++) {
  350.     input[0][i][pos] = (float) (tstring[i] - '0');
  351.     }
  352.     (void)strcpy(tstring, "11000010000010");
  353.     for (i = 0; i < LLEN; i++) {
  354.     input[1][i][pos] = (float) (tstring[i] - '0');
  355.     }
  356. }
  357.  
  358. getlet(in)
  359. char   *in;
  360. {
  361.     int     i,
  362.             j,
  363.             k,
  364.             index;
  365.  
  366.     for (k = 0; k < WLEN; k++) {
  367.     if (in[k] == '_') {
  368.         for (i = 0; i < LLEN; i++)
  369.         input[0][i][k] = input[1][i][k] = 0;
  370.         continue;
  371.     }
  372.     if (in[k] == '"') {
  373.         getfet(k);
  374.         continue;
  375.     }
  376.     if (in[k] == '*') {
  377.         mkkr(k);
  378.         continue;
  379.     }
  380.     if (in[k] == '#') {
  381.     /* the X-O mask character */
  382.         for (i = 0; i < 6; i++) {
  383.         input[0][i][k] = 0.0;
  384.         input[1][i][k] = 1.0;
  385.         }
  386.         for (; i < 10; i++) {
  387.         input[0][i][k] = 1.0;
  388.         input[1][i][k] = 0.0;
  389.         }
  390.         for (; i < LLEN; i++) {
  391.         input[0][i][k] = 0.0;
  392.         input[1][i][k] = 1.0;
  393.         }
  394.         continue;
  395.     }
  396.     if (in[k] == '.') {
  397.         for (i = 0; i < LLEN; i++) {
  398.         input[0][i][k] = blankin;
  399.         input[1][i][k] = 0;
  400.         }
  401.         continue;
  402.     }
  403.     if (in[k] == '?') {
  404.         for (i = 0; i < LLEN; i++) {
  405.         if (rnd() >=.5)
  406.             j = 1;
  407.         else
  408.             j = 0;
  409.         input[1 - j][i][k] = 0;
  410.         input[j][i][k] = 1.0;
  411.         }
  412.         continue;
  413.     }
  414.     if (isupper(in[k])) {
  415.       index = in[k] - 'A';
  416.     }
  417.     else {
  418.       put_error("Invalid character encountered in trial specification.");
  419.       return(BREAK);
  420.     }
  421.     for (i = 0; i < LLEN; i++) {
  422.         j = uc[index][i];
  423.         input[1 - j][i][k] = 0;
  424.         input[j][i][k] = 1.0;
  425.     }
  426.     }
  427.     return(CONTINUE);
  428. }
  429.  
  430. zarrays() {
  431.     int     i,
  432.             j,
  433.             k;
  434.     srand(random_seed);
  435.     cycleno = 0;
  436.     tally = 0;
  437.     fieldno = 0;
  438.     prsum = sum = ss = 0;
  439.     for (i = 0; i < NWORD; i++) {
  440.     ew[i] = iw[i] = 0;
  441.     wout[i] = wa[i] = wr[i] = fgain * freq[i] + rest[W];
  442.     }
  443.     for (j = 0; j < WLEN; j++)
  444.     for (k = 0; k < NLET; k++)
  445.         l[j][k] = out[j][k] = 0 + rest[L];
  446.     el[j][k] = il[j][k] = 0;
  447.     for (i = 0; i < WLEN; i++) {
  448.     for (j = 0; j < LLEN; j++) {
  449.         for (k = 0; k < NFET; k++)
  450.         dinput[k][j][i] = input[k][j][i] = 0;
  451.     }
  452.     }
  453.     for (i = 0; i < WLEN; i++) {
  454.     prsm[i] = sm[i] = ssm[i] = 0;
  455.     tal[i] = 0;
  456.     }
  457.     fc_max = 0.0;
  458.     update_out_values();
  459.     return(CONTINUE);
  460. }
  461.  
  462. trial() {
  463.     int     i,j,pos;
  464.     int        prevtime;
  465.     char    *str;
  466.     char    tempstr[40];
  467.     char    ststr[40];
  468.  
  469.     prevtime = 0;
  470.     
  471.     for (i = 0; i < NFIELDS; i++) {
  472.     trial_history[i] = &th[i][0];
  473.     }
  474.     for (i = 0; i < NFIELDS; i++) {
  475. gettime:    
  476.     (void)sprintf(tempstr,"field #%d: time: ",i);
  477.     str = get_command(tempstr);
  478.     if (!str || (strcmp(str,"end") == 0)) {
  479.         ftime[i] = 0;
  480.         break;
  481.     }
  482.     if (sscanf(str,"%d",&j) == 0) {
  483.         put_error("Time must be an integer.");
  484.         goto gettime;
  485.     }
  486.     if (j <= prevtime) {
  487.         put_error("Times must be strictly increasing.");
  488.         goto gettime;
  489.     }        
  490.     ftime[i] = j;
  491.     strcpy(ststr,tempstr);
  492.     (void) sprintf(tempstr,"%s %d contents: ",ststr,j);
  493.     str = NULL;
  494. getstring:    
  495.     str = get_command(tempstr);
  496.     if (strlen(str) != 4) {
  497.         put_error("Field contents must be 4 characters.");
  498.         goto getstring;
  499.     }
  500.     for (pos = 0; pos < 4; pos++) {
  501.       if(islower(str[pos])) str[pos] = toupper(str[pos]);
  502.     }
  503.     (void)strcpy(field[i],str);
  504.     for (pos = 0; pos < 4; pos++) {
  505.       if (field[i][pos] == '"') {
  506.         putfet(pos);
  507.       }
  508.     }
  509.         (void)sprintf(th[i],"%2d %s",ftime[i],field[i]);
  510.     }
  511.     change_variable_length("trial",i,10);
  512.     newstart();
  513.     return(CONTINUE);
  514. }
  515.  
  516. clear_disp_list() {
  517.     int i;
  518.     for ( i = 0; i < WLEN; i++) {
  519.         cnl[i] = numl[i] = 0;
  520.     }
  521.     cnw = numw = 0;
  522.     list_defined = 0;
  523.     change_lengths();
  524. }
  525.  
  526. get_disp_list() {
  527.     int     i;
  528.     char   *in = NULL;
  529.     char    temp[100];
  530.     char    str[5];
  531.     
  532.     clear_disp_list();
  533.     cnw = numw = 0;
  534.     in = get_command("enter words or - for dynamic specification: ");
  535.     if (in && in[0] == '-') return(CONTINUE);
  536.     while (in != NULL && strcmp(in,"end") != 0) {
  537.         for (i = 0; i < WLEN; i++) {
  538.         if (in[i] && isupper(in[i])) {
  539.             in[i] = tolower(in[i]);
  540.         }
  541.     }
  542.     for (i = 0; i < NWORD; i++) {
  543.         if (!strcmp(in, word[i])) {
  544.         wi[numw++] = i;
  545.         break;
  546.         }
  547.     }
  548.     if (i == NWORD) {
  549.         sprintf(err_string,"Unrecognized word: %s.",in);
  550.         put_error(err_string);
  551.     }
  552.     in = get_command("next word (end with end or <cr>): ");
  553.     }
  554.     cnw = numw;
  555.  
  556.     for (i = 0; i < WLEN; i++) {
  557.         numl[i] = 0;
  558.     sprintf(temp,"position %d, letter (end with end or <cr>): ", i);
  559.     in = get_command(temp);
  560.     while (in != NULL && strcmp(in,"end") != 0) {
  561.       if (isupper(in[0])) in[0] = tolower(in[0]);
  562.       if (islower(in[0])) {
  563.         li[i][numl[i]] = in[0] - 'a';
  564.       }
  565.       else {
  566.         put_error("Entries must be letters.");
  567.         goto tryagain;
  568.       }
  569.       numl[i]++;
  570. tryagain:
  571.       in = get_command(temp);      
  572.     }
  573.     cnl[i] = numl[i];
  574.     }
  575.     if (numw > 0 || numl[0] > 0 || numl[1] > 0 || numl[2] > 0 || numl[3] > 0){
  576.       list_defined = 1;
  577.       change_lengths();
  578.     }
  579.     update_out_values();
  580.     return(CONTINUE);
  581. }
  582.  
  583. fc() {
  584.     int     i;
  585.     char   *in = NULL;
  586.     char    temp[40];
  587.     char    str[5];
  588.     
  589.     fc_defined = 0;
  590.     fc_max = 0;
  591. getpos:    
  592.     in = get_command("fc position (0 to 3, - to clear): ");
  593.     if (in == NULL || in[0] == '-') {
  594.         fc_pos = 0;
  595.     disp_fc_ptr[0] = "-";
  596.     disp_fc_ptr[1] = "-";
  597.     fc_let[0] = fc_let[1] = 0;
  598.     fc_max = 0.0;
  599.     disp_fc_act[0] = disp_fc_act[1] = 0.0;
  600.     disp_fc_rpr[0] = disp_fc_rpr[1] = 0.0;
  601.     return(CONTINUE);
  602.     }
  603.     if (sscanf(in,"%d",&fc_pos) != 1) {
  604.         put_error("Must give an position number!");
  605.         goto getpos;
  606.     }
  607.     if (fc_pos < 0 || fc_pos > 3) {
  608.             put_error("Position must be 0, 1, 2, or 3.");
  609.         goto getpos;
  610.     }
  611. getcor:    
  612.     in = get_command("correct alternative: ");
  613.     if (!in) {
  614.     put_error("Must specify a letter.");
  615.     goto getcor;
  616.     }
  617.     if (islower(in[0])) {
  618.     in[0] = toupper(in[0]);
  619.     }
  620.     if (isupper(in[0])) fc_let[0] = in[0] - 'A';
  621.     else {
  622.         put_error("Alternatives must be letters.");
  623.     goto getcor;
  624.     }
  625. getinc:    
  626.     in = get_command("incorrect alternative: ");
  627.     if (!in) {
  628.     put_error("Must specify a letter.");
  629.     goto getinc;
  630.     }
  631.     if (islower(in[0])) {
  632.        in[0] = toupper(in[0]);
  633.     }
  634.     if (isupper(in[0])) fc_let[1] = in[0] - 'A';
  635.     else {
  636.         put_error("Alternatives must be letters.");
  637.     goto getinc;
  638.     }
  639.     disp_fc_ptr[0] = uc_alphabet[fc_let[0]];
  640.     disp_fc_ptr[1] = uc_alphabet[fc_let[1]];
  641.     fc_defined = 1;
  642.     update_display();
  643.     return(CONTINUE);
  644. }
  645.  
  646. printout() {
  647.     int     i,
  648.             j,
  649.             cnt,
  650.             lcnt;
  651.     char   *str;
  652.     double  lpow;
  653.     double  tstr;
  654.  
  655.     lpow = exp(oscale[L]);
  656.     
  657.     str = NULL;
  658.     while(str == NULL)
  659.       str = get_command("print words? ");
  660.     cnt = 0;
  661.     lcnt = 0;
  662.     if (*str == 'y') {
  663.     io_move(1,0);
  664.     clear_display();
  665.     for (i = 0; i < NWORD; i++) {
  666.         io_printw("%s ", word[i]);
  667.         io_printw("%.2f ", wa[i]);
  668.         cnt++;
  669.         if (cnt % 7 == 0) {
  670.             lcnt++;
  671.             io_printw("\n",NULL);
  672.             if (lcnt % 23 == 0) {
  673.             if (contin_test() == BREAK) {
  674.               break;
  675.             }
  676.             else {
  677.                 io_move(1,0);
  678.                 clear_display();
  679.             }              
  680.             }
  681.         }
  682.     }
  683.     }
  684.     str = NULL;
  685.     while(str == NULL)
  686.       str = get_command("print letters? ");
  687.     if (*str == 'y') {
  688.     clear_display();
  689.     io_move(1,0);
  690.     for (i = 0; i < NLET / 2; i++) {
  691.         io_printw("%c ", i + 'a');
  692.         for (j = 0; j < WLEN; j++)
  693.             io_printw("%6.3f ", l[j][i]);
  694.         io_printw("    ",NULL);
  695.         io_printw("%c ", i + 13 + 'a');
  696.         for (j = 0; j < WLEN; j++)
  697.             io_printw("%6.3f ", l[j][i + 13]);
  698.         io_printw("\n",NULL);
  699.     }
  700.     }
  701.     str = NULL;
  702.     while(str == NULL)
  703.        str = get_command("print letter resp-probs? ");
  704.   if (str[0] == 'y') {
  705.     clear_display();
  706.     io_move(1,0);
  707.     for (i = 0; i < WLEN; i++) {
  708.     ssm[i] = 0;
  709.     for (j = 0; j < NLET; j++)
  710.         ssm[i] += pow(lpow, out[i][j]);
  711.     }
  712.     for (i = 0; i < NLET / 2; i++) {
  713.     io_printw("%c ", i + 'a');
  714.     for (j = 0; j < WLEN; j++) {
  715.         tstr = pow(lpow, out[j][i]) / ssm[j];
  716.         io_printw("%.3f ", tstr );
  717.     }
  718.     io_printw("    ",NULL);
  719.     io_printw("%c ", i + 13 + 'a');
  720.     for (j = 0; j < WLEN; j++) {
  721.         tstr = pow(lpow, out[j][i + 13]) / ssm[j];
  722.         io_printw("%.3f ", tstr );
  723.     }
  724.     io_printw("\n",NULL);
  725.     }
  726.     str = get_command("enter <cr> to return to top level: ");
  727.   }
  728.   clear_display();
  729.   update_display();
  730.   return(CONTINUE);
  731. }
  732.  
  733. update_out_values() {
  734.     int     i,pos,j,k;
  735.     double denom;
  736.     double c0,c1;
  737.     double wpow;
  738.     double lpow;
  739.     lpow = exp(oscale[L]);
  740.     wpow = exp(oscale[W]);
  741.     
  742.     if (list_defined == 0) {
  743.         make_disp_lists();
  744.     }
  745.  
  746.     for (i = 0; i < numw; i++) {
  747.         disp_word_ptr[i] = word[wi[i]];
  748.     disp_word_act[i] = wa[wi[i]];
  749.     }
  750.     if (compute_resprob > 1) {
  751.       if (numw > 0) {
  752.     denom = 0;
  753.     for (i = 0; i < NWORD; i++) {
  754.         denom += pow(wpow, wout[i]);
  755.     }
  756.       }
  757.       for (i = 0; i < numw; i++) {
  758.     disp_word_rpr[i] = pow(wpow,wout[wi[i]])/denom;
  759.       }
  760.     }
  761.     for (pos = 0; pos < WLEN; pos++) {
  762.       for (i = 0; i < numl[pos]; i++) {
  763.         disp_let_ptr[pos][i] = alphabet[li[pos][i]];
  764.     disp_let_act[pos][i] = l[pos][li[pos][i]];
  765.       }
  766.       if (compute_resprob > 0) {
  767.         if (numl[pos] > 0) {
  768.         denom = 0;
  769.         for (i = 0; i < NLET; i++) {
  770.         denom += pow(lpow, out[pos][i]);
  771.         }
  772.     }
  773.         for (i = 0; i < numl[pos]; i++) {
  774.       disp_let_rpr[pos][i] = 
  775.             pow(lpow, out[pos][li[pos][i]])/denom;
  776.     }
  777.       }
  778.     }
  779.     if (fc_defined) {
  780.      disp_fc_act[0] = l[fc_pos][fc_let[0]];
  781.      disp_fc_act[1] = l[fc_pos][fc_let[1]];
  782.      if (compute_resprob > 0) {
  783.        c0 = pow(lpow,out[fc_pos][fc_let[0]]);
  784.        c1 = pow(lpow,out[fc_pos][fc_let[1]]);
  785.        denom = 0;
  786.        for (i = 0; i < NLET; i++) {
  787.         denom += pow(lpow, out[fc_pos][i]);
  788.        }
  789.        c0 /= denom;
  790.        c1 /= denom;
  791.        disp_fc_rpr[0] = c0 + .5*(1.0 - (c0 + c1));
  792.        disp_fc_rpr[1] = 1.0 - disp_fc_rpr[0];
  793.        if (disp_fc_rpr[0] > fc_max) fc_max = disp_fc_rpr[0];
  794.      }
  795.     }
  796. }
  797.  
  798. make_disp_lists() {
  799.     register int i,pos;
  800.     int onw,onl[WLEN],uf;
  801.     
  802.     onw = numw;
  803.     numw = 0;
  804.     for (i = 0; i < NWORD; i++) {
  805.        if (wa[i] > dthresh[WA]) wi[numw++] = i;
  806.        if (numw == 30) break;
  807.     }
  808.     for (pos = 0; pos < WLEN; pos++) {
  809.        onl[pos] = numl[pos];
  810.        numl[pos] = 0;
  811.        for (i = 0; i < NLET; i++) {
  812.          if (l[pos][i] > dthresh[LA]) {
  813.              li[pos][numl[pos]] = i;
  814.              numl[pos]++;
  815.          }
  816.          if (numl[pos] == 15) break;
  817.        }
  818.     }
  819.     cnw = numw;
  820.     if (onw > numw) {
  821.        for (i = numw; i < onw; i++) {
  822.         disp_word_ptr[i] = "          ";
  823.        }
  824.        cnw = onw;
  825.     }
  826.     for (pos = 0; pos < WLEN; pos++) {
  827.         cnl[pos] = numl[pos];
  828.         if (onl[pos] > numl[pos]) {
  829.            for (i = numl[pos]; i < onl[pos]; i++) {
  830.             disp_let_ptr[pos][i] = "          ";
  831.            }
  832.            cnl[pos] = onl[pos];
  833.         }
  834.     }
  835.     change_lengths();
  836. }
  837.  
  838. change_lengths() {
  839.     change_variable_length("dwp",cnw,0);
  840.     change_variable_length("dwa",numw,0);
  841.     change_variable_length("dwr",numw,0);
  842.     change_variable_length("dlp0",cnl[0],0);
  843.     change_variable_length("dla0",numl[0],0);
  844.     change_variable_length("dlr0",numl[0],0);
  845.     change_variable_length("dlp1",cnl[1],0);
  846.     change_variable_length("dla1",numl[1],0);
  847.     change_variable_length("dlr1",numl[1],0);
  848.     change_variable_length("dlp2",cnl[2],0);
  849.     change_variable_length("dla2",numl[2],0);
  850.     change_variable_length("dlr2",numl[2],0);
  851.     change_variable_length("dlp3",cnl[3],0);
  852.     change_variable_length("dla3",numl[3],0);
  853.     change_variable_length("dlr3",numl[3],0);
  854. }
  855.     
  856.  
  857. define_system() {
  858.     System_Defined = 1;
  859. }
  860.  
  861. /*
  862.     double  oscale[L] = 22026.4658,
  863.     double  oscale[L] = 22026.4658;
  864.     double  oscale[W] = 485165195.4;
  865. */
  866.