neuron_difKd_1cc_6.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_6.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(char LUT_PATH[])
  22. {
  23. FILE *fic;
  24. int i,j,poub;
  25. char *ligne=malloc(sizeof(char)*150), nomfic[500];
  26. float fpoub;
  27. sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_POIDS);
  28. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  29. fgets(ligne,150,fic);
  30. for(i=0; i<DNC1; i++)
  31. fscanf(fic,"%d %d %f",&poub,&poub,&dif_b1[i]);
  32. fscanf(fic,"%d %d %f",&poub,&poub,&dif_b2);
  33. for(j=0; j<DNE; j++){
  34. for(i=0; i<DNC1; i++)
  35. fscanf(fic,"%d %d %f",&poub,&poub,&dif_w1[j][i]);
  36. }
  37. for(j=0; j<DNC1; j++)
  38. fscanf(fic,"%d %d %f",&poub,&poub,&dif_w2[j]);
  39. fclose(fic);
  40. sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_MOY);
  41. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  42. fscanf(fic,"%f",&fpoub);
  43. for(i=0; i<DNE; i++)
  44. fscanf(fic,"%f",&dif_moy[i]);
  45. for(i=0; i<3; i++)
  46. fscanf(fic,"%f",&fpoub);
  47. fscanf(fic,"%f",&dif_moy[DNES-1]);
  48. fclose(fic);
  49. sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_ECART);
  50. if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
  51. fscanf(fic,"%f",&fpoub);
  52. for(i=0; i<DNE; i++)
  53. fscanf(fic,"%f",&dif_ecart[i]);
  54. for(i=0; i<3; i++)
  55. fscanf(fic,"%f",&fpoub);
  56. fscanf(fic,"%f",&dif_ecart[DNES-1]);
  57. fclose(fic);
  58. }
  59. /* -------------------------------------------------------------------------------
  60. Calcul du Kd a partir des poids - Kd computing from NN weights
  61. - Input:
  62. input[DNE] = Rrs[412 443 490 510 555], WaveLenght (for desired output Kd)
  63. ------------------------------------------------------------------------------- */
  64. float neuron_passe_avant_dif(float input[DNE])
  65. {
  66. float a[DNC1], y=0.0, x[DNE];
  67. int i,j;
  68. /* Normalisation */
  69. for(i=0; i<DNE; i++){
  70. x[i] = ((2./3.)*(input[i]-dif_moy[i]))/dif_ecart[i];
  71. }
  72. for(i=0;i<DNC1;i++){
  73. a[i] = 0.0;
  74. for(j=0;j<DNE;j++){
  75. a[i] += (x[j]*dif_w1[j][i]);
  76. }
  77. a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + dif_b1[i]));
  78. }
  79. for(j=0;j<DNC1;j++){
  80. y += (a[j] * dif_w2[j]);
  81. }
  82. /* Denormalisation */
  83. y = 1.5*(y + dif_b2)*dif_ecart[DNES-1] + dif_moy[DNES-1];
  84. y = (float)pow(10.,(double)y);
  85. return(y);
  86. }