home *** CD-ROM | disk | FTP | other *** search
- /* 11:05 04-Jul-88 (stockio.c) Stock Prediction I/O module */
-
- /************************************************************************
- * 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>
- #include <math.h>
- #ifndef SUN
- #ifndef DLC
- #include <stdlib.h>
- #endif
- #endif
-
- #ifdef MAC
- #include "macuio.redef"
- #endif
-
- /************************************************************************
- * *
- * Custom Interface for Stock Prediction *
- * *
- ************************************************************************
- This provides a convenient method of displaying the stock data and
- and comparing network prediction to actual as well as 10-week moving
- average.
- */
-
- static int InitFlag = 0; /* initialize things flag */
- static int *null_ptr = 0; /* to handle Microsoft C bug */
-
- /* */
- /************************************************************************
- * *
- * Window management *
- * *
- ************************************************************************
- */
-
- #define W0 1 /* main window */
- #define CHT 16 /* character height */
-
- #if 1
- int W0_Wid = {480}; /* basic defining parameters */
- int W0_Ht = {200}; /* height of graph */
- int W0_Sep = { 50}; /* separation */
- int W0_Pix = { 1}; /* pixel size */
- #else
- #ifdef SUN
- #define W0_Wid 800
- #define W0_Ht 400
- #define W0_Sep 100
- #else
- #define W0_Wid 480
- #define W0_Ht 200
- #define W0_Sep 50
- #endif
- #endif /* #if 1 */
-
- #define MX_ALL (10) /* x-for all messages */
- #define MY_1 (MX_ALL+10+(W0_Sep*1)/2) /* y-for messages */
- #define MY_2 (MX_ALL+10+(W0_Sep*3)/2)
- #define MY_3 (MX_ALL+10+(W0_Sep*5)/2)
-
- #define EX0 MX_ALL
- #define EX1 (W0_Wid-MX_ALL)
- #define EY0 (MX_ALL)
- #define EY1 (W0_Ht-MX_ALL)
- #define EHT (W0_Ht-2*MX_ALL)
-
- /* */
- /************************************************************************
- * *
- * SetParms() - set up basic display size parameters *
- * *
- ************************************************************************
- */
-
- void SetParms()
- {
- int xsize, ysize, ncolor, chrx, chry; /* graphic parms */
- int ifx, ify; /* integer factor */
-
- ug_gparms( &xsize, &ysize, &ncolor, &chrx, &chry );
-
- ifx = (double)xsize / (double)W0_Wid;
- ify = (double)ysize / (double)W0_Ht;
-
- if ( ifx > 1 ) {
- W0_Wid *= ifx;
- }
- if ( ify > 1 ) {
- W0_Ht *= ify;
- W0_Sep *= ify;
- }
- if ( ifx > 1 && ify > 1 ) {
- W0_Pix = 2;
- }
-
- return;
- }
- /* */
- /************************************************************************
- * *
- * PlotArray() - plot a window full of data *
- * *
- ************************************************************************
- */
-
- #ifdef MAC
- #define MAIN_COLOR 2
- #define AUX_COLOR 5
- #else
- #define MAIN_COLOR 6
- #define AUX_COLOR 13
- #endif
-
- typedef struct _WinBlk {
- int Win; /* window handle */
- char *Title; /* title */
- int X0,Y0; /* coordinates of origin */
- int X1,Y1; /* coordinates of top right */
- int XOff; /* x-offset */
- int XInc; /* x-increment */
- double Scale, Offset; /* scaling */
- int px, py; /* previous x,y */
- int ArraySize; /* array size */
- int cwx; /* current work index */
- float *SavArray; /* save array */
- char *SavFlag; /* save flags */
- } WB;
-
-
- #ifdef PROTOTYPING
- void PlotSet( WB *, int, char *, int, int, int, int, int, int, double, double,
- float *, char *, int );
- void PlotClear( WB * );
- void PlotArray( WB *, float *, float *, int, int );
- void PlotSave( WB * );
- void PlotNext( WB *, double, double, int, int );
- #endif
-
-
- void PlotSet( WBp, Win, Title, X0,Y0, X1,Y1, XOff, XInc, Scale, Offset,
- SaveA, SaveF, NSave )
- WB *WBp; /* window block pointer */
- int Win;
- char *Title;
- int X0,Y0, X1,Y1;
- int XOff;
- int XInc;
- double Scale, Offset;
- float *SaveA;
- char *SaveF;
- int NSave;
- {
- WBp->Win = Win;
- WBp->Title = Title;
- WBp->X0 = X0;
- WBp->Y0 = Y0;
- WBp->X1 = X1;
- WBp->Y1 = Y1;
- WBp->XOff = XOff;
- WBp->XInc = XInc;
- WBp->Scale = Scale;
- WBp->Offset = Offset;
- WBp->px = X0 - XInc + (XOff * XInc);
- WBp->py = Y0;
- WBp->cwx = 0;
- WBp->ArraySize = NSave;
- WBp->SavArray = SaveA;
- WBp->SavFlag = SaveF;
- }
-
-
- void PlotClear( WBp )
- WB *WBp;
- {
- int wx;
-
- WBp->px = WBp->X0 - WBp->XInc + (WBp->XOff * WBp->XInc);
- WBp->py = WBp->Y0;
- WBp->cwx = 0;
-
- if ( WBp->SavArray != (float *)null_ptr ) {
- for( wx = 0; wx < WBp->ArraySize; wx++ ) {
- WBp->SavArray[wx] = 0.0;
- WBp->SavFlag[wx] = 0;
- }
- }
-
- /* clear out the background */
- ug_boxf( WBp->Win, 0, 0, WBp->X0, WBp->Y0, WBp->X1, WBp->Y1 );
-
- /* outline box */
- ug_box( WBp->Win, 8, 0, WBp->X0-1, WBp->Y0-1, WBp->X1+1, WBp->Y1+1, 0 );
-
- return;
- }
-
-
-
- void PlotArray( WBp, MDp, ADp, NPts, off )
- WB *WBp; /* window block pointer */
- float *MDp; /* main data array */
- float *ADp; /* aux data array */
- int NPts; /* # of points in the array */
- int off; /* offset for multiple plots */
- {
- int cx, cy; /* current x,y point */
- int px, py; /* previous x,y point */
- int ay; /* y-coordinate of alternate data */
- int nx; /* index */
- int lcolor; /* line color */
-
- if ( off == 0 ) {
- /* clear out the background */
- ug_boxf( WBp->Win, 0, 0, WBp->X0, WBp->Y0, WBp->X1, WBp->Y1 );
-
- /* outline box */
- ug_box( WBp->Win, 8, 0, WBp->X0-1,WBp->Y0-1,WBp->X1+1,WBp->Y1+1, 0 );
- }
-
- /* plot the data */
- px = WBp->X0 - WBp->XInc + WBp->XOff * WBp->XInc;
- py = px;
- lcolor = ADp == (float *)null_ptr?MAIN_COLOR:AUX_COLOR;
- for( nx = 0; nx < NPts && px < WBp->X1; nx++ ) {
- /* next x-location */
- cx = px + WBp->XInc;
-
- /* y-coordinate & clip it */
- cy = off+ WBp->Y0 + ((MDp[nx] + WBp->Offset) * WBp->Scale);
- if ( cy < WBp->Y0 ) cy = WBp->Y0;
- if ( cy > WBp->Y1 ) cy = WBp->Y1;
- if ( cx > WBp->X1 ) cx = WBp->X1;
- if ( nx != 0 ) {
- ug_line( WBp->Win, lcolor, 0, px, py, cx, cy, 0 );
- }
-
- /* auxiliary data */
- if ( ADp != (float *)null_ptr ) {
- ay = off+ WBp->Y0 + ((ADp[nx] + WBp->Offset) * WBp->Scale);
- if ( ay < WBp->Y0 ) ay = WBp->Y0;
- if ( ay > WBp->Y1 ) ay = WBp->Y1;
- #if 1
- if ( W0_Pix > 1 )
- ug_boxf( WBp->Win, MAIN_COLOR, 0,
- cx-(W0_Pix-1), ay-(W0_Pix-1), cx+(W0_Pix-1), ay+(W0_Pix-1) );
- else
- ug_point( WBp->Win, MAIN_COLOR, 0, cx, ay );
- #else
- #ifdef SUN
- ug_boxf( WBp->Win, MAIN_COLOR, 0, cx-1, ay-1, cx+1, ay+1 );
- #else
- ug_point( WBp->Win, MAIN_COLOR, 0, cx, ay );
- #endif
- #endif
- }
- /* track the last point */
- px = cx;
- py = cy;
- }
-
- if ( WBp->Title != (char *)null_ptr )
- ug_puts( WBp->Win, 15, 0, WBp->X0+5, WBp->Y1-15, WBp->Title, 0 );
-
- return;
- }
-
-
-
- void PlotSave( WBp )
- WB *WBp;
- {
- int n;
-
- n = WBp->cwx;
- if ( WBp->SavFlag[WBp->ArraySize-1] != 0 ) n = WBp->ArraySize;
-
- if ( WBp->Scale > 0.0 )
- PlotArray( WBp, WBp->SavArray, (float *)null_ptr, n, 0 );
- }
-
-
-
- void PlotNext( WBp, MV, AV, af, cf ) /* plot next point */
- WB *WBp; /* window block pointer */
- double MV; /* main value */
- double AV; /* auxiliary value */
- int af; /* aux data flag */
- int cf; /* cursor flag */
- {
- int ay;
- int cx, cy;
-
- if ( cf != 0 && WBp->Scale > 0.0 ) {
- if ( WBp->X0 <= WBp->px && WBp->px < WBp->X1 ) {
- ug_line( WBp->Win, 0, 0, WBp->px+1,WBp->Y0,WBp->px+1,WBp->Y1, 0 );
- }
- }
-
- cx = WBp->px + WBp->XInc;
- cy = WBp->Y0 + (MV + WBp->Offset) * WBp->Scale;
- if ( cy < WBp->Y0 ) cy = WBp->Y0;
- if ( cy > WBp->Y1 ) cy = WBp->Y1;
- if ( cx > WBp->X1 ) cx = WBp->X1;
- if ( WBp->px < cx && WBp->Scale > 0.0 &&
- WBp->px >= (WBp->X0 + WBp->XOff * WBp->XInc) ) {
- ug_line( WBp->Win, MAIN_COLOR, 0, WBp->px, WBp->py, cx, cy, 0 );
- if ( af ) {
- ay = WBp->Y0 + (AV + WBp->Offset) * WBp->Scale;
- if ( ay < WBp->Y0 ) ay = WBp->Y0;
- if ( ay > WBp->Y1 ) ay = WBp->Y1;
- ug_point( WBp->Win, MAIN_COLOR, 0, cx, ay );
- }
- }
- if ( cx >= WBp->X1 ) cx = WBp->X0; /* wrap */
- if ( WBp->SavArray != (float *)null_ptr ) {
- WBp->SavArray[WBp->cwx] = MV;
- WBp->SavFlag[WBp->cwx] = 1;
- WBp->cwx++;
- if ( WBp->cwx >= WBp->ArraySize || cx == WBp->X0 ) {
- WBp->cwx = 0; /* force wrap */
- cx = WBp->X0;
- }
- }
-
- WBp->px = cx;
- WBp->py = cy;
-
- if ( cf != 0 && WBp->Scale > 0.0 && WBp->px < WBp->X1 ) {
- ug_line( WBp->Win, 15, 0, WBp->px+1, WBp->Y0, WBp->px+1, WBp->Y1, 0 );
- }
-
- return;
- }
- /* */
- /************************************************************************
- * *
- * Learning Error display *
- * *
- ************************************************************************
-
- There are three windows:
- top - 4-week moving average w/actual data too
- mid - neural network (learning error)
- bot - original data
- */
-
- WB EWB = {0}; /* error */
- WB MWB = {0}; /* main */
-
- #define ENPts 526 /* # of error points */
- #define EYVals 90 /* # of y-values */
-
- int ECtr = 0; /* current "data" item */
-
- double EXScale = 0.0; /* x-scale factor */
- double EXOffset = 0.0; /* error offset */
-
- float EVals[ENPts] = {0}; /* error values */
- char EVFlag[ENPts] = {0}; /* error value valid flag */
-
- /* */
- /************************************************************************
- * *
- * Common data & statics *
- * *
- ************************************************************************
- */
-
- /* data set definitions */
-
- #define NTPTS 491 /* number of pts in data file */
- #define SetSize 450 /* size of training set */
- float TrainSet[NTPTS+1] = {0.0}; /* current training set */
- float NetPred[NTPTS+1] = {0.0}; /* network prediction */
- float TenPred[NTPTS+1] = {0.0}; /* moving average prediction */
- int InputLen= 0; /* input length */
- int TSetL = 0; /* training set length */
- int TrainSz = 50; /* training samples per pass */
- int ToTrain = 0; /* # of items still to train */
- long Pass = 0; /* pass number */
- int DataCtr = 0; /* data counter */
- int NextFlag= 0; /* next cycle flag */
- float LastDR = 0.0; /* last desired result */
- float MSE = 0.0; /* mean square error for a data set */
- int x = 0; /* previous x-coordinate */
- int ynew = 0; /* current y-coordinate */
- int yold = 0; /* previous y-coordinate */
- int yout = 0; /* network out y-coordinate */
- int xlag = 14; /* first x-coordinate for network out */
- int HitRate = 0; /* # of successful times it predicts trend*/
- int HitTen = 0; /* 10-week hit rate */
- int TotalCt = 0; /* Total # of recalls */
- float PrevWk = 0.0; /* previous week output */
- float PrevPrd = 0.0; /* previously predicted output */
- float CurTen = 0.0; /* current 10-wk moving average */
- float PrevTen = 0.0; /* previous 10-wk moving average */
- double maxe = 0.0; /* max error (%) */
- int maxect = 0; /* max error count */
- double maxe2 = 0.0; /* max error > 20% */
- int maxe2ct = 0; /* max error 2 count */
- double TotErr = 0.0; /* total error over all cases */
- /* */
- /************************************************************************
- * *
- * Training Set Input / Check it is there Routines *
- * *
- ************************************************************************
- */
-
- int IsTSOk()
- {
- IORTNCDE = 0;
- if ( TSetL <= 0 ) {
- IORTNCDE = -1; /* end of file */
- }
-
- return( IORTNCDE );
- }
-
-
- int ReadTS( buf )
- char *buf; /* work buffer */
- {
- FILE *fp; /* input file pointer */
- char *sp; /* input string */
- int c; /* work character */
- int wx; /* work index */
-
- TSetL = 0;
- for(;;) {
- PutStr ("What is the training input File (<RETURN> for default) ?");
- sp = GetStr();
- while( *sp && *sp <= ' ' ) sp++; /* skip leading white space */
- if ( *sp == '\0' ) {
- sp = "sp500.in"; /* default string */
- }
-
- fp = fopen (sp, "r");
- if (fp == (FILE *) 0) {
- sprintf( buf, "Could not open <%s>\n", sp );
- PutStr( buf );
- continue;
- }
-
- for ( wx = 0; wx < NTPTS;) {
- if ( fgets( &buf[0], 80, fp ) == 0 ) break;
-
- /* kill any comments */
-
- for( sp = &buf[0]; (c = *sp) != '\0'; sp++ ) {
- if ( c == '!' || c == '*' || c == '\r' || c == '\n' )
- break;
- }
- *sp = '\0'; /* kill comments, etc */
-
- /* skip leading space and check for blank lines */
-
- for( sp = &buf[0]; *sp && *sp <= ' '; ) sp++;
- if ( *sp == '\0' ) continue;
-
- sscanf( buf, "%f", &TrainSet[wx] );
- wx++;
- }
- TSetL = wx;
- fclose(fp);
-
- if ( TSetL == 0 ) {
- PutStr( "Nothing in data set, try again\n" );
- continue;
- }
-
- break;
- }
-
- return( 0 );
- }
- /* */
- /************************************************************************
- * *
- * UsrIO() - user handler for i/o *
- * *
- ************************************************************************
- */
-
- int UsrIO() /* handle NWORKS requests */
- {
-
- char *sp; /* string pointer */
- float v; /* work float */
- int wn; /* work number */
- int wx; /* work index */
- float act, prd, ten; /* actual / predicted difference */
- char buf[100]; /* work buffer */
- #if (SUN || VAXULT) && !SYSV
- extern long random();
- #define rand random
- #define MAXRAND (0x7fffffffl)
- #else
- extern int rand(); /* random number generator */
- #define MAXRAND (0x7fff)
- #endif
- FILE *fp;
- #ifdef SUN
- extern double fabs( );
- extern double sqrt();
- #endif
-
- if ( InitFlag == 0 ) {
- /* open any files which may be required at this point in the
- code.
- */
-
- /* open all windows at this time */
- SetParms();
-
- ug_window( W0, 0, 80, 3, 80+W0_Wid, 3+W0_Ht );
-
- PlotSet( &EWB, W0, "Mean-Square Error", EX0,EY0,EX1,EY1,
- 0, 1, EHT / .005, 0.0, &EVals[0], &EVFlag[0], ENPts );
-
- #if 1
- PlotSet( &MWB, W0, (char *)null_ptr, EX0,EY0,EX1,EY1,
- 0, (int)(3.4*(EX1-EX0)/NTPTS), EHT / 2.1, 0.0, (float *)null_ptr,
- (char *)null_ptr, 0 );
- #else
- #ifdef SUN
- PlotSet( &MWB, W0, (char *)null_ptr, EX0,EY0,EX1,EY1,
- 0, (int)(3.4*(EX1-EX0)/NTPTS), EHT / 2.1, 0.0, (float *)null_ptr,
- (char *)null_ptr, 0 );
- #else
- PlotSet( &MWB, W0, (char *)null_ptr, EX0,EY0,EX1,EY1,
- 0, 3, EHT / 2.1, 0.0, (float *)null_ptr, (char *)null_ptr, 0 );
- #endif
- #endif
-
- InitFlag = 1;
- }
-
- IORTNCDE = 0; /* good return for data */
- switch( IOREQCDE ) {
-
- /* ------ LEARNING ------ */
-
- 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
- */
-
- if ( TSetL <= 0 ) ReadTS( &buf[0] ); /* read data */
- if ( IsTSOk() ) return(0);
-
- /* set up the window & tell the user what to do */
- ug_winclr( 0 ); /* clear windows */
-
- ToTrain = TrainSz-1;
- /* ask the user for the scale factor for errors */
- PutStr( "What is the maximum expected error? " );
- sp = GetStr();
-
- v = 0.0;
- sscanf( sp, "%f", &v );
- if ( v < 0 ) EXScale = -1.;
- else if ( v < 0.0001 ) {
- if ( EXScale < .0001 ) EXScale = EHT / 1.0;
- } else { EXScale = EHT / v;
- }
-
- /* display the errors as they stand */
- EWB.Scale = EXScale;
- PlotSave( &EWB );
-
- DataCtr = 0;
- MSE = 0.0;
- Pass = 0;
- 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.
- */
-
- if ( IsTSOk() ) return(0);
-
- if ( IOCOUNT > InputLen ) InputLen = IOCOUNT;
-
- /* pick next training input randomly */
- #if (SUN || VAXULT) && !SYSV
- wn = rand() % (TSetL - IOCOUNT - 1);
- #else
- wn = (((long)rand()) * (TSetL - IOCOUNT-1)) / MAXRAND;
- #endif
-
- for (wx = 0; wx < IOCOUNT; wx++, wn++)
- IODATA[wx] = TrainSet[wn];
-
- /*desired response*/
- LastDR = TrainSet[wn];
-
- 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.
- */
-
- 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.
- */
- v = IODATA[0] - LastDR; /* error */
- MSE += (v * v); /* mean square error */
-
- if ( --ToTrain <= 0 ) {
- MSE = sqrt(MSE)/TrainSz;
- Pass++;
- sprintf( buf, "pass = %ld, MSE = %.3f\n", Pass, MSE );
- PutStr( buf );
-
- PlotNext( &EWB, MSE, 0.0, 0, 1 );
- MSE = 0.0;
- ToTrain = TrainSz;
- }
- break;
-
-
- /* ------ RECALL ------ */
-
- 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.
- */
-
- if ( TSetL <= 0 ) ReadTS( &buf[0] ); /* read data */
- if ( IsTSOk() ) return(0);
-
- DataCtr = 0;
- maxe = 0.0;
- maxect = 0;
- maxe2 = 0.0;
- maxe2ct = 0;
- TotErr = 0.0;
-
- ug_winclr( 0 );
-
- yold = 0;
- xlag = 0;
- HitRate = 0;
- HitTen = 0;
- TotalCt = 0;
-
- break;
-
- 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.
- */
-
- if ( IsTSOk() ) return(0);
-
- if ( IOCOUNT > InputLen ) InputLen = IOCOUNT;
-
- /* select the next string from the data set */
- PrevTen = CurTen;
- CurTen = 0.0;
- for (wn = DataCtr, wx = 0; wx < IOCOUNT; wx++, wn++ ) {
- CurTen += TrainSet[wn];
- IODATA[wx] = TrainSet[wn];
- }
-
- TenPred[wn] =
- (1.0 * CurTen) / InputLen; /* save moving average prediction */
-
- PrevWk = LastDR; /* save previous week */
- LastDR = TrainSet[wn];
- 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.
- */
-
- wx = 0;
- IODATA[wx++] = LastDR; /* set data */
-
- while( wx < IOCOUNT ) IODATA[wx++] = 0.0; /* no data for these */
- 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.
- */
-
- NetPred[DataCtr+InputLen] = IODATA[0]; /* current prediction */
-
- if ( xlag == 0 ) {
- xlag = InputLen;
- MWB.XOff = xlag;
- }
- DataCtr++;
-
- /* see if it correctly predicted up/down trend */
- if ( fabs(IODATA[0]) > .001 ) v = fabs((IODATA[0]-LastDR)/IODATA[0]);
- else v = 0.0;
- if ( v > .10 ) {
- if ( v > maxe2 ) maxe2 = v;
- maxe2ct++;
- } else {
- if ( v > maxe ) maxe = v;
- maxect++;
- }
- TotErr += v;
-
- if ( DataCtr > 1 ) {
- act = LastDR - PrevWk;
- prd = IODATA[0] - PrevPrd;
- ten = CurTen - PrevTen;
-
- /* classify network hit rate */
- if ( (fabs(act) < .002 && fabs(prd) < .002) ||
- (act < 0.0 && prd < 0.0) || (act > 0.0 && prd > 0.0) )
- HitRate++;
- if ( (fabs(act) < .002 && fabs(ten) < .002) ||
- (act < 0.0 && ten < 0.0) || (act > 0.0 && ten > 0.0) )
- HitTen++;
- TotalCt++;
- }
- PrevPrd = IODATA[0];
- PrevWk = LastDR;
-
- if(DataCtr >= (TSetL - InputLen-1)) {
- IORTNCDE = -1;
- }
- break;
-
- case RQ_REND:
- if ( TotalCt == 0 )
- TotalCt = 1;
-
- MWB.XOff = 0;
- PlotClear( &MWB );
- PlotArray( &MWB, &TrainSet[0], (float *)null_ptr, TSetL, 0 );
- MWB.XOff = InputLen;
- PlotArray( &MWB, &NetPred[InputLen], &TrainSet[InputLen],
- TSetL-InputLen-1, W0_Sep*1 );
- PlotArray( &MWB, &TenPred[InputLen], &TrainSet[InputLen],
- TSetL-InputLen-1, W0_Sep*2 );
-
- /* put up titles */
- sprintf( buf, "%ld-Week Moving Average", (long) InputLen );
- ug_puts( W0, 13, 0, MX_ALL+5, MY_1, "S&P 500", 0 );
- ug_puts( W0, 13, 0, MX_ALL+5, MY_2, "Network Prediction", 0 );
- ug_puts( W0, 13, 0, MX_ALL+5, MY_3, buf, 0 );
-
- DataCtr = 0;
- sprintf( buf,
- "Trends: Net: %ld/%ld (%ld%%), Ave Err=%.3f%%; %ld-Week: %ld/%ld (%ld%%)",
- (long)HitRate, (long)TotalCt,
- (long) ((HitRate * 100 + TotalCt/2) / TotalCt),
- TotErr / TotalCt * 100.,
- (long) InputLen,
- (long) HitTen, (long) TotalCt,
- (long) ((HitTen * 100. + TotalCt/2) / TotalCt ));
-
- PutStr( buf );
-
- GetStr();
- 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;
- }
-