/Home/aooliver/hepsoft/lcdroot/LCDRootApps/PhUtil/src/LCDNNHFSelect.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002   $Id: LCDNNHFSelect.c,v 1.2 2001/05/11 21:35:52 toshi Exp $
00003   -----------------------------------------------------------------------------
00004 
00005   $Log: LCDNNHFSelect.c,v $
00006   Revision 1.2  2001/05/11 21:35:52  toshi
00007   Add CVS tags $Id: $ and $Log: $.
00008 
00009 
00010 */
00011 /*********************************************************
00012   LCDNNHFSelect.c
00013   --------------------------------------------------------
00014   generated at Wed Feb 21 08:56:51 2001
00015   by snns2c ( Bernward Kett 1995 ) 
00016 *********************************************************/
00017 
00018 #include <math.h>
00019 
00020 #define Act_Logistic(sum, bias)  ( (sum+bias<10000.0) ? ( 1.0/(1.0 + exp(-sum-bias) ) ) : 0.0 )
00021 #ifndef NULL
00022 #define NULL (void *)0
00023 #endif
00024 
00025 typedef struct UT {
00026           float act;         /* Activation       */
00027           float Bias;        /* Bias of the Unit */
00028           int   NoOfSources; /* Number of predecessor units */
00029    struct UT   **sources; /* predecessor units */
00030           float *weights; /* weights from predecessor units */
00031         } UnitType, *pUnit;
00032 
00033   /* Forward Declaration for all unit types */
00034   static UnitType Units[13];
00035   /* Sources definition section */
00036   static pUnit Sources[] =  {
00037 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00038 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00039 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00040 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00041 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00042 Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, 
00043 Units + 6, Units + 7, Units + 8, Units + 9, Units + 10, Units + 11, 
00044 
00045   };
00046 
00047   /* Weigths definition section */
00048   static float Weights[] =  {
00049 -5.726510, 6.655230, -11.942260, -9.211320, 0.260430, 
00050 -26.757999, 27.343969, -2.859360, 15.351010, 5.491600, 
00051 -3.124630, -23.940670, -5.141180, 3.643160, -1.002410, 
00052 -6.723220, 12.006890, -7.269670, -2.353060, 1.204720, 
00053 50.095360, 4.463220, -0.085040, 1.576510, 0.387810, 
00054 0.315170, -21.674749, -13.851600, -5.173480, -5.121190, 
00055 10.226540, 3.393190, -4.233980, -9.292990, 3.493660, -4.339010, 
00056 
00057   };
00058 
00059   /* unit definition section (see also UnitType) */
00060   static UnitType Units[13] = 
00061   {
00062     { 0.0, 0.0, 0, NULL , NULL },
00063     { /* unit 1 (Old: 1) */
00064       0.0, 1.000000, 0,
00065        &Sources[0] , 
00066        &Weights[0] , 
00067       },
00068     { /* unit 2 (Old: 2) */
00069       0.0, 0.998030, 0,
00070        &Sources[0] , 
00071        &Weights[0] , 
00072       },
00073     { /* unit 3 (Old: 3) */
00074       0.0, 0.916740, 0,
00075        &Sources[0] , 
00076        &Weights[0] , 
00077       },
00078     { /* unit 4 (Old: 4) */
00079       0.0, 0.646710, 0,
00080        &Sources[0] , 
00081        &Weights[0] , 
00082       },
00083     { /* unit 5 (Old: 5) */
00084       0.0, 0.270800, 0,
00085        &Sources[0] , 
00086        &Weights[0] , 
00087       },
00088     { /* unit 6 (Old: 6) */
00089       0.0, 4.060990, 5,
00090        &Sources[0] , 
00091        &Weights[0] , 
00092       },
00093     { /* unit 7 (Old: 7) */
00094       0.0, -6.909750, 5,
00095        &Sources[5] , 
00096        &Weights[5] , 
00097       },
00098     { /* unit 8 (Old: 8) */
00099       0.0, 11.493260, 5,
00100        &Sources[10] , 
00101        &Weights[10] , 
00102       },
00103     { /* unit 9 (Old: 9) */
00104       0.0, -0.767500, 5,
00105        &Sources[15] , 
00106        &Weights[15] , 
00107       },
00108     { /* unit 10 (Old: 10) */
00109       0.0, -21.509930, 5,
00110        &Sources[20] , 
00111        &Weights[20] , 
00112       },
00113     { /* unit 11 (Old: 11) */
00114       0.0, 12.785520, 5,
00115        &Sources[25] , 
00116        &Weights[25] , 
00117       },
00118     { /* unit 12 (Old: 12) */
00119       0.0, 1.670950, 6,
00120        &Sources[30] , 
00121        &Weights[30] , 
00122       }
00123 
00124   };
00125 
00126 
00127 
00128 int LCDNNHFSelect(float *in, float *out, int init)
00129 {
00130   int member, source;
00131   float sum;
00132   enum{OK, Error, Not_Valid};
00133   pUnit unit;
00134 
00135 
00136   /* layer definition section (names & member units) */
00137 
00138   static pUnit Input[5] = {Units + 1, Units + 2, Units + 3, Units + 4, Units + 5}; /* members */
00139 
00140   static pUnit Hidden1[6] = {Units + 6, Units + 7, Units + 8, Units + 9, Units + 10, Units + 11}; /* members */
00141 
00142   static pUnit Output1[1] = {Units + 12}; /* members */
00143 
00144   static int Output[1] = {12};
00145 
00146   for(member = 0; member < 5; member++) {
00147     Input[member]->act = in[member];
00148   }
00149 
00150   for (member = 0; member < 6; member++) {
00151     unit = Hidden1[member];
00152     sum = 0.0;
00153     for (source = 0; source < unit->NoOfSources; source++) {
00154       sum += unit->sources[source]->act
00155              * unit->weights[source];
00156     }
00157     unit->act = Act_Logistic(sum, unit->Bias);
00158   };
00159 
00160   for (member = 0; member < 1; member++) {
00161     unit = Output1[member];
00162     sum = 0.0;
00163     for (source = 0; source < unit->NoOfSources; source++) {
00164       sum += unit->sources[source]->act
00165              * unit->weights[source];
00166     }
00167     unit->act = Act_Logistic(sum, unit->Bias);
00168   };
00169 
00170   for(member = 0; member < 1; member++) {
00171     out[member] = Units[Output[member]].act;
00172   }
00173 
00174   return(OK);
00175 }

Generated on Tue Jul 18 18:33:59 2006 for LCDROOT by  doxygen 1.4.6