home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
NASANETS.ZIP
/
PARSER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-07
|
57KB
|
1,366 lines
/*=============================*/
/* NETS */
/* */
/* a product of the AI Section */
/* NASA, Johnson Space Center */
/* */
/* principal author: */
/* Paul Baffes */
/* */
/* contributing authors: */
/* Bryan Dulock */
/* Chris Ortiz */
/*=============================*/
/*
----------------------------------------------------------------------
Code For Construction Of Net Structures (Prefix = PS_)
----------------------------------------------------------------------
This code is divided into 4 major sections:
(1) include files
(2) externed functions
(3) global variables
(4) subroutines
Each section is further explained below.
----------------------------------------------------------------------
*/
/*
----------------------------------------------------------------------
INCLUDE FILES
----------------------------------------------------------------------
*/
#include "common.h"
#include "netio.h"
/*
----------------------------------------------------------------------
MACRO DEFINITIONS
----------------------------------------------------------------------
Below are eight different macros used for range checking while the
network spec file is being parsed. Each commands in the file takes
a numeric argument, and these macros can check ranges for any of the
eight possible cases given an upper bound (u) and a lower bound (l)
on the number "n".
----------------------------------------------------------------------
*/
#define GTLT(n,l,u) (((n) > (l) && (n) < (u)) ? 1 : 0)
#define GELT(n,l,u) (((n) >= (l) && (n) < (u)) ? 1 : 0)
#define GTLE(n,l,u) (((n) > (l) && (n) <= (u)) ? 1 : 0)
#define GELE(n,l,u) (((n) >= (l) && (n) <= (u)) ? 1 : 0)
#define LTGT(n,l,u) (((n) < (l) || (n) > (u)) ? 1 : 0)
#define LEGT(n,l,u) (((n) <= (l) || (n) > (u)) ? 1 : 0)
#define LTGE(n,l,u) (((n) < (l) || (n) >= (u)) ? 1 : 0)
#define LEGE(n,l,u) (((n) <= (l) || (n) >= (u)) ? 1 : 0)
/*
----------------------------------------------------------------------
EXTERNED FUNCTIONS AND GLOBALS
----------------------------------------------------------------------
Below are the functions defined in other files which are used by the
code here. They are organized by section.
----------------------------------------------------------------------
*/
extern Sint C_float_to_Sint();
extern char *sys_alloc();
extern FILE *PA_open_binary();
extern int PA_put_to_workfile();
extern void PA_flush();
extern void IO_print();
extern char IO_str[MAX_LINE_SIZE];
/*
----------------------------------------------------------------------
GLOBAL VARIABLES
----------------------------------------------------------------------
First, some markers which are used by several routines and are just
declared here a globals for convenience. A parsing variable is next,
called "use_last_command" which is needed for the parsing of layer
specifications. It determines whether or not to reuse the last
command read in during the parsing. Then come two globals which are
used during the creation of a network to indicate whether or not a
global learning rate and/or momentum has been used. If so, then these
two globals will contain the floating point equivalent of the given
values.
----------------------------------------------------------------------
*/
static int line_count = 1; /* used by parse_iopairs, PS_get_token */
static char last_char; /* holds the last character read in */
static char last_str[MAX_LINE_SIZE]; /* holds last command read in */
static int use_last_command = FALSE; /* used for layer parse (see */
/* PS_get_command). */
float global_learn_base; /* used during parse to set default */
float global_momentum; /* global learn/momentum values */
/*
======================================================================
ROUTINES IN PARSER.C
======================================================================
The routines in this file are grouped below by function. Each routine
is prefixed by the string "PS_" indicating that it is defined in the
"parser.c" file. The types returned by the routines are also shown
here so that cross checking is more easily done between these functions
and the other files which intern them.
Type Returned Routine
------------- -------
void PS_reset_for_layer_parse
int PS_global_spec_check
Layer_spec * PS_get_layer
void PS_get_learn_values
void PS_get_nodes
void PS_get_node_dimensions
void PS_get_target
void PS_get_pattern
int PS_get_command
void PS_print_command
int PS_range_check
int PS_int_check
int PS_parse_iopairs
int PS_check_items
int PS_skip_tokens
int PS_get_token
int PS_get_float_from_file
======================================================================
*/
void PS_reset_for_layer_parse()
/*
----------------------------------------------------------------------
The only thing done here, as of now, is to set the global variable
'use_last_command' to FALSE. This must be done from the OUTSIDE via
this routine because the global is static to this file.
----------------------------------------------------------------------
*/
BEGIN
use_last_command = FALSE;
END /* PS_reset_for_layer_parse */
int PS_global_spec_check(ptr_file)
FILE *ptr_file;
/*
----------------------------------------------------------------------
This routine checks for the existence of two optional specs located
at the very beginning of a network specification file. They are the
GLOBAL-LEARN-RATE and GLOBAL-MOMENTUM respectively. Either or both
of these may be specified by the user. If they are present, they
define default values for the learn_base and momemtum elements of
each layer. These values may be overridden later by using the
LEARN-RATE, SCALE-FACTOR, or MOMENTUM commands for each layer which
needs overriding.
Returns ERROR if EOF encountered while trying to check for these
first two optional commands.
----------------------------------------------------------------------
*/
BEGIN
float num;
int temp, PS_get_command(), PS_range_check();
void PS_print_command();
/*--------------------------------------*/
/* first, set the global values to -1.0 */
/* symbolizing UNKNOWN values */
/*--------------------------------------*/
global_learn_base = UNDEFINED;
global_momentum = UNDEFINED;
/*-----------------------------------*/
/* loop on PS_get_command, until you */
/* hit EOF or a LAYER command. */
/*-----------------------------------*/
temp = PS_get_command(ptr_file, &num);
while (temp != LAYER) BEGIN
if (temp == EOF) BEGIN
sprintf(IO_str, "\n*** ERROR: no specifications found in file");
IO_print(0);
return(ERROR);
ENDIF
else if (temp == GLOBAL_LEARN_RATE) BEGIN
if (PS_range_check( GTLE(num, 0, LEARN_MAX) ) == OK)
global_learn_base = num;
ENDELSE
else if (temp == GLOBAL_MOMENTUM) BEGIN
if (PS_range_check( GELE(num, 0, MOMENTUM_MAX) ) == OK)
global_momentum = num;