00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "CINNIC/contourNeuron.H"
00039 #include "Util/log.H"
00040
00041 #include <cmath>
00042 #include <cstdlib>
00043 #include <cstdio>
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 float AngleDropOff,AngleSupress,SupMult,OrthA,OrthB,OrthMult,valueCutOff;
00055 float coLinearCutOff;
00056 float NeuronExSize,NeuronSupSize,NeuronSupStart,NeuronOrthSize;
00057 float CoLinearDiff;
00058
00059
00060 float NeuralAngles[AnglesUsed]={CINNIC_ANGLES};
00061 float XCenter, YCenter, ExReach, SupReach,OrthReach;
00062 float linearFactor2e,linearFactor3e,linearFactor2s,linearFactor3s;
00063 float distanceSupFactor2,distanceSupFactor3,distanceExFactor2,distanceExFactor3;
00064
00065
00066
00067 template <class TC2>
00068 float ContourNeuronCreate<TC2>::FindRatio(TC2& XMax, TC2& X)
00069 {
00070 return ((XMax-X)/XMax);
00071 }
00072
00073
00074
00075 template <class TC2>
00076 float ContourNeuronCreate<TC2>::FindDistance(TC2& PiX, TC2& PiY)
00077 {
00078 return (sqrt((PiX*PiX)+(PiY*PiY)));
00079 }
00080
00081
00082
00083
00084 template <class TC2>
00085 void ContourNeuronCreate<TC2>::FindCenter()
00086 {
00087 XCenter = XSize/2;
00088 YCenter = YSize/2;
00089 }
00090
00091 template <class TC2>
00092 void ContourNeuronCreate<TC2>::FindReach()
00093 {
00094 ExReach = NeuronExSize/2;
00095 SupReach = NeuronSupSize/2;
00096 OrthReach = NeuronOrthSize/2;
00097 }
00098
00099
00100
00101 template <class TC2>
00102 float ContourNeuronCreate<TC2>::FindAngleToRad(TC2& X,TC2& Y)
00103 {
00104
00105
00106
00107
00108
00109 hold = 0;
00110 if(Y > YCenter)
00111 {
00112 if(X > XCenter)
00113 {
00114 hold = (atan(fabs(XCenter-X)/fabs(YCenter-Y)));
00115 }
00116 if(X < XCenter)
00117 {
00118 hold = (2*pi)-(atan(fabs(XCenter-X)/fabs(YCenter-Y)));
00119 }
00120 if(X == XCenter)
00121 {
00122 hold = 0;
00123 }
00124 }
00125
00126 if(Y < YCenter)
00127 {
00128 if(X > XCenter)
00129 {
00130 hold = pi-(atan(fabs(XCenter-X)/fabs(YCenter-Y)));
00131 }
00132 if(X < XCenter)
00133 {
00134 hold = pi+(atan(fabs(XCenter-X)/fabs(YCenter-Y)));
00135 }
00136 if(X == XCenter)
00137 {
00138 hold = pi;
00139 }
00140 }
00141
00142 if(Y == YCenter)
00143 {
00144 if(X > XCenter)
00145 {
00146 hold = pi/2;
00147 }
00148 if(X < XCenter)
00149 {
00150 hold = pi+(pi/2);
00151 }
00152 }
00153 return hold;
00154 }
00155
00156
00157
00158 template <class TC2>
00159 float ContourNeuronCreate<TC2>::FindRadToDeg(TC2& r)
00160 {
00161 return ((180/pi) * r);
00162 }
00163
00164
00165
00166 template <class TC2>
00167 float ContourNeuronCreate<TC2>::FindLinear(TC2& m, TC2& n,TC2& o,TC2& x, TC2& b)
00168 {
00169 return ((m*x)+(n*(pow(x,2)))+(o*(pow(x,3)))+b);
00170 }
00171
00172 template <class TC2>
00173 float ContourNeuronCreate<TC2>::sigmoid(TC2& beta, TC2& v)
00174 {
00175 return (1/(1+pow(2.71828,(-2.0*(beta * v)))));
00176 }
00177
00178
00179 #if 0
00180 template <class TC2>
00181 PropHold ContourNeuronCreate<TC2>::GetCompleteNeuron()
00182 {
00183
00184
00185
00186
00187
00188 return FourDNeuralMap[AnglesUsed][AnglesUsed][XSize][YSize];
00189 }
00190 #endif
00191
00192
00193
00194 template <class TC2>
00195 void ContourNeuronCreate<TC2>::CreateNeuron(readConfig &config)
00196 {
00197 one = 1;
00198 AngleDropOff = config.getItemValueF("AngleDropOff");
00199 AngleSupress = config.getItemValueF("AngleSupress");
00200 SupMult = config.getItemValueF("SupMult");
00201 OrthMult = config.getItemValueF("OrthMult");
00202 OrthA = config.getItemValueF("AngleOrthRangeA");
00203 OrthB = config.getItemValueF("AngleOrthRangeB");
00204 NeuronExSize = config.getItemValueF("NeuronExSize");
00205 NeuronSupSize = config.getItemValueF("NeuronSupSize");
00206 NeuronSupStart = config.getItemValueF("NeuronSupStart");
00207 NeuronOrthSize = config.getItemValueF("NeuronOrthSize");
00208 valueCutOff = config.getItemValueF("valueCutOff");
00209 CoLinearDiff = config.getItemValueF("CoLinearDiff");
00210 coLinearCutOff = config.getItemValueF("coLinearCutOff");
00211 linearFactor2e = config.getItemValueF("linearFactor2e");
00212 linearFactor3e = config.getItemValueF("linearFactor3e");
00213 linearFactor2s = config.getItemValueF("linearFactor2s");
00214 linearFactor3s = config.getItemValueF("linearFactor3s");
00215 distanceSupFactor2 = config.getItemValueF("distanceSupFactor2");
00216 distanceSupFactor3 = config.getItemValueF("distanceSupFactor3");
00217 distanceExFactor2 = config.getItemValueF("distanceExFactor2");
00218 distanceExFactor3 = config.getItemValueF("distanceExFactor3");
00219
00220 factor = -1/(1-FindRatio(foo = AngleCenter,bar = AngleDropOff));
00221 factor2 = -1/(1-FindRatio(foo = AngleCenter,bar = AngleSupress));
00222 OFactorA = -1/(1-FindRatio(foo = AngleCenter, bar = OrthA));
00223 OFactorB = -1/(1-FindRatio(foo = AngleCenter, bar = OrthB));
00224 FindCenter();
00225 FloatAngleCenter = AngleCenter;
00226 FindReach();
00227
00228
00229
00230 LINFO("Starting neuron generation");
00231 for (int i = 0; i < AnglesUsed; i++)
00232 {
00233 printf(".");
00234 for (int j = 0; j < AnglesUsed; j++)
00235 {
00236 for (int k = 0; k <= XSize; k++)
00237 {
00238 for (int l = 0; l <= YSize; l++)
00239 {
00240 if((k == (int)XCenter) && (l == (int)YCenter))
00241 {
00242 FourDNeuralMap[i][j][k][l].zero = false;
00243 FourDNeuralMap[i][j][k][l].angABD = 0;
00244 FourDNeuralMap[i][j][k][l].angAB = 0;
00245 FourDNeuralMap[i][j][k][l].dis = 0;
00246 }
00247 else
00248 {
00249 ii = i;jj = j;kk = k;ll = l;
00250
00251 distanceX = fabs(XCenter-kk);
00252 distanceY = fabs(YCenter-ll);
00253 distance = FindDistance(distanceX, distanceY);
00254
00255
00256
00257
00258
00259
00260
00261 float exreach = FindRatio(ExReach, distance);
00262 float supreach = FindRatio(SupReach, distance);
00263 FourDNeuralMap[i][j][k][l].dis = FindRatio(XCenter, distance);
00264 FourDNeuralMap[i][j][k][l].Edis = exreach + (distanceExFactor2*pow(exreach,2))
00265 + (distanceExFactor3*pow(exreach,3));
00266 FourDNeuralMap[i][j][k][l].Sdis = supreach + (distanceSupFactor2*pow(supreach,2))
00267 + (distanceSupFactor3*pow(supreach,3));
00268 FourDNeuralMap[i][j][k][l].Odis = FindRatio(OrthReach, distance);
00269 if(FourDNeuralMap[i][j][k][l].dis < 0)
00270 {FourDNeuralMap[i][j][k][l].dis = 0;}
00271 if(FourDNeuralMap[i][j][k][l].Edis < 0)
00272 {FourDNeuralMap[i][j][k][l].Edis = 0;}
00273 if(FourDNeuralMap[i][j][k][l].Sdis < 0)
00274 {FourDNeuralMap[i][j][k][l].Sdis = 0;}
00275 if(FourDNeuralMap[i][j][k][l].Odis < 0)
00276 {FourDNeuralMap[i][j][k][l].Odis = 0;}
00277
00278
00279 Angle = FindRadToDeg(hold = FindAngleToRad(kk,ll));
00280
00281
00282
00283
00284
00285
00286 if(Angle >= 180)
00287 {
00288 AngleA = Angle - 180;
00289 }
00290 else
00291 {
00292 AngleA = Angle;
00293 }
00294
00295
00296
00297
00298 AngleAlpha = fabs(AngleA - NeuralAngles[i]);
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 AngleBeta = fabs(AngleA - NeuralAngles[j]);
00309
00310
00311
00312 FourDNeuralMap[i][j][k][l].coLinear = false;
00313 if((Angle <= (NeuralAngles[i]+90+coLinearCutOff))
00314 && (Angle >= (NeuralAngles[i]+90-coLinearCutOff)))
00315 {
00316 FourDNeuralMap[i][j][k][l].coLinear = true;
00317 }
00318 if((Angle <= (NeuralAngles[i]-90.0F+coLinearCutOff))
00319 && (Angle >= (NeuralAngles[i]-90.0F-coLinearCutOff)))
00320 {
00321 FourDNeuralMap[i][j][k][l].coLinear = true;
00322 }
00323 if((Angle <= (NeuralAngles[i]+270.0F+coLinearCutOff))
00324 && (Angle >= (NeuralAngles[i]+270.0F-coLinearCutOff)))
00325 {
00326 FourDNeuralMap[i][j][k][l].coLinear = true;
00327 }
00328
00329
00330
00331
00332 if((Angle <= (NeuralAngles[i]+1))
00333 || (Angle >= (NeuralAngles[i]+179)))
00334 {
00335 FourDNeuralMap[i][j][k][l].pol = true;
00336
00337
00338 if(((NeuralAngles[i] <= 90) &&
00339 ((Angle < NeuralAngles[i]+270)
00340 && (Angle >= NeuralAngles[i]+180)))
00341 || ((NeuralAngles[i] > 90) &&
00342 ((Angle >= NeuralAngles[i]+180) ||
00343 (Angle < NeuralAngles[i]-90))))
00344 {
00345 FourDNeuralMap[i][j][k][l].sender = true;
00346 }
00347
00348 else
00349 {
00350 FourDNeuralMap[i][j][k][l].sender = false;
00351 }
00352 }
00353
00354 else
00355 {
00356 FourDNeuralMap[i][j][k][l].pol = false;
00357
00358 if((Angle > NeuralAngles[i]+90)
00359 || (Angle >= (NeuralAngles[i]+270)))
00360
00361 {
00362 FourDNeuralMap[i][j][k][l].sender = false;
00363 }
00364
00365 else
00366 {
00367 FourDNeuralMap[i][j][k][l].sender = true;
00368 }
00369 }
00370
00371
00372
00373 AngleAlpha = AngleCenter - fabs(AngleAlpha - AngleCenter);
00374 AngleBeta = AngleCenter - fabs(AngleBeta - AngleCenter);
00375
00376 phi = fabs(NeuralAngles[i]-NeuralAngles[j]);
00377 theta = fabs(90-AngleAlpha);
00378 OT = 90-theta;
00379
00380
00381 stop = false;
00382 FourDNeuralMap[i][j][k][l].orth = false;
00383
00384
00385
00386
00387 if((OT < OrthA) && ((phi > (90-OrthB)) && (phi < (90+OrthB))))
00388 {
00389 FourDNeuralMap[i][j][k][l].ang2 = FindRatio(OrthA,OT) * OrthMult;
00390 FourDNeuralMap[i][j][k][l].angABD =
00391 FourDNeuralMap[i][j][k][l].ang2 *
00392 FourDNeuralMap[i][j][k][l].Odis;
00393 stop = true;
00394 FourDNeuralMap[i][j][k][l].zero = true;
00395 FourDNeuralMap[i][j][k][l].orth = true;
00396 }
00397 else
00398 {
00399 FourDNeuralMap[i][j][k][l].ang2 =
00400 FindRatio(FloatAngleCenter,AngleAlpha);
00401 FourDNeuralMap[i][j][k][l].ang3 =
00402 1-FourDNeuralMap[i][j][k][l].ang2;
00403
00404 FourDNeuralMap[i][j][k][l].ang2 =
00405 FindLinear(factor,linearFactor2e,linearFactor3e,
00406 FourDNeuralMap[i][j][k][l].ang2,one);
00407 }
00408
00409
00410 FourDNeuralMap[i][j][k][l].ang =
00411 FindRatio(FloatAngleCenter,AngleBeta);
00412
00413
00414
00415
00416 FourDNeuralMap[i][j][k][l].zero = false;
00417
00418
00419 if(FourDNeuralMap[i][j][k][l].ang2 < 0)
00420 {
00421
00422 FourDNeuralMap[i][j][k][l].ang2 =\
00423 -1*FindLinear(factor2,linearFactor2s,linearFactor3s,
00424 FourDNeuralMap[i][j][k][l].ang3,one);
00425 if(FourDNeuralMap[i][j][k][l].ang2 > 0)
00426 {
00427 FourDNeuralMap[i][j][k][l].ang2 = 0;
00428 }
00429 }
00430
00431 FourDNeuralMap[i][j][k][l].ang =\
00432 FindLinear(factor,linearFactor2e,linearFactor3e,
00433 FourDNeuralMap[i][j][k][l].ang,one);
00434
00435
00436
00437 if(FourDNeuralMap[i][j][k][l].ang2 < 0)
00438 {
00439 float diff;
00440 diff = fabs(NeuralAngles[i]-NeuralAngles[j]);
00441 if((diff < CoLinearDiff) || (diff > (180 - CoLinearDiff)))
00442 {
00443
00444 if(diff > (180 - CoLinearDiff))
00445 {
00446 diff = 180 - diff;
00447 }
00448 FourDNeuralMap[i][j][k][l].angAB =
00449 FourDNeuralMap[i][j][k][l].ang2 *
00450 FindRatio(CoLinearDiff,diff);
00451
00452
00453 if((FourDNeuralMap[i][j][k][l].Sdis > 0)
00454 && (distance >= NeuronSupStart))
00455 {
00456 FourDNeuralMap[i][j][k][l].angABD = SupMult*
00457 (((-1*FourDNeuralMap[i][j][k][l].Sdis)+
00458 FourDNeuralMap[i][j][k][l].angAB)/2);
00459 FourDNeuralMap[i][j][k][l].zero = true;
00460 }
00461 }
00462 }
00463
00464 else
00465 {
00466 if((FourDNeuralMap[i][j][k][l].ang > valueCutOff)
00467 && (stop == false))
00468 {
00469
00470 FourDNeuralMap[i][j][k][l].angAB = \
00471 (FourDNeuralMap[i][j][k][l].ang2*
00472 FourDNeuralMap[i][j][k][l].ang);
00473
00474 if((FourDNeuralMap[i][j][k][l].angAB > valueCutOff) && \
00475 (FourDNeuralMap[i][j][k][l].Edis > valueCutOff))
00476 {
00477 FourDNeuralMap[i][j][k][l].angABD = \
00478 ((FourDNeuralMap[i][j][k][l].angAB
00479 +FourDNeuralMap[i][j][k][l].Edis)/2);
00480 if(FourDNeuralMap[i][j][k][l].angABD > valueCutOff)
00481 {
00482
00483 FourDNeuralMap[i][j][k][l].zero = true;
00484 }
00485 }
00486 }
00487 }
00488 }
00489 }
00490 }
00491 }
00492 }
00493 printf("\n");
00494 }
00495
00496 template class ContourNeuronCreate<float>;
00497
00498
00499
00500
00501
00502