Previous Next Contents

Chapter 8:   Simulation Runs: Function Approximation:

This simulation run uses a finite amount of discrete data collected in an x-y grid to approximate the function

f(x,y) =
e
.1 (x2 + y2)
 
sin(2x + y)

on the interval -3.0 £ x £ 3.0 and -3.0 £ y £ 3.0 . Hence, there are two inputs and one analog output.

The training set of
256 samples consists of the triples (xi,yj,zij), where

xi = -3.0 + .4(i-1), 1 £ i £ 16
yj = -3.0 + .4(j-1), 1 £ j £ 16
zij = f(xi,yj).

The test set of 51 samples is constructed in a simpler fashion:

xi = -3.0 + .12(i-1), 1 £ i £ 51
yi = -3.0 + .12(j-1), 1 £ i £ 51
zii = f(xi,yi).

The actual graph of this function is presented in Figure 8.1 using the the graphic generation capabilities of MATLAB with 3721 data points.



Figure 8.1:

8.1   The Application Code:

The application is generated using three files:

test_generator.c:
This function generates the training files used to build the CMAC model, the testing file used to validate the CMAC model, and a file containing the data points required to accurately graph the true function surface.
simul.c:
This function builds the CMAC model.
testmodel.c:
This function generates data files which are used to graph the surface generated by the CMAC model. The graphing itself will be done via MATLAB using a procedure called picture.m. The procedure picture.m is listed below with explanatory comments prefaced by %% to the right of each line.

 
fid = fopen('data','r');  %% open the file called data containing the
                          %% x y z triples needed to graph the surface
                          %% We assume there are N x data points,
                          %% that are linearly ordered from xmin to xmax;
                          %% N y data points linearly ordered from
                          %% ymin to ymax for a total of N*N
                          %% x y z triples.  Beware: We think
                          %% of our data as being indexed from 0 to N-1
                          %%  whilke MATLAB uses the standard Fortran
                          %% indexing scheme of 1 to N.
                          %% The triples are ordered as follows:
                          %% x(0),y(0), z(0,0)
                          %% x(0),y(1), z(0,1)
                          %% x(0),y(2), z(0,2)
                          %%   .
                          %%   .
                          %%   .
                          %% x(0),y(N-1), z(0,N-1) 
                          %% x(1),y(0), z(1,0)
                          %% x(1),y(1), z(1,1)
                          %% x(1),y(2), z(1,2)
                          %%   .
                          %%   .
                          %%   .
                          %% x(1),y(N-1), z(1,N-1)
                          %%   .
                          %%   .
                          %%   .   
                          %% x(N-1),y(0), z(N-1,0)
                          %% x(N-1),y(1), z(N-1,1)
                          %% x(N-1),y(2), z(N-1,2)
                          %%   .
                          %%   .
                          %%   .
                          %% x(N-1),y(N-1), z(N-1,N-1)                   
for i = 1:N               %% You must supply the value of N here
  for j = 1:N
    X(i,j)= fscanf(fid,'%f',1);  %% Reads from the file the
                                 %% contents of data field 1
                                 %%  and stores the x values
                                 %% into a N x N array; so row i of this
                                 %% matrix is constant row having x(i-1)
                                 %% repeated N times.
    Y(i,j)= fscanf(fid,'%f',1);  %% Reads from the file the
                                 %% contents of data field 2 and stores the 
                                 %% y values
                                 %% into a N x N array; row i of this
                                 %% matrix has the form
                                 %% y(0), y(1),...,y(N-1)
    Z(i,j)= fscanf(fid,'%f',1);  %% Read from the file the
                                 %% contents of data field 3 and stores the 
                                 %% z values
                                 %% into a N x N array; row i of this
                                 %% matrix has the form
                                 %% z(i-1,0), z(i-1,1),...,z(i-1,N-1)
  end
end
surf(X,Y,Z);                     %% Parametric surface plot with
                                 %% surface coordinates (X(i,j),Y(i,j),Z(i,j))
view(40,20);                     %% Observer views surface from this position
fclose('all');                   %% Close the data file
   
In the MATLAB session below, the MATLAB script picture.m is loaded and executed by simply typing its name at the MATLAB prompt. The default extension .m is not required to be entered. To use this script to generate surface plots, edit picture.m to insert your chosen data file name and your data point size N and use it as follows:


albert% MATLAB
>> picture                        %% edit file to add your N 
                                  %% and your file name   
>> print -deps file_name.eps      %% print plot to file_name.eps 
  

8.1.1   The MakeFile: MakeApplication

There are three separate make files:

The Make File for test_generator.c

                               
                
# -------------------------- #
# paths for this simulation  #
# -------------------------- #
INCLUDE_PATH_UTILITY = /home/peterson/programs/utility
INCLUDE_PATH_CMAC = /home/peterson/programs/cmacclass
INCLUDE_PATH_CONSTANTS = /home/peterson/Xheaders
INCLUDES = -I$(INCLUDE_PATH_UTILITY) -I$(INCLUDE_PATH_CMAC) \
        -I$(INCLUDE_PATH_CONSTANTS)

LIBRARY_PATH_UTILITY = /home/peterson/programs/utility
LIBRARY_PATH_CMAC = /home/peterson/programs/cmacclass
SIMLIBS = -lcmac -lutility  

# ----------- #
# Definitions #
# ----------- #
CC = CC
LIBS        = -ll -lm -lgen
COMPILE_FLAGS_LINK = -g $(INCLUDES)
COMPILE_FLAGS_SOURCES = -c -g $(INCLUDES)
LIBRARY_FLAGS_SOURCES = -L$(LIBRARY_PATH_UTILITY)  \
        -L$(LIBRARY_PATH_CMAC)

# ------------- #
# Define target #
# ------------- #
TARGET = test_generator

FILESOBJ = test_generator.o 

SOURCES = $(FILESOBJ:.o=.c)

$(TARGET): $(SOURCES) $(FILESOBJ) 
        $(CC) $(COMPILE_FLAGS_LINK) -o $(TARGET) $(FILESOBJ) \
        $(LIBRARY_FLAGS_SOURCES) $(SIMLIBS) $(LIBS)

# --------------------------------------------- #
# Dependencies of source files  on header files #
# --------------------------------------------- #
$(FILESOBJ):        
        $(CC) $(COMPILE_FLAGS_SOURCES) $(LIBRARY_FLAGS_SOURCES) \
        $(SIMLIBS) $(LIBS) $*.c

test_generator.c: simul.h 
        @touch $@

The Make File for simul.c

                               
                
# -------------------------- #
# paths for this simulation  #
# -------------------------- #
INCLUDE_PATH_UTILITY = /home/peterson/programs/utility
INCLUDE_PATH_CMAC = /home/peterson/programs/cmacclass
INCLUDE_PATH_CONSTANTS = /home/peterson/Xheaders
INCLUDES = -I$(INCLUDE_PATH_UTILITY) -I$(INCLUDE_PATH_CMAC) \
        -I$(INCLUDE_PATH_CONSTANTS)

LIBRARY_PATH_UTILITY = /home/peterson/programs/utility
LIBRARY_PATH_CMAC = /home/peterson/programs/cmacclass
SIMLIBS = -lcmac -lutility 

# ----------- #
# Definitions #
# ----------- #
CC = CC
LIBS        = -ll -lm -lgen
COMPILE_FLAGS_LINK = -g $(INCLUDES)
COMPILE_FLAGS_SOURCES = -c -g $(INCLUDES)
LIBRARY_FLAGS_SOURCES = -L$(LIBRARY_PATH_UTILITY) \
        -L$(LIBRARY_PATH_CMAC)

# ------------- #
# Define target #
# ------------- #
TARGET = usecmac

FILESOBJ = simul.o 

SOURCES = $(FILESOBJ:.o=.c)

$(TARGET): $(SOURCES) $(FILESOBJ) 
        $(CC) $(COMPILE_FLAGS_LINK) -o $(TARGET) $(FILESOBJ) \
        $(LIBRARY_FLAGS_SOURCES) $(SIMLIBS) $(LIBS)

# --------------------------------------------- #
# Dependencies of source files  on header files #
# --------------------------------------------- #
$(FILESOBJ):        
        $(CC) $(COMPILE_FLAGS_SOURCES) $(LIBRARY_FLAGS_SOURCES) \
        $(SIMLIBS) $(LIBS) $*.c

simul.c: simul.h 
        @touch $@

The Make File for testmodel.c

                               
                
# -------------------------- #
# paths for this simulation  #
# -------------------------- #
INCLUDE_PATH_UTILITY = /home/peterson/programs/utility
INCLUDE_PATH_CMAC = /home/peterson/programs/cmacclass
INCLUDE_PATH_CONSTANTS = /home/peterson/Xheaders
INCLUDES = -I$(INCLUDE_PATH_UTILITY) -I$(INCLUDE_PATH_CMAC) \
        -I$(INCLUDE_PATH_CONSTANTS)

LIBRARY_PATH_UTILITY = /home/peterson/programs/utility
LIBRARY_PATH_CMAC = /home/peterson/programs/cmacclass
SIMLIBS = -lcmac -lutility  

# ----------- #
# Definitions #
# ----------- #
CC = CC
LIBS        = -ll -lm -lgen
COMPILE_FLAGS_LINK = -g $(INCLUDES)
COMPILE_FLAGS_SOURCES = -c -g $(INCLUDES)
LIBRARY_FLAGS_SOURCES = -L$(LIBRARY_PATH_UTILITY)  \
        -L$(LIBRARY_PATH_CMAC)

# ------------- #
# Define target #
# ------------- #
TARGET = testmodel

FILESOBJ = testmodel.o 

SOURCES = $(FILESOBJ:.o=.c)

$(TARGET): $(SOURCES) $(FILESOBJ) 
        $(CC) $(COMPILE_FLAGS_LINK) -o $(TARGET) $(FILESOBJ) \
        $(LIBRARY_FLAGS_SOURCES) $(SIMLIBS) $(LIBS)

# --------------------------------------------- #
# Dependencies of source files  on header files #
# --------------------------------------------- #
$(FILESOBJ):        
        $(CC) $(COMPILE_FLAGS_SOURCES) $(LIBRARY_FLAGS_SOURCES) \
        $(SIMLIBS) $(LIBS) $*.c

testmodel.c: simul.h 
        @touch $@

8.1.2   The Application Code:

test_generator.c

                               
                
#include "simul.h"

int main(int argc,char *argv[])
{
  int i,j;
  unsigned int seed;
  float xmin,xmax,ymin,ymax,xdiv,ydiv,x,y,z;
  char *test_file_name,*train_file_name,*full_data;
  FILE *fdtrain,*fdtest,*fdfull;

  // echo command line arguments 
  printf("argc = %d\n",argc);
  if( !(argc==4) ){
    printf(" Incorrect Number of Command Line Arguments!\n");
    exit(1);
    }
  else{
    switch(argc){
       case 4:
         test_file_name = argv[1];
         printf("test_file_name file = %s\n",test_file_name);
         train_file_name = argv[2]; 
         printf("train_file_name file = %s\n",train_file_name);
         full_data = argv[3]; 
         printf("full_data file = %s\n",full_data);
         break;
       default:
         printf("We should never be in this case!\n");
         exit(1);
       }
     }

  if((fdtrain=fopen(train_file_name,"w")) == NULL){
    printf("\nCan't open file %s\n",train_file_name);
    exit(0);
    }
  if((fdtest=fopen(test_file_name,"w")) == NULL){
    printf("\nCan't open file %s\n",test_file_name);
    exit(0);
    }
  if((fdfull=fopen(full_data,"w")) == NULL){
    printf("\nCan't open file %s\n",full_data);
    exit(0);
    }

  xmin = -3.0;
  xmax = 3.0;
  ymin = -3.0;
  ymax = 3.0;
  xdiv = .1;
  ydiv = .1;

  /* generate the functional data */
  seed = 50;
  srand(seed);

  /*===============================================================
     original functions

     z = 3*pow(1-x,2)*exp(-pow(x,2)-pow(y+1,2))
         -10*(x/5-pow(x,3)-pow(y,5))*exp(-pow(x,2)-pow(y,2))
        -1/3*exp(-pow(x+1,2)-pow(y,2));

     z = (x/2-pow(x,2)-pow(y,2))*exp(-.5*pow(x,2)-.5*pow(y,2))*pow(cos(y),2);

     z = exp(.1*pow(x,2)+.1*pow(y,2))*sin(2*x+y);
    ================================================================*/

  for(i=1;i<=61;++i){
    for(j=1;j<=61;++j){
      x = xmin + xdiv*(i-1);
      y = ymin + ydiv*(j-1);
      z = exp(.1*pow(x,2)+.1*pow(y,2))*sin(2*x+y);
      fprintf(fdfull,"%f   %f    %f\n",x,y,z);
      }
    }

  /* generate the training data */

  xdiv = .4;
  ydiv = .4;
  for(i=1;i<=16;++i){
    for(j=1;j<=16;++j){
      x = xmin + xdiv*(i-1);
      y = ymin + ydiv*(j-1);
      z = exp(.1*pow(x,2)+.1*pow(y,2))*sin(2*x+y);
      fprintf(fdtrain,"%f   %f    %f\n",x,y,z);
      }
    }

  /* generate the testing data */

  xdiv = .12;
  ydiv = .12;
  for(i=1;i<=51;++i){
    x = xmin + xdiv*(i-1);
    y = ymin + ydiv*(i-1);
     z = exp(.1*pow(x,2)+.1*pow(y,2))*sin(2*x+y);
    fprintf(fdtest,"%f   %f    %f\n",x,y,z);
    }
  fclose(fdtrain);
  fclose(fdtest);
  fclose(fdfull);

  return(0);
}

simul.c

                               
                
#include "simul.h"

#define DESIRED_TOL (1.0e-6)
#define STOP_TOL (1.0e-5)
#define RUN_MAX (100)
#define FREQ (5)

int main(int argc,char *argv[])
{
  int run,trainsize,testsize;
  int echo_input,do_train;
  float **intr,**inte,**outtr,**outte,rms,rmstest;

  echo_input = 1;
  do_train = 1;

  // set up CMAC architecture
  CMAC cmac(argv[1]);
  cmac.read_training_data(&intr,&outtr);
  cmac.read_testing_data(&inte,&outte);
  cmac.initialize();
  cmac.number();

  if(echo_input)
    cmac.echo();

  cmac.gettrainsize(&trainsize).gettestsize(&testsize);
  //compute rms on test set
  rmstest = cmac.compute_rms(testsize,inte,outte);
  //compute cmac rms on training 
  rms =  cmac.compute_rms(trainsize,intr,outtr);
  
  if(do_train){
    for(run=0;run<RUN_MAX;++run){
      //compute rms on test set
      rmstest = cmac.compute_rms(testsize,inte,outte);
      //compute cmac rms on training 
      rms =  cmac.compute_rms(trainsize,intr,outtr); 
      if(rms>STOP_TOL){
        cmac.train(1,DESIRED_TOL,trainsize,intr,outtr);
        if(run%FREQ==0){
          printf("rms[%3d]     = %12.6e ",run,rms);
          printf("rmstest[%3d] = %12.6e\n",run,rmstest);
          }
        }/* rms > STOP_TOL loop */ 
      }//run loop     
    printf("rms[%3d] = %12.6e ",run,rms);
    printf("rmstest[%3d] = %12.6e\n",run,rmstest);
    cmac.write_wts();
    }//
  else{
    //compute rms on test set
    rmstest = cmac.compute_rms(testsize,inte,outte);
    //compute cmac rms on training 
    rms =  cmac.compute_rms(trainsize,intr,outtr);

    printf("rms[%3d] = %12.6e ",run,rms);
    printf("rmstest[%3d] = %12.6e\n",run,rmstest);
    }

  return(1);
}

testmodel.c

                               
                
#include "simul.h"

int main(int argc,char *argv[])
{
  int i,k,count,run,testsize,out_size;
  float x,y,z,**inte,**outte,rms;
  float *values;
  char *source_file,*destination_file;
  FILE *in_file_pointer,*out_file_pointer;

  // echo command line arguments 
  printf("argc = %d\n",argc);
  if( !(argc==4) ){
    printf(" Incorrect Number of Command Line Arguments!\n");
    exit(1);
    }
  else{
    switch(argc){
       case 4:
         //argv[1] contains the name of the CMAC
         //initialization file.
         source_file = argv[2]; 
         printf("source file = %s\n",source_file);
         destination_file = argv[3]; 
         printf("source file = %s\n",destination_file);
         break;
       default:
         printf("We should never be in this case!\n");
         exit(1);
       }
     }

  /*======================================================= 
     open the file which contains ordered triples
     
          x  y z

     where x, y and z are floating point numbers.
     The pair (x,y) denotes a data point in the
     domain of the function f(x,y).  The scalar
     value z denotes the true value of the function
     f at the domain value (x,y).
    =======================================================*/

  if((in_file_pointer=fopen(source_file,"r")) == NULL){
    printf("\nCan't open file %s\n",source_file);
    exit(1);
    }

  /*======================================================= 
     open an output file to put the model results into
     in the following format 

          x  y w

     where x, y and w are floating point numbers.
     The pair (x,y) denotes a data point in the
     domain of the function f(x,y).  The scalar
     value w denotes the value of the CMAC model
     for the function f at the domain value (x,y).
     It is important to realize that w and z need not be 
     the same.
    =======================================================*/
  if((out_file_pointer=fopen(destination_file,"w")) == NULL){
    printf("\nCan't open file $s\n",destination_file);
    exit(1);
    }

  // initialize counters 
  count = 0;

  // count the number of samples in the source file 
  while( fscanf(in_file_pointer,"%f %f %f",&x,&y,&z) !=EOF)
    ++count;
  fclose(in_file_pointer);

  // reopen the source file with read only status 
  if((in_file_pointer=fopen(source_file,"r")) == NULL){
    printf("\nCan't open file %s\n",source_file);
    exit(1);
    }

   fclose(in_file_pointer);

  // set up CMAC architecture and read in weights
  CMAC cmac(argv[1]);
  cmac.read_training_data(&inte,&outte).initialize().number();
  cmac.echo();

  /*=====================================================
    Generate a file of test inputs and cmac outputs for
    3d graphing purposes: we assume there are only 2 inputs
    and 1 output 
    ====================================================*/
  printf("Howdy! We have finished with the cmac inits\n");
  cmac.getoutputsize(&out_size);
  printf("count = %d\n",count);
  values = new float[out_size];
  for(k=0;k<count;++k){
    values = cmac.cmaceval(1,inte[k]);
    outte[k][0] = values[0];
    for(i=0;i<2;++i){
      fprintf(out_file_pointer,"%8.3f ",inte[k][i]);
      //printf("%8.3f ",inte[k][i]); 
      }     
    fprintf(out_file_pointer,"%8.3f\n",values[0]);
    fprintf(out_file_pointer,"\n");
    }
  fclose(out_file_pointer);

  //compute rms on model data
  rms = cmac.compute_rms(count,inte,outte);  

  delete inte;
  delete outte;
  return(1);
}

8.1.3   Configuration Files:

The configuration files needed by the simulation program are ASCII text files containing the information such as that given below:

func.cfg:
basic configuration
funcinit.txt:
file containing names of configuration files for CMAC architectures; one file name per output component
func_train.txt:
training file
func_test.txt:
testing file
func.fin:
CMAC weights can be initialized using contents of this file
func.fin:
CMAC weights for a training run are stored in this file
121:
number of training samples
50:
number of testing samples
2:
number of input components
1:
number of output components
.95:
the learning rate
0.0:
the setting for setup.inflate_bottom
0.0:
the setting for setup.inflate_top
setfunc.cfg:
specifies CMAC structure
3:
the number of levels
26:
the hash size
.8:
the receptive field width
funcinit.txt:
contains a file name for each output component; here, there is only one output component, so there is just one file name --- setfunc.cfg
setfunc.cfg:
CMAC configuration file for output 1
The actual terminal output for the simulation run corresponding to the configuration files above is presented below. First, we generate training and testing data for this function using test_generator().


albert% test_generator test1.txt train1.txt full1.txt
argc = 4
test_file_name file = test1.txt
train_file_name file = train1.txt
full_data file = full1.txt
Next, we train the given CMAC model on the data using usecmac().


albert% usecmac func.cfg
startup_file = func.cfg
funcinit.txt
train1.txt
test1.txt
func.fin
func.fin
setup.training_set_size = 256  !!! setup.training_set_size
setup.testing_set_size = 51  !!! setup.testing_set_size
setup.in_dimensions = 2  !!! setup.in_dimensions
setup.out_dimensions = 1  !!! setup.out_dimensions
setup.learning_rate = 0.950000  !!! setup.learning_rate
setup.echo_input = 1  !!!  setup.echo_input
setup.do_training = 1  !!! setup.do_training
setup.read_in_wts = 0  !!! setup.read_in_wts
setup.autosize = 1  !!! setup.autosize
setup.inflate_bottom = 0  !!! setup.inflate_bottom
setup.inflate_top = 0  !!! setup.inflate_top
setfunc.cfg
Input[0]::min/max of input widths=    -3.000000/    3.000000
Input[1]::min/max of input widths=    -3.000000/    3.000000
Input[0]::min/max of input widths=    -3.000000/    3.000000
Input[1]::min/max of input widths=    -3.000000/    3.000000

setup.startup_file = func.cfg
setup.cmac_file = funcinit.txt
setup.training_file = train1.txt
setup.testing_file = test1.txt
setup.initfile = func.fin
setup.wtfile = func.fin
setup.training_set_size = 256
setup.testing_set_size =  51
setup.learning_rate =     0.950000
setup.in_dimensions =   2
setup.out_dimensions =   1
input interval[  0] = [   -3.000000,    3.000000]
input interval[  1] = [   -3.000000,    3.000000]

setup.file[  0] = setfunc.cfg

*************************
CMAC[  0] parameters
*************************

number levels =   3
hash =  26
offset =     0.333333
width =     0.800000
LEVEL  INPUT   OFFSET       FIELD WIDTH  HASH_SIZE

   0      0        0.000000       0.800000    26
   0      1        0.000000       0.800000    26
   1      0        0.266667       0.800000    26
   1      1        0.266667       0.800000    26
   2      0        0.533333       0.800000    26
   2      1        0.533333       0.800000    26
sensors[output = 0][level = 0][input = 0] = 216368
sensors[output = 0][level = 0][input = 1] = 909127728
sensors[output = 0][level = 1][input = 0] = 216384
sensors[output = 0][level = 1][input = 1] = 807411744
sensors[output = 0][level = 2][input = 0] = 216400
sensors[output = 0][level = 2][input = 1] = 775303216

flattened sensors[output = 0, levels = 3][0 input] = 23
flattened sensors[output = 0, levels = 3][1 input] = 23
flattened sensors[output = 0, levels = 3, input = 2] = 529
Total flattened sensors for 1 outputs = 529

rms[  0]     = 1.677679e+00 rmstest[  0] = 1.891320e+00
rms[  1]     = 1.399867e+00 rmstest[  1] = 1.795955e+00
rms[  2]     = 1.382564e+00 rmstest[  2] = 1.944340e+00
rms[  3]     = 1.357107e+00 rmstest[  3] = 1.805224e+00
rms[  4]     = 1.346904e+00 rmstest[  4] = 1.796974e+00
rms[  5]     = 1.352754e+00 rmstest[  5] = 1.822708e+00
rms[  6]     = 1.354311e+00 rmstest[  6] = 1.830258e+00
rms[  7]     = 1.353011e+00 rmstest[  7] = 1.825351e+00
rms[  8]     = 1.352653e+00 rmstest[  8] = 1.824166e+00
rms[  9]     = 1.353043e+00 rmstest[  9] = 1.825368e+00
rms[ 10]     = 1.353172e+00 rmstest[ 10] = 1.825570e+00
rms[ 11]     = 1.353148e+00 rmstest[ 11] = 1.825254e+00
rms[ 12]     = 1.353192e+00 rmstest[ 12] = 1.825204e+00
rms[ 13]     = 1.353262e+00 rmstest[ 13] = 1.825271e+00
rms[ 14]     = 1.353309e+00 rmstest[ 14] = 1.825279e+00
rms[ 15]     = 1.353344e+00 rmstest[ 15] = 1.825267e+00
rms[ 16]     = 1.353376e+00 rmstest[ 16] = 1.825270e+00
rms[ 17]     = 1.353405e+00 rmstest[ 17] = 1.825277e+00
rms[ 18]     = 1.353428e+00 rmstest[ 18] = 1.825279e+00
rms[ 19]     = 1.353447e+00 rmstest[ 19] = 1.825280e+00
rms[ 20]     = 1.353464e+00 rmstest[ 20] = 1.825281e+00
rms[ 21]     = 1.353477e+00 rmstest[ 21] = 1.825283e+00
rms[ 22]     = 1.353488e+00 rmstest[ 22] = 1.825283e+00
rms[ 23]     = 1.353498e+00 rmstest[ 23] = 1.825283e+00
rms[ 24]     = 1.353505e+00 rmstest[ 24] = 1.825284e+00
rms[ 25] = 1.353505e+00 rmstest[ 25] = 1.825284e+00

Finally, we generate the data needed to plot the surface corresponding to the CMAC model using testmodel(). This function call requires that we slighly modify the original func.cfg configuration file as follows:


funcinit.txt
full1.txt                        <====  New training file is full1.txt
test1.txt
func.fin
func.fin
3721!!! setup.training_set_size  <====  New training size
51!!! setup.testing_set_size
2!!! setup.in_dimensions
1!!! setup.out_dimensions
.95!!! setup.learning_rate
0!!!  setup.echo_input
0!!! setup.do_training
1!!! setup.read_in_wts           <=====  Read in the trained CMAC weights
0!!! setup.autosize              <====   Use a fixed domain size
-3.1!!! setup.inflate_bottom     <====   Set common_start
3.1!!! setup.inflate_top         <====   Set common_end

albert% testmodel func2.cfg full1.txt MATLAB1.txt
The CMAC model built to approximate this function using three levels, a hash size of 26 and a receptive field width of 0.8 is shown in Figure 8.2. This model is the result of the sample session shown above.



Figure 8.2:

8.2   64 Level Approximation:

The function data generated above was used to calculate the CMAC response for the data points (xi,yj) for a CMAC simulation run using the basic configuration below:

setfunc.cfg:
specifies CMAC structure
  1. 64: the number of levels
  2. 373: hash size
  3. 0.3 field width
The resulting surface model is shown in Figure 8.3.



Figure 8.3:

8.3   20 Level Approximation:

What happens if the number of levels and the receptive width are decreased? An entire series of CMAC simulation runs can be completed using 20 levels and the basic configuration:

setfunc.cfg:
specifies CMAC structure
  1. 20: the number of levels
  2. 373: hash size
  3. 0.2 width
As is seen in Figure 8.4, the approximation is now much worse, with clearly defined spikes in the surface plot.

There are significant hashing collisions in this model and a very fine field width. There are about
900 sensors per level with a hash size of 373. This model is not very good.



Figure 8.4:

We will recalculate this model using a larger receptive field width:

setfunc.cfg:
specifies CMAC structure
  1. 20: the number of levels
  2. 373: hash size
  3. 0.4 width
As is seen in Figure 8.5, the approximation is now much worse, with clearly defined spikes in the surface plot.



Figure 8.5:

8.4   Eight or Fewer Level Approximation:

If the number of levels is further decreased, there is a concommittant further decrease in performance. An entire series of CMAC simulation runs can also be completed using just eight levels and the basic configuration

setfunc.cfg:
specifies CMAC structure
  1. 8: the number of levels
  2. 373: hash size
  3. 1.2 width


Figure 8.6:


Previous Next Contents