#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <setjmp.h>
#ifdef X
#include <X/Xlib.h>
#endif
#include "defs.h"

#ifdef ims
FILE	*stdin;
FILE	*stdout;
FILE	*stderr;
#endif
FILE   *cfp;				    /* config file */
FILE   *datafp;				    /* the token data */
FILE   *teachfp;			    /* the teacher data */
FILE   *ifp;				    /* file with index of type of each
					     * token */
FILE   *tfp;				    /* number of types & type labels
					     * for graphics */
FILE   *errfp;
FILE   *cmdfp;
FILE   *onlyfp;
jmp_buf env;
float	etot;
int   ndtokens;			    /* # data tokens */
float   rate = DEFRATE;
int	insize;
float   tsize;
float	weight_limit = 1.0;
float	wtstart = -10.0;
float	wtstop = 10.0;
int	wtstep = 20;
int	wlabels = 0;			    /* print labels on wts? */
float **d_tokenp;			    /* data token pointer */
float **t_tokenp;			    /* teacher token pointer */
float **tp;
float  *dp;
float **lp;
float  *type_index;
float  *tip;
float  *extract_end;
int	val;
int	nwts = 0;		    /* total number of weights in network */
int     width = DEFWIDTH;
int     height = DEFHEIGHT;
int     debug = 0;		    /* nothing=0,conmat>1,constr>2,wts> * 4 */
int     decayflag = 0;		    /* no decays=1; decays in .cf = 1 */
int     nobias = 0;		    /* 0 means we DO use biases;1=nobias */
int     bipolar = 0;		    /* 0 means normal logistic; 1 = -1 to 1 */
int     only = 0;		    /* 0 means normal learing; 1 = .only */
int     sequential = 0;		    /* random access of tokens=0; seq.=1 */
int     continuous = 0;		    /* doing continuous scan thru  input */
long     sweeps = 0;
int	ecount = 100;
int	pat_err = 0;		    /* print pattern error on each pattern */
long     run = 0;
long	seed;
int	rbp = 0;		    /* recurrent back prop = 1 */
int	pcomp = 0;		    /* pattern completion = 1 */
int	update = 0;		    /* update error only after epoch (if = 1) */
int	updatenow = 0;		    /* update error now (end of epoch) */
float	alpha = 1.0;		    /* gain for rbp, old input */
float	beta = 1.0;		    /* gain for rbp, new input */
float	eps = 0.001;	       	    /* target minimum rbp change */
float	*delta_x;	    	    /* current minimum rbp forward change */
float	*delta_z;	    	    /* current minimum rbp backward change */
int	iter = 1;		    /* # of forward props per cycle */
float   noise = 0.0;
int     array = 0;		    /* describe network with array */
int     errsig = 0;		    /* print error signal */
int     linflag = NONLINEAR;	    /* default is nonlinear out.funcs. */
int     all_linear = 0;		    /* flag for all units linear */
int     dispout = 0;		    /* display output units. */
int     disphid = 0;		    /* display hidden units. */
char    **type_list;
char    fileroot[128];
char    title[80];

#ifdef X
char	grphcmd[] = GRPHCMD;
Display	*display;
int	plot2 = 0;		    /* doing 2-d plotting */
int	plot3 = 0; 		    /* doing 3-d plotting */
int	forePixel;
int	backPixel;
Pixmap	foreTile;
Pixmap	backTile;
#endif

int     context = 0;		    /* 0 = no context units; 1=context units */
float   momentum = DEFMOM;
float   olderr = 0.;
char    loadfile[128];
char    datafile[128];
char    teachfile[128];
char    indexfile[128];
char    typefile[128];
char    errfile[128];
char    cmdfile[128];
char    onlyfile[128];

char	exp_path[] = "/afs/athena/astaff/project/argus/src/thm/ur/rlearn/exp/exp_table";
/*char	exp_path[] = "/u1/ln163s/public/exp_table";*/

char	*progname;
long     check = 0;		    /* how often to checkpoint weights */
int     box = 0;		    /* send unit activation to SUN */
int     printout = 0;		    /* print output results */
int     printhid = 0;		    /* send unit activation to tty */
int     test = 0;		    /* are we in test mode */
int     extract = 0;		    /* extract mode, printing params */
int     cur_token = -1;		    /* which of ndtokens we're training */
u_int	cur_type = 0;		    /* type of cur_token */
int     types = 0;		    /* # of different pattern types */
int     autoen = 0;		    /* doing autoencoding */
int     advance = 1;		    /* how much to advance */
int     nolearn = 0;		    /* 0 means we DO learning; 1 =  skip */
int     interactive = 0;	    /* 0 means non-interactive; 1=int. */
int	nh;
int	testall;
int	no_cmd;
