next up previous contents
Next: Main Modules Up: Source Code Previous: Module: Backpropagation   Contents

Subsections

Module: Genetic Backpropagation

File: genback.h


  1	
  2	/* Definitions for Genetic Backpropagation */
  3	
  4	#ifndef GENBACK_H
  5	#define GENBACK_H       1
  6	
  7	#include "defs.h"
  8	
  9	void randomNetPop(int popsize,float w);
 10	void gen2back(ind x);
 11	void back2gen(ind x);
 12	void backsteps(ind x,int n);
 13	
 14	#endif
 15

File: genback.c


  1	
  2	/* Implementations for Genetric Backpropagation */
  3	
  4	#include "defs.h"
  5	#include "ind.h"
  6	#include "gen.h"
  7	#include "back.h"
  8	#include "stdnet.h"
  9	#include "genback.h"
 10	
 11	void randomNetPop(int popsize,float w)
 12	{
 13	  int i;
 14	
 15	  for(i=0;i<popsize;i++)
 16	  {
 17	    randomNet(w);
 18	    back2gen(Pop[i]);
 19	  };
 20	}
 21	
 22	void gen2back(ind x)
 23	{
 24	  int i,j,k;
 25	  for(i=0;i<=Nin;i++)
 26	    for(j=0;j<Nhid;j++)
 27	      { Wih[i][j]=weight1(x,i,j); DDih[i][j]=0.0; };
 28	  for(j=0;j<=Nhid;j++)
 29	    for(k=0;k<Nout;k++)
 30	      { Who[j][k]=weight2(x,j,k); DDho[j][k]=0.0; };
 31	  LearnRate=lrate(x);
 32	  Impulse=imp(x);
 33	}
 34	
 35	void back2gen(ind x)
 36	{
 37	  int i,j,k;
 38	  int w,m;
 39	  float s;
 40	
 41	  m=(1<<Nbits)-1;
 42	  s=((1<<(Nbits-1))-1)/Width;
 43	  for(i=0;i<=Nin;i++)
 44	    for(j=0;j<Nhid;j++)
 45	    {
 46	      w=float2int(Wih[i][j]);
 47	      if(w<0) w=0; else if(w>FGmax) w=FGmax;
 48	      putbits(int2grey[w],x,IncW1*j+Nbits*i,Nbits);
 49	    };
 50	  for(j=0;j<=Nhid;j++)
 51	    for(k=0;k<Nout;k++)
 52	    {
 53	      w=float2int(Who[j][k]);
 54	      if(w<0) w=0; else if(w>FGmax) w=FGmax;
 55	      putbits(int2grey[w],x,OffW2+IncW2*k+Nbits*j,Nbits);
 56	    };
 57	}
 58	
 59	void backsteps(ind x,int n)
 60	{
 61	  int i;
 62	
 63	  gen2back(x);
 64	  for(i=0;i<n;i++)
 65	  {
 66	    calcNetErr();
 67	    updateNet();
 68	  };
 69	  back2gen(x);
 70	}
 71



(c) Bernhard Ömer - oemer@tph.tuwien.ac.at - http://tph.tuwien.ac.at/~oemer/