neuron_kd_switch160715.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <errno.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <memory.h>
  7. #include "neuron_switch160715.h"
  8. #include "iop_Rrs_neuron.h"
  9. /* -------------------------------------------------------------------------------
  10. Lecture des differrentes Look Up Tables
  11. ------------------------------------------------------------------------------- */
  12. void neuron_lect_LUTswitch(int idSensor, char *lutpath)
  13. {
  14. FILE *fic;
  15. int i,j,poub;
  16. char *ligne=malloc(sizeof(char)*150), nomfic[1000];
  17. float fpoub;
  18. if( (poub = strcmp(lutpath, "None")) == 0){
  19. if( (lutpath = getenv("IOP_LUTS_PATH")) == NULL) {perror("IOP_LUTS_PATH"); exit(-1);}
  20. }
  21. /* ===================================== SeaWiFS ===================================== */
  22. if( idSensor == idSEAWIFS ){
  23. /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
  24. sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_POIDS);
  25. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  26. fgets(ligne,150,fic);
  27. for(i=0; i<rsupSW_NC1; i++)
  28. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b1[i]);
  29. for(i=0; i<rsupSW_NC2; i++)
  30. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b2[i]);
  31. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b3);
  32. for(j=0; j<rsupSW_NE; j++){
  33. for(i=0; i<rsupSW_NC1; i++)
  34. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w1[j][i]);
  35. }
  36. for(j=0; j<rsupSW_NC1; j++){
  37. for(i=0; i<rsupSW_NC2; i++)
  38. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w2[j][i]);
  39. }
  40. for(i=0; i<rsupSW_NC2; i++)
  41. fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w3[i]);
  42. fclose(fic);
  43. sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_MOY);
  44. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  45. fscanf(fic,"%f",&fpoub);
  46. for(i=0; i<rsupSW_NE-1; i++)
  47. fscanf(fic,"%f",&rsupSW_moy[i]);
  48. fscanf(fic,"%f",&fpoub);
  49. fscanf(fic,"%f",&rsupSW_moy[rsupSW_NE-1]);
  50. fscanf(fic,"%f",&fpoub);
  51. fscanf(fic,"%f",&rsupSW_moy[rsupSW_NES-1]);
  52. fclose(fic);
  53. sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_ECART);
  54. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  55. fscanf(fic,"%f",&fpoub);
  56. for(i=0; i<rsupSW_NE-1; i++)
  57. fscanf(fic,"%f",&rsupSW_ecart[i]);
  58. fscanf(fic,"%f",&fpoub);
  59. fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NE-1]);
  60. fscanf(fic,"%f",&fpoub);
  61. fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NES-1]);
  62. fclose(fic);
  63. /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
  64. sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_POIDS);
  65. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  66. fgets(ligne,150,fic);
  67. for(i=0; i<rinfSW_NC1; i++)
  68. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b1[i]);
  69. for(i=0; i<rinfSW_NC2; i++)
  70. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b2[i]);
  71. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b3);
  72. for(j=0; j<rinfSW_NE; j++){
  73. for(i=0; i<rinfSW_NC1; i++)
  74. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w1[j][i]);
  75. }
  76. for(j=0; j<rinfSW_NC1; j++){
  77. for(i=0; i<rinfSW_NC2; i++)
  78. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w2[j][i]);
  79. }
  80. for(i=0; i<rinfSW_NC2; i++)
  81. fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w3[i]);
  82. fclose(fic);
  83. sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_MOY);
  84. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  85. fscanf(fic,"%f",&fpoub);
  86. for(i=0; i<rinfSW_NE; i++)
  87. fscanf(fic,"%f",&rinfSW_moy[i]);
  88. fscanf(fic,"%f",&fpoub);
  89. fscanf(fic,"%f",&rinfSW_moy[rinfSW_NES-1]);
  90. fclose(fic);
  91. sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_ECART);
  92. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  93. fscanf(fic,"%f",&fpoub);
  94. for(i=0; i<rinfSW_NE; i++)
  95. fscanf(fic,"%f",&rinfSW_ecart[i]);
  96. fscanf(fic,"%f",&fpoub);
  97. fscanf(fic,"%f",&rinfSW_ecart[rinfSW_NES-1]);
  98. fclose(fic);
  99. }
  100. /* ===================================== MODIS ===================================== */
  101. if( idSensor == idMODIS){
  102. /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
  103. sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_POIDS);
  104. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  105. fgets(ligne,150,fic);
  106. for(i=0; i<rsupMO_NC1; i++)
  107. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b1[i]);
  108. for(i=0; i<rsupMO_NC2; i++)
  109. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b2[i]);
  110. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b3);
  111. for(j=0; j<rsupMO_NE; j++){
  112. for(i=0; i<rsupMO_NC1; i++)
  113. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w1[j][i]);
  114. }
  115. for(j=0; j<rsupMO_NC1; j++){
  116. for(i=0; i<rsupMO_NC2; i++)
  117. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w2[j][i]);
  118. }
  119. for(i=0; i<rsupMO_NC2; i++)
  120. fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w3[i]);
  121. fclose(fic);
  122. sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_MOY);
  123. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  124. fscanf(fic,"%f",&fpoub);/*412*/
  125. fscanf(fic,"%f",&rsupMO_moy[0]); /*443*/
  126. fscanf(fic,"%f",&rsupMO_moy[1]); /*488*/
  127. fscanf(fic,"%f",&rsupMO_moy[2]); /*531*/
  128. fscanf(fic,"%f",&rsupMO_moy[3]); /*547*/
  129. fscanf(fic,"%f",&fpoub); /*620*/
  130. fscanf(fic,"%f",&fpoub); /*667*/
  131. fscanf(fic,"%f",&rsupMO_moy[rsupMO_NE-1]);
  132. fscanf(fic,"%f",&fpoub);
  133. fscanf(fic,"%f",&rsupMO_moy[rsupMO_NES-1]);
  134. fclose(fic);
  135. sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_ECART);
  136. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  137. fscanf(fic,"%f",&fpoub);
  138. fscanf(fic,"%f",&rsupMO_ecart[0]); /*443*/
  139. fscanf(fic,"%f",&rsupMO_ecart[1]); /*488*/
  140. fscanf(fic,"%f",&rsupMO_ecart[2]); /*531*/
  141. fscanf(fic,"%f",&rsupMO_ecart[3]); /*547*/
  142. fscanf(fic,"%f",&fpoub); /*620*/
  143. fscanf(fic,"%f",&fpoub); /*667*/
  144. fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NE-1]);
  145. fscanf(fic,"%f",&fpoub);
  146. fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NES-1]);
  147. fclose(fic);
  148. /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
  149. sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_POIDS);
  150. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  151. fgets(ligne,150,fic);
  152. for(i=0; i<rinfMO_NC1; i++)
  153. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b1[i]);
  154. for(i=0; i<rinfMO_NC2; i++)
  155. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b2[i]);
  156. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b3);
  157. for(j=0; j<rinfMO_NE; j++){
  158. for(i=0; i<rinfMO_NC1; i++)
  159. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w1[j][i]);
  160. }
  161. for(j=0; j<rinfMO_NC1; j++){
  162. for(i=0; i<rinfMO_NC2; i++)
  163. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w2[j][i]);
  164. }
  165. for(i=0; i<rinfMO_NC2; i++)
  166. fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w3[i]);
  167. fclose(fic);
  168. sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_MOY);
  169. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  170. fscanf(fic,"%f",&fpoub);/*412*/
  171. fscanf(fic,"%f",&rinfMO_moy[0]); /*443*/
  172. fscanf(fic,"%f",&rinfMO_moy[1]); /*488*/
  173. fscanf(fic,"%f",&rinfMO_moy[2]); /*531*/
  174. fscanf(fic,"%f",&rinfMO_moy[3]); /*547*/
  175. fscanf(fic,"%f",&fpoub); /*620*/
  176. fscanf(fic,"%f",&rinfMO_moy[4]); /*667*/
  177. fscanf(fic,"%f",&rinfMO_moy[rinfMO_NE-1]);
  178. fscanf(fic,"%f",&fpoub);
  179. fscanf(fic,"%f",&rinfMO_moy[rinfMO_NES-1]);
  180. fclose(fic);
  181. sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_ECART);
  182. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  183. fscanf(fic,"%f",&fpoub);
  184. fscanf(fic,"%f",&rinfMO_ecart[0]); /*443*/
  185. fscanf(fic,"%f",&rinfMO_ecart[1]); /*488*/
  186. fscanf(fic,"%f",&rinfMO_ecart[2]); /*531*/
  187. fscanf(fic,"%f",&rinfMO_ecart[3]); /*547*/
  188. fscanf(fic,"%f",&fpoub); /*620*/
  189. fscanf(fic,"%f",&rinfMO_ecart[4]); /*667*/
  190. fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NE-1]);
  191. fscanf(fic,"%f",&fpoub);
  192. fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NES-1]);
  193. fclose(fic);
  194. }
  195. /* ===================================== MERIS / OLCI ===================================== */
  196. if( idSensor == idMERIS){
  197. /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
  198. sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_POIDS);
  199. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  200. fgets(ligne,150,fic);
  201. for(i=0; i<rsupOL_NC1; i++)
  202. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b1[i]);
  203. for(i=0; i<rsupOL_NC2; i++)
  204. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b2[i]);
  205. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b3);
  206. for(j=0; j<rsupOL_NE; j++){
  207. for(i=0; i<rsupOL_NC1; i++)
  208. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w1[j][i]);
  209. }
  210. for(j=0; j<rsupOL_NC1; j++){
  211. for(i=0; i<rsupOL_NC2; i++)
  212. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w2[j][i]);
  213. }
  214. for(i=0; i<rsupOL_NC2; i++)
  215. fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w3[i]);
  216. fclose(fic);
  217. sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_MOY);
  218. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  219. fscanf(fic,"%f",&fpoub);/*412*/
  220. fscanf(fic,"%f",&rsupOL_moy[0]); /*443*/
  221. fscanf(fic,"%f",&rsupOL_moy[1]); /*490*/
  222. fscanf(fic,"%f",&rsupOL_moy[2]); /*510*/
  223. fscanf(fic,"%f",&rsupOL_moy[3]); /*560*/
  224. fscanf(fic,"%f",&fpoub); /*665*/
  225. fscanf(fic,"%f",&rsupOL_moy[rsupOL_NE-1]);
  226. fscanf(fic,"%f",&fpoub);
  227. fscanf(fic,"%f",&rsupOL_moy[rsupOL_NES-1]);
  228. fclose(fic);
  229. sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_ECART);
  230. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  231. fscanf(fic,"%f",&fpoub);
  232. fscanf(fic,"%f",&rsupOL_ecart[0]); /*443*/
  233. fscanf(fic,"%f",&rsupOL_ecart[1]); /*488*/
  234. fscanf(fic,"%f",&rsupOL_ecart[2]); /*510*/
  235. fscanf(fic,"%f",&rsupOL_ecart[3]); /*560*/
  236. fscanf(fic,"%f",&fpoub); /*665*/
  237. fscanf(fic,"%f",&rsupOL_ecart[rsupOL_NE-1]);
  238. fscanf(fic,"%f",&fpoub);
  239. fscanf(fic,"%f",&rsupOL_ecart[rsupOL_NES-1]);
  240. fclose(fic);
  241. /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
  242. sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_POIDS);
  243. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  244. fgets(ligne,150,fic);
  245. for(i=0; i<rinfOL_NC1; i++)
  246. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b1[i]);
  247. for(i=0; i<rinfOL_NC2; i++)
  248. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b2[i]);
  249. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b3);
  250. for(j=0; j<rinfOL_NE; j++){
  251. for(i=0; i<rinfOL_NC1; i++)
  252. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w1[j][i]);
  253. }
  254. for(j=0; j<rinfOL_NC1; j++){
  255. for(i=0; i<rinfOL_NC2; i++)
  256. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w2[j][i]);
  257. }
  258. for(i=0; i<rinfOL_NC2; i++)
  259. fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w3[i]);
  260. fclose(fic);
  261. sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_MOY);
  262. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  263. fscanf(fic,"%f",&fpoub);/*412*/
  264. fscanf(fic,"%f",&rinfOL_moy[0]); /*443*/
  265. fscanf(fic,"%f",&rinfOL_moy[1]); /*490*/
  266. fscanf(fic,"%f",&rinfOL_moy[2]); /*510*/
  267. fscanf(fic,"%f",&rinfOL_moy[3]); /*560*/
  268. fscanf(fic,"%f",&rinfOL_moy[4]); /*665*/
  269. fscanf(fic,"%f",&rinfOL_moy[rinfOL_NE-1]);
  270. fscanf(fic,"%f",&fpoub);
  271. fscanf(fic,"%f",&rinfOL_moy[rinfOL_NES-1]);
  272. fclose(fic);
  273. sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_ECART);
  274. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  275. fscanf(fic,"%f",&fpoub); /*412*/
  276. fscanf(fic,"%f",&rinfOL_ecart[0]); /*443*/
  277. fscanf(fic,"%f",&rinfOL_ecart[1]); /*490*/
  278. fscanf(fic,"%f",&rinfOL_ecart[2]); /*510*/
  279. fscanf(fic,"%f",&rinfOL_ecart[3]); /*560*/
  280. fscanf(fic,"%f",&rinfOL_ecart[4]); /*665*/
  281. fscanf(fic,"%f",&rinfOL_ecart[rinfOL_NE-1]);
  282. fscanf(fic,"%f",&fpoub);
  283. fscanf(fic,"%f",&rinfOL_ecart[rinfOL_NES-1]);
  284. fclose(fic);
  285. }
  286. }
  287. /* =============================================== SEAWIFS =============================================== */
  288. /* -------------------------------------------------------------------------------
  289. Calcul du Kd a partir des poids
  290. - Input:
  291. input[NE] = Rrs 443 490 510 555 Lambda
  292. ------------------------------------------------------------------------------- */
  293. float rsupSW_neuron_passe_avant(float input[rsupSW_NE+1])
  294. {
  295. float a[rsupSW_NC1], b[rsupSW_NC2], y=0.0, x[rsupSW_NE];
  296. int i,j;
  297. /* Normalisation */
  298. for(i=0; i<rsupSW_NE; i++){
  299. x[i] = ((2./3.)*(input[i]-rsupSW_moy[i]))/rsupSW_ecart[i];
  300. }
  301. for(i=0;i<rsupSW_NC1;i++){
  302. a[i] = 0.0;
  303. for(j=0;j<rsupSW_NE;j++){
  304. a[i] += (x[j]*rsupSW_w1[j][i]);
  305. }
  306. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupSW_b1[i]));
  307. }
  308. for(i=0;i<rsupSW_NC2;i++){
  309. b[i] = 0.0;
  310. for(j=0;j<rsupSW_NC1;j++){
  311. b[i] += (a[j]*rsupSW_w2[j][i]);
  312. }
  313. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupSW_b2[i]));
  314. }
  315. for(j=0;j<rsupSW_NC2;j++){
  316. y += (b[j]*rsupSW_w3[j]);
  317. }
  318. /* Denormalisation */
  319. y = 1.5*(y + rsupSW_b3)*rsupSW_ecart[rsupSW_NES-1] + rsupSW_moy[rsupSW_NES-1];
  320. y = (float)pow(10.,y);
  321. return(y);
  322. }
  323. /* -------------------------------------------------------------------------------
  324. Calcul du Kd a partir des poids
  325. - Input:
  326. input[NE] = Rrs 443 490 510 555 670 Lambda
  327. ------------------------------------------------------------------------------- */
  328. float rinfSW_neuron_passe_avant(float input[rinfSW_NE])
  329. {
  330. float a[rinfSW_NC1], b[rinfSW_NC2], y=0.0, x[rinfSW_NE];
  331. int i,j;
  332. /* Normalisation */
  333. for(i=0; i<rinfSW_NE; i++){
  334. x[i] = ((2./3.)*(input[i]-rinfSW_moy[i]))/rinfSW_ecart[i];
  335. }
  336. for(i=0;i<rinfSW_NC1;i++){
  337. a[i] = 0.0;
  338. for(j=0;j<rinfSW_NE;j++){
  339. a[i] += (x[j]*rinfSW_w1[j][i]);
  340. }
  341. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfSW_b1[i]));
  342. }
  343. for(i=0;i<rinfSW_NC2;i++){
  344. b[i] = 0.0;
  345. for(j=0;j<rinfSW_NC1;j++){
  346. b[i] += (a[j]*rinfSW_w2[j][i]);
  347. }
  348. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfSW_b2[i]));
  349. }
  350. for(j=0;j<rinfSW_NC2;j++){
  351. y += (b[j]*rinfSW_w3[j]);
  352. }
  353. /* Denormalisation */
  354. y = 1.5*(y + rinfSW_b3)*rinfSW_ecart[rinfSW_NES-1] + rinfSW_moy[rinfSW_NES-1];
  355. y = (float)pow(10.,y);
  356. return(y);
  357. }
  358. /* =============================================== MODIS ================================================ */
  359. /* -------------------------------------------------------------------------------
  360. Calcul du Kd a partir des poids
  361. - Input:
  362. input[NE] = Rrs 443 490 510 555 Lambda
  363. ------------------------------------------------------------------------------- */
  364. float rsupMO_neuron_passe_avant(float input[rsupMO_NE+1])
  365. {
  366. float a[rsupMO_NC1], b[rsupMO_NC2], y=0.0, x[rsupMO_NE];
  367. int i,j;
  368. /* Normalisation */
  369. for(i=0; i<rsupMO_NE; i++){
  370. x[i] = ((2./3.)*(input[i]-rsupMO_moy[i]))/rsupMO_ecart[i];
  371. }
  372. for(i=0;i<rsupMO_NC1;i++){
  373. a[i] = 0.0;
  374. for(j=0;j<rsupMO_NE;j++){
  375. a[i] += (x[j]*rsupMO_w1[j][i]);
  376. }
  377. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupMO_b1[i]));
  378. }
  379. for(i=0;i<rsupMO_NC2;i++){
  380. b[i] = 0.0;
  381. for(j=0;j<rsupMO_NC1;j++){
  382. b[i] += (a[j]*rsupMO_w2[j][i]);
  383. }
  384. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupMO_b2[i]));
  385. }
  386. for(j=0;j<rsupMO_NC2;j++){
  387. y += (b[j]*rsupMO_w3[j]);
  388. }
  389. /* Denormalisation */
  390. y = 1.5*(y + rsupMO_b3)*rsupMO_ecart[rsupMO_NES-1] + rsupMO_moy[rsupMO_NES-1];
  391. y = (float)pow(10.,y);
  392. return(y);
  393. }
  394. /* -------------------------------------------------------------------------------
  395. Calcul du Kd a partir des poids
  396. - Input:
  397. input[NE] = Rrs 443 490 510 555 670 Lambda
  398. ------------------------------------------------------------------------------- */
  399. float rinfMO_neuron_passe_avant(float input[rinfMO_NE])
  400. {
  401. float a[rinfMO_NC1], b[rinfMO_NC2], y=0.0, x[rinfMO_NE];
  402. int i,j;
  403. /* Normalisation */
  404. for(i=0; i<rinfMO_NE; i++){
  405. x[i] = ((2./3.)*(input[i]-rinfMO_moy[i]))/rinfMO_ecart[i];
  406. }
  407. for(i=0;i<rinfMO_NC1;i++){
  408. a[i] = 0.0;
  409. for(j=0;j<rinfMO_NE;j++){
  410. a[i] += (x[j]*rinfMO_w1[j][i]);
  411. }
  412. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfMO_b1[i]));
  413. }
  414. for(i=0;i<rinfMO_NC2;i++){
  415. b[i] = 0.0;
  416. for(j=0;j<rinfMO_NC1;j++){
  417. b[i] += (a[j]*rinfMO_w2[j][i]);
  418. }
  419. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfMO_b2[i]));
  420. }
  421. for(j=0;j<rinfMO_NC2;j++){
  422. y += (b[j]*rinfMO_w3[j]);
  423. }
  424. /* Denormalisation */
  425. y = 1.5*(y + rinfMO_b3)*rinfMO_ecart[rinfMO_NES-1] + rinfMO_moy[rinfMO_NES-1];
  426. y = (float)pow(10.,y);
  427. return(y);
  428. }
  429. /* =============================================== MERIS /OLCI ================================================ */
  430. /* -------------------------------------------------------------------------------
  431. Calcul du Kd a partir des poids
  432. - Input:
  433. input[NE] = Rrs 443 490 510 560 Lambda
  434. ------------------------------------------------------------------------------- */
  435. float rsupOL_neuron_passe_avant(float input[rsupOL_NE+1])
  436. {
  437. float a[rsupOL_NC1], b[rsupOL_NC2], y=0.0, x[rsupOL_NE];
  438. int i,j;
  439. /* Normalisation */
  440. for(i=0; i<rsupOL_NE; i++){
  441. x[i] = ((2./3.)*(input[i]-rsupOL_moy[i]))/rsupOL_ecart[i];
  442. }
  443. for(i=0;i<rsupOL_NC1;i++){
  444. a[i] = 0.0;
  445. for(j=0;j<rsupOL_NE;j++){
  446. a[i] += (x[j]*rsupOL_w1[j][i]);
  447. }
  448. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupOL_b1[i]));
  449. }
  450. for(i=0;i<rsupOL_NC2;i++){
  451. b[i] = 0.0;
  452. for(j=0;j<rsupOL_NC1;j++){
  453. b[i] += (a[j]*rsupOL_w2[j][i]);
  454. }
  455. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupOL_b2[i]));
  456. }
  457. for(j=0;j<rsupOL_NC2;j++){
  458. y += (b[j]*rsupOL_w3[j]);
  459. }
  460. /* Denormalisation */
  461. y = 1.5*(y + rsupOL_b3)*rsupOL_ecart[rsupOL_NES-1] + rsupOL_moy[rsupOL_NES-1];
  462. y = (float)pow(10.,y);
  463. return(y);
  464. }
  465. /* -------------------------------------------------------------------------------
  466. Calcul du Kd a partir des poids
  467. - Input:
  468. input[NE] = Rrs 443 490 510 560 665 Lambda
  469. ------------------------------------------------------------------------------- */
  470. float rinfOL_neuron_passe_avant(float input[rinfOL_NE])
  471. {
  472. float a[rinfOL_NC1], b[rinfOL_NC2], y=0.0, x[rinfOL_NE];
  473. int i,j;
  474. /* Normalisation */
  475. for(i=0; i<rinfOL_NE; i++){
  476. x[i] = ((2./3.)*(input[i]-rinfOL_moy[i]))/rinfOL_ecart[i];
  477. }
  478. for(i=0;i<rinfOL_NC1;i++){
  479. a[i] = 0.0;
  480. for(j=0;j<rinfOL_NE;j++){
  481. a[i] += (x[j]*rinfOL_w1[j][i]);
  482. }
  483. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfOL_b1[i]));
  484. }
  485. for(i=0;i<rinfOL_NC2;i++){
  486. b[i] = 0.0;
  487. for(j=0;j<rinfOL_NC1;j++){
  488. b[i] += (a[j]*rinfOL_w2[j][i]);
  489. }
  490. b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfOL_b2[i]));
  491. }
  492. for(j=0;j<rinfOL_NC2;j++){
  493. y += (b[j]*rinfOL_w3[j]);
  494. }
  495. /* Denormalisation */
  496. y = 1.5*(y + rinfOL_b3)*rinfOL_ecart[rinfOL_NES-1] + rinfOL_moy[rinfOL_NES-1];
  497. y = (float)pow(10.,y);
  498. return(y);
  499. }
  500. /*
  501. int main (int argc, char *argv[])
  502. {
  503. FILE *fic;
  504. float data_in[rinfSW_NE],result_in,result_out, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0., fpoub;
  505. int i,nbinf, nbsup, nb,lu;
  506. // if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
  507. if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_sup_180515_test.dat","r")) == NULL) {perror("input"); exit(-1);}
  508. neuron_lect_LUTswitch(0, "None");
  509. nb = nbsup = nbinf = 0;
  510. while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
  511. for(i=1; i<rinfSW_NE; i++)
  512. fscanf(fic,"%f",&data_in[i]);
  513. fscanf(fic,"%f",&fpoub);
  514. fscanf(fic,"%f",&result_in);
  515. result_in = (float)pow(10.,result_in);
  516. printf("%f ",result_in);
  517. if(data_in[1]/data_in[3] < .85){
  518. result_out = rinfSW_neuron_passe_avant(data_in);
  519. sumInf_rms += (float)pow((double)(result_in-result_out),2.);
  520. sumInf_rel += (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
  521. nbinf++;
  522. }
  523. else {
  524. data_in[5] = data_in[6];
  525. result_out = rsupSW_neuron_passe_avant(data_in);
  526. sumSup_rms += (float)pow((double)(result_in-result_out),2.);
  527. sumSup_rel += (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
  528. nbsup++;
  529. }
  530. printf(" %f\n",result_out);
  531. nb++;
  532. }
  533. printf("rmseInf = %f, rel errInf= %f, rmseSup = %f, rel errSup= %f nbinf = %d nbsup = %d\n",(float)sqrt((double)sumInf_rms/nbinf),sumInf_rel/nbinf, (float)sqrt((double)sumSup_rms/nbsup),sumSup_rel/nbsup, nbinf, nbsup);
  534. fclose(fic);
  535. exit(1);
  536. }
  537. */
  538. /*int main (int argc, char *argv[])
  539. {
  540. FILE *fic;
  541. float fpoub, data_in[rinfSW_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
  542. int i,nb,lu;
  543. printf(" -- SUP --\n");
  544. if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_sup_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
  545. neuron_lect_LUTswitch(idMODIS);
  546. nb = 0;
  547. while((lu=fscanf(fic,"%f",&fpoub)) == 1){
  548. for(i=0; i<4; i++)
  549. fscanf(fic,"%f",&data_in[i]);
  550. fscanf(fic,"%f",&fpoub);
  551. fscanf(fic,"%f",&fpoub);
  552. fscanf(fic,"%f",&data_in[4]);
  553. fscanf(fic,"%f",&fpoub);
  554. fscanf(fic,"%f",&result_in);
  555. result_out = rsupMO_neuron_passe_avant(data_in);
  556. result_in = (float)pow(10.,result_in);
  557. if (data_in[4] == 488 ){
  558. sumSup_rms += (float)pow((double)(result_in-result_out),2.);
  559. sumSup_rel += (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
  560. nb++;
  561. }
  562. }
  563. printf("rmseSup = %f, rel errSup= %f nb = %d\n",(float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
  564. fclose(fic);
  565. printf(" -- INF --\n");
  566. if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_inf_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
  567. nb = 0;
  568. while((lu=fscanf(fic,"%f",&fpoub)) == 1){
  569. for(i=0; i<4; i++)
  570. fscanf(fic,"%f",&data_in[i]);
  571. fscanf(fic,"%f",&fpoub);
  572. fscanf(fic,"%f",&data_in[4]);
  573. fscanf(fic,"%f",&data_in[5]);
  574. fscanf(fic,"%f",&fpoub);
  575. fscanf(fic,"%f",&result_in);
  576. result_out = rinfMO_neuron_passe_avant(data_in);
  577. result_in = (float)pow(10.,result_in);
  578. if (data_in[5] == 488 ){
  579. sumInf_rms += (float)pow((double)(result_in-result_out),2.);
  580. sumInf_rel += (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
  581. nb++;
  582. }
  583. }
  584. printf("rmseInf = %f, rel errInf= %f nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, nb);
  585. exit(1);
  586. }*/