src/common/filter_net.c

00001 /*********************************************************
00002   test_1/filter_net.c
00003   --------------------------------------------------------
00004   generated at Tue Jul 19 14:46:44 2005
00005   by snns2c ( Bernward Kett 1995 ) 
00006 *********************************************************/
00007 
00008 #include <math.h>
00009 
00010 #define Act_Logistic(sum, bias)  ( (sum+bias<10000.0) ? ( 1.0/(1.0 + exp(-sum-bias) ) ) : 0.0 )
00011 #ifndef NULL
00012 #define NULL (void *)0
00013 #endif
00014 
00015 typedef struct UT {
00016           float act;         /* Activation       */
00017           float Bias;        /* Bias of the Unit */
00018           int   NoOfSources; /* Number of predecessor units */
00019    struct UT   **sources; /* predecessor units */
00020           float *weights; /* weights from predecessor units */
00021         } UnitType, *pUnit;
00022 
00023   /* Forward Declaration for all unit types */
00024   static UnitType Units[10];
00025   /* Sources definition section */
00026   static pUnit Sources[] =  {
00027 Units + 1, Units + 2, Units + 3, 
00028 Units + 1, Units + 2, Units + 3, 
00029 Units + 1, Units + 2, Units + 3, 
00030 Units + 1, Units + 2, Units + 3, 
00031 Units + 1, Units + 2, Units + 3, 
00032 Units + 4, Units + 5, Units + 6, Units + 7, Units + 8, 
00033 
00034   };
00035 
00036   /* Weigths definition section */
00037   static float Weights[] =  {
00038 2.075310, 3.843340, 0.061740, 
00039 -0.027020, 0.112820, 0.606700, 
00040 -0.672260, 0.391710, 0.799930, 
00041 0.888670, 3.404130, 0.143620, 
00042 -0.815620, -0.186080, -0.807600, 
00043 -4.194760, -0.058950, -1.101900, -3.117450, 1.956400, 
00044 
00045   };
00046 
00047   /* unit definition section (see also UnitType) */
00048   static UnitType Units[10] = 
00049   {
00050     { 0.0, 0.0, 0, NULL , NULL },
00051     { /* unit 1 (unit) */
00052       0.0, 1.000000, 0,
00053        &Sources[0] , 
00054        &Weights[0] , 
00055       },
00056     { /* unit 2 (unit) */
00057       0.0, 0.998030, 0,
00058        &Sources[0] , 
00059        &Weights[0] , 
00060       },
00061     { /* unit 3 (unit) */
00062       0.0, 0.916740, 0,
00063        &Sources[0] , 
00064        &Weights[0] , 
00065       },
00066     { /* unit 4 (unit) */
00067       0.0, 0.406360, 3,
00068        &Sources[0] , 
00069        &Weights[0] , 
00070       },
00071     { /* unit 5 (unit) */
00072       0.0, -0.057010, 3,
00073        &Sources[3] , 
00074        &Weights[3] , 
00075       },
00076     { /* unit 6 (unit) */
00077       0.0, -0.434500, 3,
00078        &Sources[6] , 
00079        &Weights[6] , 
00080       },
00081     { /* unit 7 (unit) */
00082       0.0, 0.663390, 3,
00083        &Sources[9] , 
00084        &Weights[9] , 
00085       },
00086     { /* unit 8 (unit) */
00087       0.0, 0.311790, 3,
00088        &Sources[12] , 
00089        &Weights[12] , 
00090       },
00091     { /* unit 9 (unit) */
00092       0.0, 0.392790, 5,
00093        &Sources[15] , 
00094        &Weights[15] , 
00095       }
00096 
00097   };
00098 
00099 
00100 
00101 int filter_net(float *in, float *out, int init)
00102 {
00103   int member, source;
00104   float sum;
00105   enum{OK, Error, Not_Valid};
00106   pUnit unit;
00107 
00108 
00109   /* layer definition section (names & member units) */
00110 
00111   static pUnit Input[3] = {Units + 1, Units + 2, Units + 3}; /* members */
00112 
00113   static pUnit Hidden1[5] = {Units + 4, Units + 5, Units + 6, Units + 7, Units + 8}; /* members */
00114 
00115   static pUnit Output1[1] = {Units + 9}; /* members */
00116 
00117   static int Output[1] = {9};
00118 
00119   for(member = 0; member < 3; member++) {
00120     Input[member]->act = in[member];
00121   }
00122 
00123   for (member = 0; member < 5; member++) {
00124     unit = Hidden1[member];
00125     sum = 0.0;
00126     for (source = 0; source < unit->NoOfSources; source++) {
00127       sum += unit->sources[source]->act
00128              * unit->weights[source];
00129     }
00130     unit->act = Act_Logistic(sum, unit->Bias);
00131   };
00132 
00133   for (member = 0; member < 1; member++) {
00134     unit = Output1[member];
00135     sum = 0.0;
00136     for (source = 0; source < unit->NoOfSources; source++) {
00137       sum += unit->sources[source]->act
00138              * unit->weights[source];
00139     }
00140     unit->act = Act_Logistic(sum, unit->Bias);
00141   };
00142 
00143   for(member = 0; member < 1; member++) {
00144     out[member] = Units[Output[member]].act;
00145   }
00146 
00147   return(OK);
00148 }

Generated on Wed Apr 11 16:50:49 2007 for open_prospect by  doxygen 1.4.6