/***************************************************************************** * * * FOX Controller Library, Version 1.3.3. * * * * Copyright (C) 1998,1999,2000 Russell Smith (rl.smith@auckland.ac.nz) * * * * The FOX Controller Library is free software; you can redistribute it * * and/or modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either version * * 2 of the License, or (at your option) any later version. * * * * The FOX Controller Library is distributed in the hope that it will be * * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with the Fox Controller Library; see the file COPYING.LIB. * * If not, write to the Free Software Foundation, Inc., 59 Temple Place - * * Suite 330, Boston, MA 02111-1307, USA. * * * *****************************************************************************/ // Test of the FOX-N algorithm on simple linear systems. #include #include #include #include #include "fox-n.h" cftype frandom() { return cftype(random())/cftype(RAND_MAX); } void PlotData (int n, float *y) { for (int i=0; i fabs(old_pos_error)) fox.Train (error * learning_rate); else fox.Train (error * learning_rate * 0.1); old_pos_error = pos_error; cftype newy[2]; newy[0] = Adata[0]*y[0] + Adata[1]*y[1] + Bdata[0]*x; newy[1] = Adata[2]*y[0] + Adata[3]*y[1] + Bdata[1]*x; y[0] = newy[0]; y[1] = newy[1]; } // plot the results if ((iteration % 10)==0) { fprintf (stderr,"%d\n",iteration); PlotData (T,this_y0); PlotData (T,this_y1); PlotData (T,this_x); cftype *tmp = this_y0; this_y0 = save_y0; save_y0 = tmp; tmp = this_y1; this_y1 = save_y1; save_y1 = tmp; tmp = this_x; this_x = save_x; save_x = tmp; } } return 0; }