home *** CD-ROM | disk | FTP | other *** search
- /* 15:40 04-Jul-88 (bsbwh.c) Brain-State-in-a-Box, Widrow-Hoff learning */
-
- /************************************************************************
- * Copyright(C) 1988-1990 NeuralWare Inc *
- * Penn Center West, IV-227, Pittsburgh, PA 15276 *
- * *
- * All rights reserved. No part of this program may be reproduced, *
- * stored in a retrieval system, or transmitted, in any form or by any *
- * means, electronic, mechanical, photocopying, recording or otherwise *
- * without the prior written permission of the copyright owner, *
- * NeuralWare, Inc. *
- ************************************************************************
- */
-
-
- #include "userutl.h"
- #include <string.h>
- #ifndef SUN
- #ifndef DLC
- #include <stdlib.h>
- #endif
- #endif
-
- #ifdef MAC
- #include "macuio.redef"
- #endif
- /************************************************************************
- * *
- * User I/O for Brain-State-in-a-Box Widrow-Hoff Example *
- * *
- ************************************************************************
- The data examples contained in this module can be written to a
- standard ".nna" Ascii File by "EXECUTE NETWORK/ATTENTION".
- */
-
- #define ORGANISM 0
- #define TYPE_ORG 1
- #define DISEASE 2
- #define DRUG1 3
- #define SIDE_EFF 4
- #define M_ADMIN 5
- #define DRUG2 6
-
- #define N_CATEG 7 /* Number of categories */
-
- #define N_ORG 16
- #define N_TYO 7
- #define N_DIS 15
- #define N_SID 5
- #define N_ADM 3
- #define N_DRG 8
-
- #define NULL_STR 0
-
- /* Indices into arrays */
- static int curr_index[N_CATEG] = {0};
-
- static int num_words[N_CATEG] =
- { N_ORG, N_TYO, N_DIS, N_DRG, N_SID, N_ADM, N_DRG };
- static int pos_abbrev[N_CATEG] = { 0, 8, 12, 18, 4, 13, 18 };
-
- static char **c_cat_array[N_CATEG] = {0};
- static char **a_cat_array[N_CATEG] = {0};
-
- static short curr_mode = 0;
-
- static char *c_organism[] = { /* Complete words for organisms */
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR
- };
- static char *a_organism[] = { /* Abbreviated words for organisms */
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR
- };
- static char *c_type_org[] = { /* Complete words for organism types */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR
- };
- static char *a_type_org[] = { /* Abbrev words for organism types */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR
- };
- static char *c_disease[] = { /* Complete words for diseases */
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR
- };
- static char *a_disease[] = { /* Abbreviated words for diseases */
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR
- };
- static char *c_side_eff[] = { /* Side effects */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR
- };
- static char *a_side_eff[] = { /* Side effects ( abbrev ) */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR
- };
- static char *c_m_admin[] = { /* Methods of administration */
- NULL_STR, NULL_STR, NULL_STR
- };
- static char *a_m_admin[] = { /* Meth admin */
- NULL_STR, NULL_STR, NULL_STR
- };
- static char *c_drug[] = { /* Drugs */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR
- };
- static char *a_drug[] = { /* Drgs */
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR, NULL_STR,
- NULL_STR, NULL_STR
- };
-
- /* Local menu definitions */
-
- static char *mode_text[] = { /* menu text for mode option */
- NULL_STR, NULL_STR
- };
-
- #define M_MODE 0
- #define M_CLEAR 1
- #define M_ENTER 2
- #define M_QUIT 3
-
- #define M_INPUT 0
-
- #define M_OUTPUT 0
-
- static GMENU_ITEM Cat1List[] = { /* Menu List */
- { ORGANISM, NULL_STR, NULL_STR },
- { TYPE_ORG, NULL_STR, NULL_STR },
- { DISEASE, NULL_STR, NULL_STR },
- { DRUG1, NULL_STR, NULL_STR }
- };
-
- static GMENU_ITEM Cat2List[] = { /* Menu List */
- { SIDE_EFF, NULL_STR, NULL_STR },
- { M_ADMIN, NULL_STR, NULL_STR },
- { DRUG2, NULL_STR, NULL_STR }
- };
- static GMENU_ITEM UtList[] = { /* Menu List */
- { M_MODE, NULL_STR, NULL_STR },
- { M_CLEAR, NULL_STR, NULL_STR },
- { M_ENTER, NULL_STR, NULL_STR },
- { M_QUIT, NULL_STR, NULL_STR }
- };
- static GMENU_ITEM InItem =
- { M_INPUT, NULL_STR, NULL_STR , 0x0002 };
- static GMENU_ITEM OutItem =
- { M_OUTPUT, NULL_STR, NULL_STR , 0x0002 };
-
- static GMENU CatMenu[2] = { /* Category menus */
- { 0, /* Organism mode */
- 4, /* 4 items */
- 1 /* key */
- },
- { 0, /* Side effect mode */
- 3, /* 3 items */
- 1 /* key */
- }
- };
-
- static GMENU UtMenu = { /* Utility menu */
- 0,
- 4, /* 4 items */
- 2 /* key */
- };
-
- static GMENU InpMenu = { /* Displays abbreviated input vector */
- 0,
- 1, /* 1 item */
- 3 /* key */
- };
-
- static GMENU OutMenu = { /* Displays abbreviated ouput vector */
- 0,
- 1, /* 1 item */
- 4 /* key */
- };
-
- /* menu window positions */
- static int x_cat,y_cat,x_cat1,x_ut,y_ut,x_inp,y_inp,x_out,y_out;
-
- #ifdef PROTOTYPING
- /* --- prototypes --- */
- void abbreviate( int );
- void encode( int, float * );
- char decode( float *, double );
- #endif
-
- void abbreviate( item ) /* abbreviate Input vector */
- int item; /* item to abbreviate ( all = -1 ) */
- {
- if ( item == -1 ) {
- if ( curr_mode == 0 ) {
- strcpy( InItem.text, a_organism[curr_index[ORGANISM]] );
- strcat( InItem.text, a_type_org[curr_index[TYPE_ORG]] );
- strcat( InItem.text, a_disease[curr_index[DISEASE]] );
- strcat( InItem.text, a_drug[curr_index[DRUG1]] );
- } else if ( curr_mode == 1 ) {
- strcpy( InItem.text, "SiEf" );
- strcat( InItem.text, a_side_eff[curr_index[SIDE_EFF]] );
- strcat( InItem.text, a_m_admin[curr_index[M_ADMIN]] );
- strcat( InItem.text, a_drug[curr_index[DRUG2]] );
- }
- } else {
- if ( item == SIDE_EFF ) strncpy( InItem.text, "SiEf", 4 );
- strncpy( &InItem.text[pos_abbrev[item]],
- a_cat_array[item][curr_index[item]],
- strlen( a_cat_array[item][0] ) );
- }
- }
-
- void encode( a, vp )
- int a; /* character to encode */
- float *vp; /* pointer to vector of floats containing encoded char */
- {
- unsigned char wa;
- unsigned char mask;
- int wx, parity;
-
- if ( a == '_' ) wa = 0xff;
- else if ( a >= 'a' && a <= 'z' ) wa = a - 'a';
- else if ( a >= 'A' && a <= 'Z' ) wa = a - 'A';
- else if ( a == '+' ) wa = 26;
- else if ( a == '-' ) wa = 27;
- else if ( a == '.' ) wa = 28;
- else if ( a == ' ' ) wa = 29;
- else wa = 30;
-
- /* Find parity */
- parity = 0;
- for ( wx = 0, mask = 0x10; wx < 5; wx++, mask >>= 1 )
- if ( (wa & mask) != 0 ) parity++;
- parity %= 2;
-
- if ( a >= 'A' && a <= 'Z' ) { /* Make capitals odd parity */
- if (parity == 0) wa |= 0x20;
- } else if ( a != '_' ) { /* make rest even parity */
- if ( parity ) wa |= 0x20;
- }
-
- for ( wx = 0, mask = 0x20; wx < 6; wx++, mask >>= 1 ) {
- if ( wa == 0xff ) vp[wx] = 0.0;
- else if ( (wa & mask) != 0 ) vp[wx] = 1.0;
- else vp[wx] = -1.0;
- }
- }
-
- char decode( vp, thr ) /* Returns character */
- float *vp; /* vector of floats containing encoded char */
- double thr; /* threshold to determine ON/OFF */
- {
- unsigned char wa;
- char rc;
- unsigned char mask;
- int wx, parity;
-
- wa = 0;
-
- for ( wx = 0, mask = 0x20; wx < 6; wx++, mask >>= 1 ) {
- if ( vp[wx] >= thr ) wa |= mask;
- else if ( vp[wx] > -thr ) { /* if between thresholds set all to 0 */
- wa = 0xff;
- break;
- }
- }
-
- /* Find parity */
- parity = 0;
- for ( wx = 0, mask = 0x20; wx < 6; wx++, mask >>= 1 )
- if ( (wa & mask) != 0 ) parity++;
- parity %= 2;
-
- if ( wa == 0xff ) rc = '_';
- else if ( parity ) { /* odd parity - check for capitals */
- wa &= 0x001f;
- if ( wa >= 0 && wa < 26 ) rc = wa + 'A';
- else rc = '?';
- } else { /* Even parity - check for rest */
- wa &= 0x001f;
- if ( wa >= 0 && wa < 26 ) rc = wa + 'a';
- else if ( wa == 26 ) rc = '+';
- else if ( wa == 27 ) rc = '-';
- else if ( wa == 28 ) rc = '.';
- else if ( wa == 29 ) rc = ' ';
- else rc = '?';
- }
-
- return( rc );
- }
-
- /************************************************************************
- * *
- * UsrIO - user I/O routine to handle requests from NWORKS *
- * *
- ************************************************************************
- */
-
- static int InitFlag = 0; /* initialize things flag */
-
- int UsrIO() /* handle NWORKS requests */
- {
- GMENU_ITEM *gmip;
- char *sp; /* string pointer */
- char buf[100]; /* character buffer */
- int wx, wy; /* work indices */
- int key, xp, yp, button; /* mouse parameters */
- int *ci, nw;
- int xsize, ysize, ncolor, chrx, chry; /* graphics parameters */
- int iv_num; /* input vector number */
- static int wr_count; /* count for RQ_WRSTEP */
- float wr[6], *p_outv;
- FILE *asc_fp;
- static char InItemTextBuf[30] = {0}; /* work buffer */
- static char OutItemTextBuf[30] = {0}; /* second work buffer */
-
- if ( InitFlag == 0 ) {
- /* open any files which may be required at this point in the
- code. */
- /* Complete words for organisms */
- c_organism[0] = " ";
- c_organism[1] = "Staphylococcus ";
- c_organism[2] = "Streptococcus ";
- c_organism[3] = "Neisseria ";
- c_organism[4] = "Corynebacterium";
- c_organism[5] = "Clostridium ";
- c_organism[6] = "Enterobacter ";
- c_organism[7] = "Salmonella ";
- c_organism[8] = "Treponema ";
- c_organism[9] = "Candida ";
- c_organism[10] = "Histoplasma ";
- c_organism[11] = "Escherichia ";
- c_organism[12] = "Proteus ";
- c_organism[13] = "Yersinia ";
- c_organism[14] = "Cryptococcus ";
- c_organism[15] = "Aspergillus ";
-
- /* Abbreviated words for organisms */
- a_organism[0] = "________";
- a_organism[1] = "Staphaur";
- a_organism[2] = "Streptop";
- a_organism[3] = "Neisseri";
- a_organism[4] = "Coryneba";
- a_organism[5] = "Clostrid";
- a_organism[6] = "Enteroba";
- a_organism[7] = "Salmonel";
- a_organism[8] = "Treponem";
- a_organism[9] = "Candidaa";
- a_organism[10] = "Histopla";
- a_organism[11] = "E. Coli ";
- a_organism[12] = "Proteus ";
- a_organism[13] = "Yersinap";
- a_organism[14] = "Cryptoco";
- a_organism[15] = "Aspergil";
-
- /* Complete words for organism types */
- c_type_org[0] = " ";
- c_type_org[1] = "Gram +ve coccus ";
- c_type_org[2] = "Gram -ve coccus ";
- c_type_org[3] = "Gram +ve bacillus";
- c_type_org[4] = "Gram -ve bacillus";
- c_type_org[5] = "Spirochetal ";
- c_type_org[6] = "Fungal " ;
-
- /* Abbrev words for organism types */
- a_type_org[0] = "____";
- a_type_org[1] = "+coc";
- a_type_org[2] = "-coc";
- a_type_org[3] = "+bac";
- a_type_org[4] = "-bac";
- a_type_org[5] = "spir";
- a_type_org[6] = "fung";
-
- /* Complete words for diseases */
- c_disease[0] = " ";
- c_disease[1] = "Endocarditis ";
- c_disease[2] = "Pneumonia ";
- c_disease[3] = "Gonorrhea ";
- c_disease[4] = "Tetanus ";
- c_disease[5] = "Urinary Tract";
- c_disease[6] = "Typhoid ";
- c_disease[7] = "Syphilis ";
- c_disease[8] = "Lesion ";
- c_disease[9] = "Meningitis ";
- c_disease[10] = "Scarlet Fever";
- c_disease[11] = "Pharyngitis ";
- c_disease[12] = "Gangrene ";
- c_disease[13] = "Plague ";
- c_disease[14] = "Yaws ";
-
- /* Abbreviated words for diseases */
- a_disease[0] = "______";
- a_disease[1] = "Endoca";
- a_disease[2] = "Pneumo";
- a_disease[3] = "Gonorh";
- a_disease[4] = "Tetanu";
- a_disease[5] = "UrTrIn";
- a_disease[6] = "Typhoi";
- a_disease[7] = "Syphil";
- a_disease[8] = "Lesion";
- a_disease[9] = "Mening";
- a_disease[10] = "ScarFe";
- a_disease[11] = "Pharyn";
- a_disease[12] = "Gangre";
- a_disease[13] = "Plague";
- a_disease[14] = "Yaws ";
-
- /* Side effects */
- c_side_eff[0] = " ";
- c_side_eff[1] = "Hypersensitivity";
- c_side_eff[2] = "Aplastic Anemia ";
- c_side_eff[3] = "Ototoxicity ";
- c_side_eff[4] = "Kidneys ";
-
- /* Side effects ( abbrev ) */
- a_side_eff[0] = "_________";
- a_side_eff[1] = "Hypersens";
- a_side_eff[2] = "AplasticA";
- a_side_eff[3] = "Ototoxic ";
- a_side_eff[4] = "Kidneys++";
-
- /* Methods of administration */
- c_m_admin[0] = " ";
- c_m_admin[1] = "Injection";
- c_m_admin[2] = "Oral ";
-
- /* Meth admin */
- a_m_admin[0] = "_____";
- a_m_admin[1] = "Inje ";
- a_m_admin[2] = "Oral ";
-
- /* Drugs */
- c_drug[0] = " ";
- c_drug[1] = "Penicillin ";
- c_drug[2] = "Ampicillin ";
- c_drug[3] = "Cephalosporin ";
- c_drug[4] = "Chloramphenicol";
- c_drug[5] = "Amphotericin ";
- c_drug[6] = "Gentamycin ";
- c_drug[7] = "Tetracyclin ";
-
- /* Drugs (abbrev)*/
- a_drug[0] = "_______";
- a_drug[1] = "Penicil";
- a_drug[2] = "Ampicil";
- a_drug[3] = "Cephalo";
- a_drug[4] = "Chloram";
- a_drug[5] = "Amphote";
- a_drug[6] = "Gentamy";
- a_drug[7] = "Tetracy";
-
- /* menu text for mode option */
- mode_text[0] = "Mode: Disease ";
- mode_text[1] = "Mode: Side Effects";
-
- /* Menu List */
- UtList[0].text = "Mode: Disease ";
- UtList[1].text = "Clear";
- UtList[2].text = "Enter";
- UtList[3].text = "Quit";
-
- strcpy( InItemTextBuf, "_________________________" );
- strcpy( OutItemTextBuf, InItemTextBuf );
- InItem.text = &InItemTextBuf[0];
- OutItem.text = &OutItemTextBuf[0];
-
- CatMenu[0].item = Cat1List;
- CatMenu[1].item = Cat2List;
- UtMenu.item = UtList;
- InpMenu.item = &InItem;
- OutMenu.item = &OutItem;
-
- c_cat_array[ORGANISM] = &c_organism[0];
- c_cat_array[TYPE_ORG] = &c_type_org[0];
- c_cat_array[DISEASE] = &c_disease[0];
- c_cat_array[SIDE_EFF] = &c_side_eff[0];
- c_cat_array[M_ADMIN] = &c_m_admin[0];
- c_cat_array[DRUG1] = &c_drug[0];
- c_cat_array[DRUG2] = &c_drug[0];
-
- a_cat_array[ORGANISM] = &a_organism[0];
- a_cat_array[TYPE_ORG] = &a_type_org[0];
- a_cat_array[DISEASE] = &a_disease[0];
- a_cat_array[SIDE_EFF] = &a_side_eff[0];
- a_cat_array[M_ADMIN] = &a_m_admin[0];
- a_cat_array[DRUG1] = &a_drug[0];
- a_cat_array[DRUG2] = &a_drug[0];
-
- /* Initialize menu text */
- for ( wy = 0; wy < 2; wy++ ) {
- for ( wx = 0, gmip = CatMenu[wy].item; wx < CatMenu[wy].num_items;
- wx++, gmip++ ) {
- curr_index[gmip->code] = 1;
- gmip->text = c_cat_array[gmip->code][1];
- }
- }
- curr_mode = 0;
- abbreviate( -1 );
-
- /* Get screen parameters */
- ug_gparms( &xsize, &ysize, &ncolor, &chrx, &chry);
-
- if ( ncolor < 8 ) {
- gm_intcolor = 1;
- gm_txtcolor = 0;
- gm_outcolor = 0;
- } else {
- gm_intcolor = 7;
- gm_txtcolor = 4;
- gm_outcolor = 0;
- }
-
- /* Initialize menus and set window positions */
- InitGMenu( &InpMenu, chrx, chry );
- InitGMenu( &OutMenu, chrx, chry );
- InitGMenu( &UtMenu, chrx, chry );
- InitGMenu( &CatMenu[0], chrx, chry );
- InitGMenu( &CatMenu[1], chrx, chry );
- x_inp = (xsize - InpMenu.x1) / 2;
- x_out = (xsize - OutMenu.x1) / 2;
- x_ut = (xsize - UtMenu.x1) / 2;
- if ( (wx = CatMenu[0].x1 - CatMenu[1].x1) >= 0 ) {
- x_cat = (xsize - CatMenu[0].x1) / 2;
- x_cat1 = x_cat + CatMenu[0].x1 + 2;
- CatMenu[0].x0 = 0;
- CatMenu[1].x0 = wx / 2;
- } else {
- x_cat = (xsize - CatMenu[1].x1) / 2;
- x_cat1 = x_cat + CatMenu[1].x1 + 2;
- CatMenu[0].x0 = - (wx / 2);
- CatMenu[1].x0 = 0;
- }
- y_cat = ysize / 4;
- y_ut = y_cat + 30;
- y_out = y_ut + 30;
- y_inp = y_out + 30;
-
- InpMenu.x0 = 0; /* Menu position relative to window */
- InpMenu.y0 = 0;
- OutMenu.x0 = 0; /* Menu position relative to window */
- OutMenu.y0 = 0;
- UtMenu.x0 = 0; /* Menu position relative to window */
- UtMenu.y0 = 0;
- CatMenu[0].y0 = CatMenu[1].y0 = 0;
-
- InitFlag = 1;
- }
-
- IORTNCDE = 0; /* good return for data */
- switch( IOREQCDE ) {
- case RQ_ATTENTION:
- /* This is invoked at the request of the user from the
- execute menu. It allows parameters to be changed or
- altered. Any graphics or other interactions are allowable
- as usual for the other options.
- */
- asc_fp = (FILE * ) 0;
- iv_num = 1;
- PutStr("Create <.nna> file ? - previous bsbwh.nna will be deleted.\n");
- PutStr( "Press right button to abort, left button to continue.\n" );
- for ( ; ; ) {
- ug_mouse( &key, &xp, &yp, &button );
- if ( button == MBUT_RIGHT ) goto end_attn;
- if ( button == MBUT_LEFT ) break;
- }
- #ifndef MAC
- unlink( "bsbwh.nna" ); /* Delete file if it exists */
- #endif
- asc_fp = fopen( "bsbwh.nna", "w" ); /* Open for writing */
- if ( asc_fp == (FILE *)0 ) goto end_attn;
- fprintf( asc_fp,
- "! Input file for antibiotic example. Autoassociative network%s",
- NEW_LINE_STR );
-
- /* Display menus and await inputs */
- ug_window( InpMenu.key, gm_intcolor, x_inp, y_inp,
- x_inp + InpMenu.x1 + 2, y_inp + InpMenu.y1 + 2);
- ug_window( UtMenu.key, gm_intcolor, x_ut, y_ut,
- x_ut + UtMenu.x1 + 2, y_ut + UtMenu.y1 + 2);
- ug_window( CatMenu[curr_mode].key, gm_intcolor, x_cat, y_cat,
- x_cat1, y_cat + CatMenu[0].y1 + 2);
-
- DispGMenu( &InpMenu );
- DispGMenu( &UtMenu );
- DispGMenu( &CatMenu[curr_mode] );
-
- for ( ; ; ) {
- while ( (gmip=LookGMenu(&CatMenu[curr_mode],&button))
- != (GMENU_ITEM *) 0 ) {
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- ci = &curr_index[gmip->code];
- nw = num_words[gmip->code];
- if (button == MBUT_LEFT ) *ci = (*ci + 1) % nw;
- else *ci = (*ci + nw - 1) % nw;
- gmip->text = c_cat_array[gmip->code][*ci];
- DispGItem( &CatMenu[curr_mode], gmip,
- gm_intcolor, gm_txtcolor );
- abbreviate( -1 );
- DispGMenu( &InpMenu );
- }
- /* If button was pressed, wait for it to be released */
- while ( button != 0 )
- ug_mouse( &key, &xp, &yp, &button );
- }
-
- while ( (gmip=LookGMenu( &UtMenu, &button )) != (GMENU_ITEM *) 0 ) {
- switch( gmip->code ) {
- case M_MODE:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- curr_mode = (curr_mode + 1) % 2;
- gmip->text = mode_text[curr_mode];
- DispGItem( &UtMenu, gmip, gm_intcolor, gm_txtcolor );
- ug_winclr( CatMenu[0].key );
- DispGMenu( &CatMenu[curr_mode] );
- abbreviate( -1 );
- DispGMenu( &InpMenu );
- }
- break;
- case M_CLEAR:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- /* Set current index to 0 for all menu items and redisplay */
- for ( gmip = CatMenu[curr_mode].item, wx = 0;
- wx < CatMenu[curr_mode].num_items; wx++, gmip++ ) {
- curr_index[gmip->code] = 0;
- gmip->text = c_cat_array[gmip->code][0];
- }
- DispGMenu( &CatMenu[curr_mode] );
- abbreviate( -1 );
- DispGMenu( &InpMenu );
- }
- break;
- case M_ENTER:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- fprintf( asc_fp, "! F%ld: ", (long)iv_num );
- iv_num++;
- fprintf( asc_fp, InItem.text );
- fprintf( asc_fp, "%s ", NEW_LINE_STR );
- for ( sp = InItem.text, wx = 0; wx < 25; sp++, wx++ ) {
- encode( (int)(*sp), wr );
- if ( wx != 0 && wx%3 == 0 ) fprintf( asc_fp, "%s&", NEW_LINE_STR);
- for ( wy = 0; wy < 6; wy++ )
- fprintf( asc_fp, " %2.0f.", wr[wy] );
- }
- fprintf( asc_fp, NEW_LINE_STR );
- }
- break;
- case M_QUIT:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- IORTNCDE = -1;
- goto end_attn;
- }
- break;
- }
- /* If button was pressed, wait for it to be released */
- while ( button != 0 )
- ug_mouse( &key, &xp, &yp, &button );
- }
- }
-
- end_attn:
- if ( asc_fp != (FILE * ) 0 ) fclose( asc_fp );
- break;
-
- case RQ_LSTART: /* starting learn */
- /* This tells the user that the program is about to start
- learning. It is called once for a LEARN ALL, LEARN ONE,
- LEARN N, or LEARN START
- */
- break;
-
- case RQ_LEARNIN: /* read training input */
- /* IODATA points to an empty array of IOCOUNT elements. The
- values placed in this array by the user will become the
- inputs to the network for training purposes.
- */
-
- case RQ_READ: /* read test data */
- /* IODATA points to an empty array of IOCOUNT values. The
- user must fill in these values. The elements of the
- array will become the "sum" of the inputs to the input
- layer of processing elements.
- */
-
- wr_count = 0;
-
- ug_window( InpMenu.key, gm_intcolor, x_inp, y_inp,
- x_inp + InpMenu.x1 + 2, y_inp + InpMenu.y1 + 2);
- ug_window( UtMenu.key, gm_intcolor, x_ut, y_ut,
- x_ut + UtMenu.x1 + 2, y_ut + UtMenu.y1 + 2);
- ug_window( CatMenu[curr_mode].key, gm_intcolor, x_cat, y_cat,
- x_cat1, y_cat + CatMenu[0].y1 + 2);
-
- DispGMenu( &InpMenu );
- DispGMenu( &UtMenu );
- DispGMenu( &CatMenu[curr_mode] );
-
- for ( ; ; ) {
- while ( (gmip=LookGMenu(&CatMenu[curr_mode],&button))
- != (GMENU_ITEM *) 0 ) {
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- ci = &curr_index[gmip->code];
- nw = num_words[gmip->code];
- if (button == MBUT_LEFT )
- *ci = (*ci + 1) % nw;
- else
- *ci = (*ci + nw - 1) % nw;
- gmip->text = c_cat_array[gmip->code][*ci];
- DispGItem( &CatMenu[curr_mode], gmip,
- gm_intcolor, gm_txtcolor );
- abbreviate( gmip->code );
- DispGMenu( &InpMenu );
- }
- /* If button was pressed, wait for it to be released */
- while ( button != 0 )
- ug_mouse( &key, &xp, &yp, &button );
- }
-
- while ( (gmip=LookGMenu( &UtMenu, &button )) != (GMENU_ITEM *) 0 ) {
- switch( gmip->code ) {
- case M_MODE:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- curr_mode = (curr_mode + 1) % 2;
- gmip->text = mode_text[curr_mode];
- DispGItem( &UtMenu, gmip, gm_intcolor, gm_txtcolor );
- ug_winclr( CatMenu[0].key );
- DispGMenu( &CatMenu[curr_mode] );
- if ( IOREQCDE == RQ_LEARNIN ) abbreviate( -1 );
- DispGMenu( &InpMenu );
- }
- break;
- case M_CLEAR:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- /* Set current index to 0 for all menu items and redisplay */
- for ( gmip = CatMenu[curr_mode].item, wx = 0;
- wx < CatMenu[curr_mode].num_items; wx++, gmip++ ) {
- curr_index[gmip->code] = 0;
- gmip->text = c_cat_array[gmip->code][0];
- }
- DispGMenu( &CatMenu[curr_mode] );
- abbreviate( -1 );
- DispGMenu( &InpMenu );
- }
- break;
- case M_ENTER:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- /* Fill in IODATA with bit patterns for current input */
- for ( sp = InItem.text, wx = 0, p_outv = IODATA;
- wx < 25; sp++, wx++, p_outv += 6 ) {
- encode( (int)(*sp), p_outv );
- }
- goto end_read;
- }
- break;
- case M_QUIT:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- IORTNCDE = -1;
- goto end_read;
- }
- break;
- }
- /* If button was pressed, wait for it to be released */
- while ( button != 0 )
- ug_mouse( &key, &xp, &yp, &button );
- }
- }
- end_read:
- break;
-
- case RQ_LEARNOUT: /* read desired output */
- /* IODATA points to an empty array of IOCOUNT values. The
- elements of the array will become the desired outputs for
- training purposes. These desired outputs correspond to
- the most recent "RQ_LEARNIN" request.
- */
-
- break;
-
- case RQ_WRITE: /* write out results */
- /* IODATA points to an array of IOCOUNT "float" type values.
- The values are the outputs of the top-most layer of the
- network.
- */
- IORTNCDE = 1; /* Redraw */
- break;
-
- case RQ_LEARNRSLT:
- /* IODATA points to an array of IOCOUNT values. These are the
- output of the network caused by the inputs from RQ_LEARNIN.
- */
-
- ug_window( OutMenu.key, gm_intcolor, x_out, y_out,
- x_out + OutMenu.x1 + 2, y_out + OutMenu.y1 + 2);
-
- for ( sp = OutItem.text, wx = 0, p_outv = IODATA;
- wx < 25; wx++, p_outv += 6 )
- *sp++ = decode( p_outv, 0.1 );
-
- DispGMenu( &OutMenu );
-
- /* Lock Items */
- for ( wy = 0; wy < 2; wy++ )
- for ( wx = 0, gmip = CatMenu[wy].item;
- wx < CatMenu[wy].num_items; wx++, gmip++ )
- gmip->flag |= GM_LOCKED;
-
- UtList[M_MODE].flag |= GM_LOCKED;
- UtList[M_CLEAR].flag |= GM_LOCKED;
- UtList[M_QUIT].flag |= GM_LOCKED;
-
- for ( ; ; ) {
- while ( (gmip=LookGMenu( &UtMenu, &button )) == (GMENU_ITEM *)0 ) ;
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) break;
- }
- /* Unlock Items */
- for ( wy = 0; wy < 2; wy++ )
- for ( wx = 0, gmip = CatMenu[wy].item;
- wx < CatMenu[wy].num_items; wx++, gmip++ )
- gmip->flag &= ~GM_LOCKED;
-
- UtList[M_MODE].flag &= ~GM_LOCKED;
- UtList[M_CLEAR].flag &= ~GM_LOCKED;
- UtList[M_QUIT].flag &= ~GM_LOCKED;
-
- IORTNCDE = 1;
- break;
-
- case RQ_WRSTEP: /* write interim results */
- /* each recall cycle for the Hopfield and BAM control strategies,
- the intermediate output is made available to userio to test
- for convergence or other desired states. This option is
- not used for other control strategies.
- */
-
- if ( wr_count++ % 5 == 0 ) {
- ug_window( OutMenu.key, gm_intcolor, x_out, y_out,
- x_out + OutMenu.x1 + 2, y_out + OutMenu.y1 + 2);
-
- for ( sp = OutItem.text, wx = 0, p_outv = IODATA;
- wx < 25; wx++, p_outv += 6 )
- *sp++ = decode( p_outv, 0.1 );
-
- DispGMenu( &OutMenu );
-
- /* Lock Items */
- for ( wy = 0; wy < 2; wy++ )
- for ( wx = 0, gmip = CatMenu[wy].item;
- wx < CatMenu[wy].num_items; wx++, gmip++ )
- gmip->flag |= GM_LOCKED;
-
- UtList[M_MODE].flag |= GM_LOCKED;
- UtList[M_CLEAR].flag |= GM_LOCKED;
-
- sprintf( buf, "Recall iteration number %ld%s", (long)wr_count, NEW_LINE_STR );
- PutStr( buf );
- PutStr( "Select ENTER to continue, QUIT to terminate recall\n" );
- for ( ; ; ) {
- while ( (gmip=LookGMenu(&UtMenu,&button )) == (GMENU_ITEM *)0 ) ;
- switch( gmip->code ) {
- case M_ENTER:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) goto end_wr;
- break;
- case M_QUIT:
- if ( button == MBUT_LEFT || button == MBUT_RIGHT ) {
- IORTNCDE = -1;
- goto end_wr;
- }
- break;
- }
- }
- end_wr:
- /* Unlock Items */
- for ( wy = 0; wy < 2; wy++ )
- for ( wx = 0, gmip = CatMenu[wy].item;
- wx < CatMenu[wy].num_items; wx++, gmip++ )
- gmip->flag &= ~GM_LOCKED;
-
- UtList[M_MODE].flag &= ~GM_LOCKED;
- UtList[M_CLEAR].flag &= ~GM_LOCKED;
- }
-
- break;
-
- case RQ_RSTART: /* starting recall */
- /* This tells the user that the program is about to start
- a recall. It is called once for a REACLL ALL, RECALL ONE,
- RECALL N, or RECALL START.
- */
- break;
-
- case RQ_RCLTST: /* read desired output during recall test */
- /* IODATA points to an empty array of IOCOUNT values. The
- elements of the array will become the desired outputs for
- recall purposes. This request is only made during a
- Execute Network/Recall Test.
- */
-
- break;
-
- case RQ_TERM: /* terminate interface */
- /* close any files which may be open. Deallocate any memory
- which was allocated. (This is VERY VERY important. If
- allocated memory is NOT released, dos memory will become
- fragmented and it will become necessary to reboot.
- */
-
- PutStr( "bye bye\n" );
- break;
- }
-
- return;
- }
-