00001
00002
00003
00004
00005
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;
00017 float Bias;
00018 int NoOfSources;
00019 struct UT **sources;
00020 float *weights;
00021 } UnitType, *pUnit;
00022
00023
00024 static UnitType Units[10];
00025
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
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
00048 static UnitType Units[10] =
00049 {
00050 { 0.0, 0.0, 0, NULL , NULL },
00051 {
00052 0.0, 1.000000, 0,
00053 &Sources[0] ,
00054 &Weights[0] ,
00055 },
00056 {
00057 0.0, 0.998030, 0,
00058 &Sources[0] ,
00059 &Weights[0] ,
00060 },
00061 {
00062 0.0, 0.916740, 0,
00063 &Sources[0] ,
00064 &Weights[0] ,
00065 },
00066 {
00067 0.0, 0.406360, 3,
00068 &Sources[0] ,
00069 &Weights[0] ,
00070 },
00071 {
00072 0.0, -0.057010, 3,
00073 &Sources[3] ,
00074 &Weights[3] ,
00075 },
00076 {
00077 0.0, -0.434500, 3,
00078 &Sources[6] ,
00079 &Weights[6] ,
00080 },
00081 {
00082 0.0, 0.663390, 3,
00083 &Sources[9] ,
00084 &Weights[9] ,
00085 },
00086 {
00087 0.0, 0.311790, 3,
00088 &Sources[12] ,
00089 &Weights[12] ,
00090 },
00091 {
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
00110
00111 static pUnit Input[3] = {Units + 1, Units + 2, Units + 3};
00112
00113 static pUnit Hidden1[5] = {Units + 4, Units + 5, Units + 6, Units + 7, Units + 8};
00114
00115 static pUnit Output1[1] = {Units + 9};
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 }