neuron_difKd_1cc_26.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Kd estimation references :
  3. Jamet, C., H. Loisel, and D. Dessailly (2012), Retrieval of the spectral diffuse attenuation coefficient Kd(l) in open and coastal ocean waters using a neural network inversion, J. Geophys. Res., 117, C10023, doi:10.1029/2012JC008076.
  4. Jamet, C., H., Loisel and D., Dessailly, 2010. Estimation of the diffuse attenuation coefficient Kd(lambda) with a neural network, Proceedings of IGARSS '11
  5. Jamet, C., H., Loisel and D., Dessailly, 2010. Empirical nonlinear determination of the diffuse attenuation coefficient Kd(490) in coastal waters from ocean color image, Proceedings of SPIE-Asia-Pacific Remote Sensing, DOI: 10.1117/12.869730
  6. C coding version :
  7. 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
  8. Laboratoire d'Oceanoligie et Geoscience (LOG)
  9. */
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include <errno.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <memory.h>
  16. #include "neuron_difKd1cc_26.h"
  17. /* -------------------------------------------------------------------------------
  18. Lecture des differentes Look Up Tables - LUTs reading
  19. - Files names and path define in neuron1cc.h
  20. ------------------------------------------------------------------------------- */
  21. void neuron_lect_LUTs_dif()
  22. {
  23. FILE *fic;
  24. int i,j,poub;
  25. char *ligne=malloc(sizeof(char)*150);
  26. float fpoub;
  27. if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
  28. fgets(ligne,150,fic);
  29. for(i=0; i<DNC1; i++)
  30. fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
  31. fscanf(fic,"%d %d %f",&poub,&poub,&b2);
  32. for(j=0; j<DNE; j++){
  33. for(i=0; i<DNC1; i++)
  34. fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
  35. }
  36. for(j=0; j<DNC1; j++)
  37. fscanf(fic,"%d %d %f",&poub,&poub,&w2[j]);
  38. fclose(fic);
  39. if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
  40. fscanf(fic,"%f",&fpoub);
  41. for(i=0; i<DNE; i++)
  42. fscanf(fic,"%f",&moy[i]);
  43. for(i=0; i<3; i++)
  44. fscanf(fic,"%f",&fpoub);
  45. fscanf(fic,"%f",&moy[DNES-1]);
  46. fclose(fic);
  47. if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
  48. fscanf(fic,"%f",&fpoub);
  49. for(i=0; i<DNE; i++)
  50. fscanf(fic,"%f",&ecart[i]);
  51. for(i=0; i<3; i++)
  52. fscanf(fic,"%f",&fpoub);
  53. fscanf(fic,"%f",&ecart[DNES-1]);
  54. fclose(fic);
  55. }
  56. /* -------------------------------------------------------------------------------
  57. Calcul du Kd a partir des poids - Kd computing from NN weights
  58. - Input:
  59. input[DNE] = Rrs[412 443 490 510 555 670], WaveLenght (for desired output Kd)
  60. ------------------------------------------------------------------------------- */
  61. float neuron_passe_avant_dif(float input[DNE])
  62. {
  63. float a[DNC1], y=0.0, x[DNE];
  64. int i,j;
  65. /* Normalisation */
  66. for(i=0; i<DNE; i++){
  67. x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
  68. }
  69. for(i=0;i<DNC1;i++){
  70. a[i] = 0.0;
  71. for(j=0;j<DNE;j++){
  72. a[i] += (x[j]*w1[j][i]);
  73. }
  74. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
  75. }
  76. for(j=0;j<DNC1;j++){
  77. y += (a[j] * w2[j]);
  78. }
  79. /* Denormalisation */
  80. y = 1.5*(y + b2)*ecart[DNES-1] + moy[DNES-1];
  81. y = (float)pow(10.,(double)y);
  82. return(y);
  83. }