Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
OUTSTAR Simulator
)Maureen Caudill
Adaptics
16776 Bernardo Center Drive
Suite 110 B
San Diego, CA 92128
(617) 451-3752
July, 1988
Written in Lightspeed C (v. 2.15) on Macintosh
Version 1.0
--------------------------------------------------------------------------------
OPERATION OF THIS SIMULATOR
To run the simulator, you need to have a pattern file which contains the
pattern you want the grid to learn to reproduce when stimulated by the outstar.
The program begins by initializing the weights, activations, reading the data
file and so on. Then the values of the Grossberg learning/activation constants
are checked, with default values assumed initially. I suggest that you leave
these values as they are until you are sure you understand the learning laws.
--------------------------------------------------------------------------------
STRUCTURE OF THIS FILE
include files
constant definitions
general global storage
Grossberg activation/learning constant storage (global)
QQ Major functions QQ
initialize();; initialize network operations
train();; train the grid for a specified time
decay();; allow grid activation to decay a specified time
test();; test the grid for a specified time
QQ Utility functions QQ
compute_activation();; compute current activation for a grid neurode
change_weight();; modify weight of a grid neurode
read_pattern() ;; read pattern from data file
parseline() ;; parse one line of data from file
randomize_wts();; randomize weights on grid neurodes
randomize_activity();; randomize activity of grid neurodes
set_constants();; set Grossberg equation constants
show_constants();; show current values of learning/activity constants
show_wts();; print current weights on grid neurodes
displaygrid();; print the current grid activation
print_menu();; print menu of operator choices (train, test, decay, quit)
QQ Main control function QQ
main();; main control function
----------------------------------------------------------------------------------
-
**********************************************************************************
******/
include <math.h>
include <stdio.h>
#defineROWSIZE7
defineCOLSIZE10
defineSTRINGSIZE80
defineQUIT-1
defineSTIMMASK1
defineACTIVATION 1
defineLEARNING2
defineDISPLAYON1
defineDISPLAYOFF2
defineSTIM1
defineNOSTIM0
/************* General Global Storage
***************************************************/
oublegridwts[ROWSIZE][COLSIZE]; /* this stores only the weights from the
single outstar neurode to the grid of rim
neurodes. */
ntpattern[ROWSIZE][COLSIZE]; /*this contains the pattern to be impressed
on the grid of rim neurodes */
oubleactivity[ROWSIZE][COLSIZE]; /*this contains the current activation levels
of each grid neurode */
ntcurtime;/* current time (in integral units) */
oubleoutstar;/* activation level of outstar */
har*inpath = "pattern";/* file containing pattern to be learned */
nsigned intoutstar_save;/*saves history of outstar's output */
/*********************************************************************************
********/
/************* Grossberg Activation Constants (set by user or default values)
************/
oubleA = 0.9;/* activation decay constant */
oubleT = 0.0;/* threshold */
ntt0 = 1;/* transmission time between neurodes */
oubleF = 0.01;/* forgetting constant for long term memory */
oubleG = 0.2;/* learning constant for Hebbian learning term */
/*************************************************************
initialize()
initializes the system by:
1. reading in the pattern file
2.randomizing the weights
3.setting the current time to 0
4.establishing the activation/learning constants
*************************************************************/
nitialize()
*************************************************************
train(duration)
trains the outstar and grid for "duration" timeunits.
weights are modified during this training period
After each synchronous update of the grid, the
activations are displayed.
*************************************************************/
rain()
intduration, displayflag;
intstoptime;
inti,j;
intstim_grid, stim_outstar;
/* ask how many time units to train */
printf("\n How many time units do you want the network to train? ");
printf("\n (Integer value < 32767, negative suppresses all but final display) ");
scanf("%d", &duration);
displayflag = DISPLAYON;
if (duration<0)
{
duration = -duration;
displayflag = DISPLAYOFF;
}
stoptime = curtime+duration;
for ( ; curtime<stoptime; curtime++)
{
stim_grid = STIM;
stim_outstar = STIM;
printf("\n Current time = %d",curtime);
save_outstim(stim_outstar);
for (i=0; i<ROWSIZE; i++)
{
for (j=0; j<COLSIZE; j++)
{
compute_activation(i,j,stim_grid, stim_outstar);
change_weight(i,j,stim_outstar);
}
}
if(displayflag == DISPLAYON)
displaygrid();
}
curtime--; /* decrement to avoid using an extra time unit */
/* when complete, if have not been updating display, do a final display of status
*/
if (displayflag == DISPLAYOFF)
displaygrid();
return;
/*************************************************************
decay(duration)
allows grid activation to decay for "duration" timeunits.
no weights are modified during this period, since
stimulations from the outstar are 0.0
After each synchronous update of the grid, the
activations are displayed.
*************************************************************/
ecay()
intduration;
intdisplayflag;
intstoptime;
inti,j;
intstim_grid, stim_outstar;
/* ask how many time units to decay */
printf("\n How many time units do you want the network to decay? ");
printf("\n (Integer value < 32767, negative suppresses all but final display) ");
scanf("%d", &duration);
displayflag = DISPLAYON;
if (duration<0)
{
duration = -duration;
displayflag = DISPLAYOFF;
}
stim_grid = NOSTIM;/* during decay, no external stimulation of grid */
stim_outstar = NOSTIM;/* during decay, the outstar does not stimulate grid */
stoptime = curtime+duration;
for ( ; curtime<stoptime; curtime++)
{
printf("\n Current time = %d",curtime);
save_outstim(stim_outstar);
for (i=0; i<ROWSIZE; i++)
{
for (j=0; j<COLSIZE; j++)
{
compute_activation(i,j,stim_grid, stim_outstar);
}
}
if(displayflag == DISPLAYON)
displaygrid();
}
curtime--;
/* when complete, if have not been updating display, do a final display of status
*/
if (displayflag == DISPLAYOFF)
displaygrid();
return;
/*************************************************************
test(duration)
tests the outstar and grid for "duration" timeunits.
weights are not modified during this training period
After each synchronous update of the grid, the
activations are displayed.
*************************************************************/
est()
intduration, displayflag;
intstoptime;
inti,j;
intstim_grid, stim_outstar;
return;
****************************************************************************
save_outstim(stimout)
Parameter stimout either has the value STIM (1) or NOSTIM (0).
save_outstim keeps a 16-time-unit historical record of
the outputs of the outstar by modifying the global unsigned
integer "outstar_save".
Each time unit the outstar is stimulating the grid is represented
by a "1" in outstar_save; if there is no stimulus, outstar_save has
a "0". The 0th bit has the most recent record, the 15th bit has
the oldest record.
****************************************************************************/
ave_outstim(stimout)
ntstimout;
outstar_save = outstar_save << 1;/* left shift one bit. A zero fills
the lowest order bit, and the oldest
(highest order bit) is lost */
outstar_save += stimout;/* add current stimulus value
(0 if no stim, 1 if stim) */
return;
**************************************************************
compute_activation(row,col,grid_on,out_on)
compute the current activation for the specified
grid neurode
Parameter "grid_on" is a flag to tell whether or not
the external stimulus is impressing the pattern on
the grid.
Parameter "out_on" is a flag indicating whether the
outstar is currently stimulating the grid.
/*********************************************************************************
*****
change_weight(row,col,out_on)
modify the weight of the specified grid neurode synapse
Parameter "out_on" is a flag indicating whether or not
the outstar is currently stimulating the grid.
Note that differential equation is calculated as an
incremental difference equation.
**********************************************************************************
*****/
hange_weight(row,col,out_on)
ntrow,col, out_on;
change = -F * activity[row][col];
if (out_on == STIM)
{
status = outstar_save;/* Be sure not to change the global version */
status = status >> t0;/* right shift by t0 time units to allow for
transmission time from outstar */
outstim = status & STIMMASK;
change += G * activity[row][col] * (outstim - T);
}
gridwts[row][col] += change;
return;
/*******************************************************************
read_pattern()
Read in the input data file and store the patterns in
in_pats and out_pats.
FILE*infile;
intxinsize,yinsize;
intrownum, numcols,x;
intvalue, vals_read, status;
charinstring[STRINGSIZE];
/*******************************************************************
parseline(string,numele,row)
parse line of text to derive elements from pattern string.
Parameters
"string" is a pointer to string to be parsed.
"numele" specifies number of elements contained in "string"
"row" is pointer to correct row of "pattern" for elements.
Elements in the string must be either "0", "1", <space>, ","
0,1 puts appropriate values in pattern array
"<space>", or "," is ignored
Return:
-1 if error, 0 else.
*******************************************************************/
arseline(string,numele,ygrid)
harstring[];
ntnumele,ygrid;
intvalue;
intcharnum, ele;
charch;
charnum = 0;
value = 0;
ele = 0;
while ((ele < numele) && (value == 0))
{
if (charnum == STRINGSIZE) /* made it to the end without filling all element
entries */
value = -1;
else
{/*This routine does not care if digits are separated or not.
each instance of a 0 or 1 will be taken as an element entry in
the pattern. */
ch = string[charnum];
switch (ch)
{
case '0' : /* each "0" will be treated as a grid entry */
pattern[ele][ygrid] = 0;
ele++;
break;
case '1' : /* each "1" will be treated as a grid entry */
pattern[ele][ygrid] = 1;
ele++;
break;
default : /* all other characters are ignored. */
break;
}
charnum++;
}
}
return value;
/*******************************************************************
randomize_wts()
Intialize the weights in the grid neurodes to
random values between -0.25..+0.25
*******************************************************************/
andomize_wts()
inti,j;
doublevalue;
*******************************************************************
randomize_activity()
Intialize the activity in the grid neurodes to
random values between 0.0..0.5
*******************************************************************/
andomize_activity()
inti,j;
doublevalue;
/*******************************************************************
set_constants()
displays current (default) values for learning/activation
constants and requests user changes.
*******************************************************************/
et_constants()
intans;
floatvalue;
show_constants(ACTIVATION);
scanf("%d",&ans);
while (ans != 0)
{
printf("\n New value for A? ");
scanf("%f",&value);
A = (double) value;
printf("\n New value for T? ");
scanf("%f",&value);
T = (double) value;
printf("\n New value for t0? ");
scanf("%d",&t0);
show_constants(ACTIVATION);
scanf("%d",&ans);
}
show_constants(LEARNING);
scanf("%d",&ans);
while (ans != 0)
{
printf("\n New value for F? ");
scanf("%f",&value);
F = (double) value;
printf("\n New value for G? ");
scanf("%f",&value);
G = (double) value;
show_constants(LEARNING);
scanf("%d",&ans);
}
return;
*********************************************************************
show_constants (which)
displays either activation or learning constants for
user approval or modification
Paramter "which" determines which set will be displayed
*********************************************************************/
how_constants(which)
ntwhich;
if (which == ACTIVATION)
{
printf("\n The current values for the Grossberg activation constants are:");
printf("\n Activation Decay Time constant (A): %6.3f",A);
printf("\n Activity Threshold (T): %6.3f",T);
printf("\n Transmission time to grid (t0): %d",t0);
}
if (which == LEARNING)
{
printf("\n The current values for the Grossberg learning constants are:");
printf("\n Learning Decay 'Forgetting' constant (F): %6.3f",F);
printf("\n Learning Gain constant (G): %6.3f",G);
}
printf("\n\n Do you wish to change any of these constants? (0 = no) ");
return;
/*******************************************************************
show_wts()
print out the weights for the grid neurodes on the screen
*******************************************************************/
how_wts()
introw,col;
/**************************************************************
displaygrid()
prints (text-only for portability) the current activity
of the grid neurodes. Also displays the current time,
and the desired pattern.
**************************************************************/
isplaygrid()
inti,j;
doublevalue;
/***************************************************************
print_menu()
prints out menu of operations for user choice
***************************************************************/
rint_menu()
/***************************************************************
main()
main program
***************************************************************/
ain()
intyesno;
intdone, donetraining;
inttraintime;
intchoice;
done = 0; donetraining = 0;
while (done == 0)
{
initialize();
choice = 0;
/* display the desired grid pattern on the screen */
print_menu();
printf("\n\n Please enter your choice: ");
scanf("%d",&choice);
printf("\n Your selection was %d",choice);
while (choice != QUIT)
{
switch (choice)
{
case 1:
train();
break;
case 2:
decay();
break;
case 3:
test();
break;
default:
{
choice = QUIT;
break;
}
}
print_menu();
printf("\n\n Please enter your choice: ");
scanf("%d",&choice);
printf("\n Your selection was %d",choice);
}
printf("\n\n Training session terminated at user request...");