@@ -41,9 +41,12 @@ int spectral_predict(ard_t ard, small *mask_, int nc, int sid);
41
41
#define _SPECHOMO_N_DST_ 10 // number of destination bands
42
42
#define _SPECHOMO_N_COF_ 7 // number of coefficients
43
43
#define _SPECHOMO_N_SIM_ 10 // max. number of close clusters to be used for kNN
44
- #define _SPECHOMO_GOOD_SAM_ 0.0698132 // accept clusters that are closer than this angle
45
- #define _SPECHOMO_POOR_SAM_ 0.2617995 // used to compute a weight for each cluster
44
+ #define _SPECHOMO_GOOD_SAM_ 0.0698132 // good clusters are closer than this angle (4°)
45
+ #define _SPECHOMO_MEDI_SAM_ 0.2094395 // ok'ish clusters are closer than this angle (12°)
46
+ #define _SPECHOMO_POOR_SAM_ 0.2617995 // clusters further away from this angle (15°) should not be uses
47
+ // also used to compute a weight for each cluster
46
48
#define _SPECHOMO_MIN_WEIGHT_ 1.0 - _SPECHOMO_GOOD_SAM_/_SPECHOMO_POOR_SAM_
49
+ #define _SPECHOMO_MED_WEIGHT_ 1.0 - _SPECHOMO_MEDI_SAM_/_SPECHOMO_POOR_SAM_
47
50
48
51
const char _SPECHOMO_SENSOR_ [_SPECHOMO_N_SEN_ ][NPOW_04 ] = {
49
52
"LND04" , "LND05" , "LND07" , "LND08" , "MOD01" , "MOD02" };
@@ -736,7 +739,7 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
736
739
// weight for each cluster center
737
740
// not exactly as in the paper, pragmatic suggestion by D. Scheffler
738
741
if (sam > _SPECHOMO_POOR_SAM_ ){
739
- weight [s ] = 0.01 ;
742
+ weight [s ] = 0.00001 ;
740
743
} else {
741
744
weight [s ] = 1.0 - sam / _SPECHOMO_POOR_SAM_ ;
742
745
}
@@ -750,27 +753,26 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
750
753
printf ("lib: " );
751
754
for (b = 0 ; b < _SPECHOMO_N_SRC_ ; b ++ ) printf ("%05d " , _SPECHOMO_CENTER_ [sid ][b ][s ]);
752
755
printf ("\n" );
753
- printf ("xx: %.2f, yy: %.2f, xy: %.2f, sam: %.2f , weight: %.2f \n" , xx , yy , xy , sam , weight [s ]);
756
+ printf ("xx: %.2f, yy: %.2f, xy: %.2f, sam: %.5f , weight: %.5f \n" , xx , yy , xy , sam , weight [s ]);
754
757
#endif
755
758
756
759
// maximum weight of close clusters (-1 if no close cluster)
757
- if (weight [s ] >= _SPECHOMO_MIN_WEIGHT_ &&
758
- weight [s ] > max_weight &&
760
+ if (weight [s ] > max_weight &&
759
761
s != _SPECHOMO_N_SIM_ - 1 ){
760
762
761
- max_weight = weight [s ];
762
- max_cluster = s ;
763
+ max_weight = weight [s ];
764
+ max_cluster = s ;
763
765
764
766
}
765
767
766
768
#ifdef FORCE_DEBUG
767
- printf ("max_weight: %.2f , max_cluster: %02d\n" , max_weight , max_cluster );
769
+ printf ("max_weight: %.5f , max_cluster: %02d\n" , max_weight , max_cluster );
768
770
#endif
769
771
770
772
}
771
773
772
774
#ifdef FORCE_DEBUG
773
- print_dvector (weight , "all weights" , _SPECHOMO_N_CLS_ , 2 , 4 );
775
+ print_dvector (weight , "all weights" , _SPECHOMO_N_CLS_ , 2 , 5 );
774
776
#endif
775
777
776
778
@@ -779,29 +781,30 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
779
781
// find closest clusters, fill with global
780
782
for (c = 0 ; c < _SPECHOMO_N_SIM_ ; c ++ ){
781
783
782
- // if no more close cluster can be found, add global cluster, then stop
783
- if (max_weight < 0 ){
784
- cluster_select [c ] = _SPECHOMO_N_CLS_ - 1 ;
785
- weight_select [c ] = weight [cluster_select [c ]];
786
- break ;
787
- }
784
+ // init with global cluster
785
+ cluster_select [c ] = _SPECHOMO_N_CLS_ - 1 ;
786
+ weight_select [c ] = weight [_SPECHOMO_N_CLS_ - 1 ];
788
787
789
- // copy closest cluster
790
- cluster_select [c ] = max_cluster ;
791
- weight_select [c ] = weight [cluster_select [c ]];
788
+ if (max_weight > _SPECHOMO_MIN_WEIGHT_ ||
789
+ (max_weight > _SPECHOMO_MED_WEIGHT_ &&
790
+ max_weight > weight [_SPECHOMO_N_CLS_ - 1 ])){
791
+
792
+ // copy closest cluster
793
+ cluster_select [c ] = max_cluster ;
794
+ weight_select [c ] = max_weight ;
792
795
793
- // remove weight from closest cluster
794
- weight [cluster_select [c ]] = 0.0 ;
796
+ // remove weight from closest cluster
797
+ weight [max_cluster ] = 0.0 ;
798
+
799
+ } else break ;
795
800
796
801
// find the next closest cluster
797
802
max_weight = -1.0 ;
798
803
for (s = 0 ; s < (_SPECHOMO_N_CLS_ - 1 ); s ++ ){
799
- if (weight [s ] >= _SPECHOMO_MIN_WEIGHT_ &&
800
- weight [s ] > max_weight ){
804
+ if (weight [s ] > max_weight ){
801
805
max_weight = weight [s ];
802
806
max_cluster = s ;
803
807
}
804
-
805
808
}
806
809
807
810
}
@@ -811,8 +814,8 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
811
814
812
815
#ifdef FORCE_DEBUG
813
816
printf ("found %d clusters\n" , n_cluster );
814
- print_ivector (cluster_select , "cluster" , _SPECHOMO_N_SIM_ , 7 );
815
- print_dvector (weight_select , "weights" , _SPECHOMO_N_SIM_ , 2 , 4 );
817
+ print_ivector (cluster_select , "cluster" , _SPECHOMO_N_SIM_ , 8 );
818
+ print_dvector (weight_select , "weights" , _SPECHOMO_N_SIM_ , 2 , 5 );
816
819
#endif
817
820
818
821
// predict the target reflectance by using a weighted average of
0 commit comments