 |
SAGA API
v9.9
|
Go to the documentation of this file.
53 #ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H
54 #define HEADER_INCLUDED__SAGA_API__mat_tools_H
96 #define M_PI 3.141592653589793
99 #define M_PI_045 (M_PI / 4.)
100 #define M_PI_090 (M_PI / 2.)
101 #define M_PI_135 (M_PI * 3. / 4.)
102 #define M_PI_180 (M_PI)
103 #define M_PI_225 (M_PI * 5. / 4.)
104 #define M_PI_270 (M_PI * 3. / 2.)
105 #define M_PI_315 (M_PI * 7. / 4.)
106 #define M_PI_360 (M_PI * 2.)
108 #define M_RAD_TO_DEG (180. / M_PI)
109 #define M_DEG_TO_RAD (M_PI / 180.)
112 #define M_EULER 2.718281828459045
115 #define N_MEGABYTE_BYTES 0x100000
119 #define M_FLT_EPSILON FLT_EPSILON
121 #define M_FLT_EPSILON 1.192092896e-07F
125 #define M_DBL_EPSILON DBL_EPSILON
127 #define M_DBL_EPSILON 2.2204460492503131e-016
131 #define M_ALMOST_ZERO (1.e-03)
132 #define M_TINY (1.e-20)
137 #define M_SQR(x) ((x) * (x))
138 #define M_SQRT(x) sqrt((double)(x))
139 #define M_GET_LENGTH(x, y) sqrt((double)((x)*(x) + (y)*(y)))
141 #define M_GET_MIN(a, b) (((a) < (b)) ? (a) : (b))
142 #define M_GET_MAX(a, b) (((a) > (b)) ? (a) : (b))
143 #define M_SET_MINMAX(min, max, x) if( min > x ) { min = x; } else if( max < x ) { max = x; }
145 #define M_SET_SIGN(x, sign) ((sign) < 0 ? (x < 0 ? x : -x) : (x > 0 ? x : -x))
147 #define M_HAS_DECIMALS(x) (x - floor(x) > 0.)
150 #define SG_ROUND_TO_BYTE(x) ((BYTE )(x < 0. ? x - 0.5 : x + 0.5))
151 #define SG_ROUND_TO_CHAR(x) ((char )(x < 0. ? x - 0.5 : x + 0.5))
152 #define SG_ROUND_TO_WORD(x) ((WORD )(x < 0. ? x - 0.5 : x + 0.5))
153 #define SG_ROUND_TO_SHORT(x) ((short)(x < 0. ? x - 0.5 : x + 0.5))
154 #define SG_ROUND_TO_DWORD(x) ((DWORD)(x < 0. ? x - 0.5 : x + 0.5))
155 #define SG_ROUND_TO_INT(x) ((int )(x < 0. ? x - 0.5 : x + 0.5))
156 #define SG_ROUND_TO_LONG(x) ((long )(x < 0. ? x - 0.5 : x + 0.5))
157 #define SG_ROUND_TO_ULONG(x) ((uLong)(x < 0. ? x - 0.5 : x + 0.5))
158 #define SG_ROUND_TO_SLONG(x) ((sLong)(x < 0. ? x - 0.5 : x + 0.5))
223 bool Create (
sLong nValues,
int *Values,
bool bAscending =
true);
225 CSG_Index (
sLong nValues,
double *Values,
bool bAscending =
true);
226 bool Create (
sLong nValues,
double *Values,
bool bAscending =
true);
235 void Show_Progress (
bool bProgress =
true);
237 bool Add_Entry (
sLong Position = -1);
238 bool Del_Entry (
sLong Position = -1);
240 bool is_Okay (
void)
const {
return( m_nValues > 0 ); }
245 return( Position < 0 || Position >= m_nValues ? -1 : m_Index[Ascending ? Position : m_nValues - 1 - Position] );
250 return( Position < 0 || Position >= m_nValues ? -1 : m_Index[Position] );
258 sLong m_nValues, *m_Index;
261 void _On_Construction (
void);
263 bool _Set_Array (
sLong nValues);
264 bool _Set_Index (CSG_Index_Compare *pCompare);
295 void Create (
size_t maxSize = 256);
299 bool is_Empty (
void)
const {
return( m_nItems == 0 ); }
300 size_t Get_Size (
void)
const {
return( m_nItems ); }
303 void Add (CSG_PriorityQueueItem *pItem);
306 CSG_PriorityQueueItem * Poll (
void);
315 return( m_pLeaf[0]->Minimum() );
318 return( m_Items[0] );
330 return( m_pLeaf[1]->Maximum() );
333 return( m_Items[m_nItems - 1] );
342 size_t m_nItems, m_maxSize;
346 CSG_PriorityQueueItem **m_Items;
349 size_t _Insert_Position (CSG_PriorityQueueItem *pItem);
371 bool Create (
sLong n,
const double *Data = NULL);
375 bool Set_Rows (
sLong nRows);
376 bool Add_Rows (
sLong nRows);
377 bool Del_Rows (
sLong nRows);
378 bool Add_Row (
double Value = 0.);
379 bool Del_Row (
sLong Row = -1);
383 size_t Get_uSize (
void)
const {
return( m_Array.Get_uSize() ); }
384 int Get_N (
void)
const {
return( (
int)m_Array.Get_Size() ); }
386 double *
Get_Data (
void)
const {
return( (
double *)m_Array.Get_Array() ); }
388 double operator () (
sLong x)
const {
return( Get_Data()[x] ); }
389 double & operator [] (
sLong x) {
return( Get_Data()[x] ); }
390 double & operator [] (
size_t x) {
return( Get_Data()[x] ); }
391 double & operator [] (
int x) {
return( Get_Data()[x] ); }
392 const double & operator [] (
sLong x)
const {
return( Get_Data()[x] ); }
393 const double & operator [] (
size_t x)
const {
return( Get_Data()[x] ); }
394 const double & operator [] (
int x)
const {
return( Get_Data()[x] ); }
395 operator const double * (void)
const {
return( Get_Data() ); }
397 CSG_String to_String (
int Width = -1,
int Precision = -1,
bool bScientific =
false,
const SG_Char *Separator = NULL)
const;
400 bool is_Null (
void)
const;
401 bool is_Equal (
const CSG_Vector &Vector)
const;
402 bool is_Collinear (
const CSG_Vector &Vector)
const;
404 bool Assign (
double Scalar);
406 bool Add (
double Scalar);
409 bool Multiply (
double Scalar);
411 bool Multiply_Cross (
const CSG_Vector &Vector);
412 double Multiply_Scalar (
const CSG_Vector &Vector)
const;
413 bool Multiply (
const class CSG_Matrix &Matrix);
415 bool operator == (
const CSG_Vector &Vector)
const {
return( is_Equal(Vector) ); }
416 bool operator != (
const CSG_Vector &Vector)
const {
return( !is_Equal(Vector) ); }
433 bool Set_Zero (
void);
434 bool Set_Unity (
void);
436 bool Flip_Values (
void);
438 bool Sort (
bool bAscending =
true);
440 double Get_Length (
void)
const;
443 double Get_Angle (
const CSG_Vector &Vector)
const;
489 bool Create (
sLong nCols,
sLong nRows,
const double *Data = NULL);
492 bool Create (
sLong nCols,
sLong nRows,
const double **Data);
497 bool Set_Cols (
sLong nCols);
498 bool Set_Rows (
sLong nRows);
499 bool Add_Cols (
sLong nCols);
500 bool Add_Rows (
sLong nRows);
501 bool Del_Cols (
sLong nCols);
502 bool Del_Rows (
sLong nRows);
503 bool Add_Col (
const double *Data = NULL);
505 bool Add_Row (
const double *Data = NULL);
507 bool Ins_Col (
sLong Col,
const double *Data = NULL);
509 bool Ins_Row (
sLong Row,
const double *Data = NULL);
511 bool Set_Col (
sLong Col,
const double *Data);
514 bool Set_Row (
sLong Row,
const double *Data);
517 bool Del_Col (
sLong Col);
518 bool Del_Row (
sLong Row);
522 int Get_NX (
void)
const {
return( (
int)m_nx ); }
523 int Get_NY (
void)
const {
return( (
int)m_ny ); }
527 operator const double ** (void)
const {
return( (
const double **)m_z ); }
530 double operator () (
sLong Row,
sLong Col)
const {
return( m_z[Row][Col] ); }
531 double * operator [] (
sLong Row)
const {
return( m_z[Row] ); }
532 double * operator [] (
size_t Row)
const {
return( m_z[Row] ); }
533 double * operator [] (
int Row)
const {
return( m_z[Row] ); }
535 CSG_String to_String (
int Width = -1,
int Precision = -1,
bool bScientific =
false,
const SG_Char *Separator = NULL)
const;
538 bool is_Square (
void)
const {
return( m_nx > 0 && m_nx == m_ny ); }
539 bool is_Equal (
const CSG_Matrix &Matrix)
const;
541 bool Assign (
double Scalar);
543 bool Add (
double Scalar);
546 bool Multiply (
double Scalar);
550 bool operator == (
const CSG_Matrix &Matrix)
const;
567 bool Set_Zero (
void);
568 bool Set_Identity (
void);
569 bool Set_Transpose (
void);
570 bool Set_Inverse (
bool bSilent =
true,
int nSubSquare = 0);
572 double Get_Determinant (
void)
const;
574 CSG_Matrix Get_Inverse (
bool bSilent =
true,
int nSubSquare = 0)
const;
584 void _On_Construction (
void);
616 bool Create (
int maxRadius);
622 int Get_nPoints (
int iRadius) {
return( iRadius >= 0 && iRadius < m_maxRadius ? m_nPoints_R[iRadius] : 0 ); }
626 if( iPoint >= 0 && iPoint < m_nPoints )
628 x = m_Points[iPoint].x;
629 y = m_Points[iPoint].y;
631 return( m_Points[iPoint].d );
637 double Get_Point (
int iPoint,
int xOffset,
int yOffset,
int &x,
int &y)
641 if( (d = Get_Point(iPoint, x, y)) >= 0. )
650 double Get_Point (
int iRadius,
int iPoint,
int &x,
int &y)
652 if( iRadius >= 0 && iRadius <= m_maxRadius && iPoint >= 0 && iPoint < m_nPoints_R[iRadius] )
654 x = m_Points_R[iRadius][iPoint].x;
655 y = m_Points_R[iRadius][iPoint].y;
657 return( m_Points_R[iRadius][iPoint].d );
663 double Get_Point (
int iRadius,
int iPoint,
int xOffset,
int yOffset,
int &x,
int &y)
667 if( (d = Get_Point(iRadius, iPoint, x, y)) >= 0. )
679 int m_maxRadius, m_nPoints, *m_nPoints_R;
681 typedef struct SSG_Grid_Radius
689 TSG_Grid_Radius *m_Points, **m_Points_R;
706 static void Initialize (
void);
707 static void Initialize (
unsigned int Value);
709 static double Get_Uniform (
void);
710 static double Get_Uniform (
double min,
double max);
712 static double Get_Gaussian (
double mean,
double stddev);
733 bool Create (
bool bHoldValues =
false);
735 bool Create (
double Mean,
double StdDev,
sLong Count = 1000);
736 bool Create (
const CSG_Vector &Values,
bool bHoldValues =
false);
738 void Invalidate (
void);
739 bool Evaluate (
void);
743 bool Set_Count (
sLong Count);
748 double Get_Minimum (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Minimum ); }
749 double Get_Maximum (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Maximum ); }
750 double Get_Range (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Range ); }
751 double Get_Sum (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Sum ); }
753 double Get_Mean (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Mean ); }
754 double Get_Variance (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_Variance ); }
755 double Get_StdDev (
void) {
if( m_bEvaluated < 1 ) _Evaluate(1);
return( m_StdDev ); }
757 double Get_Kurtosis (
void) {
if( m_bEvaluated < 2 ) _Evaluate(2);
return( m_Kurtosis ); }
758 double Get_Skewness (
void) {
if( m_bEvaluated < 2 ) _Evaluate(2);
return( m_Skewness ); }
759 double Get_SkewnessPearson (
void);
761 double Get_Quantile (
double Quantile);
762 double Get_Percentile (
double Percentile);
763 double Get_Median (
void);
764 double Get_Gini (
void);
766 sLong Get_IndexOfMinimum (
void);
767 sLong Get_IndexOfMaximum (
void);
769 sLong Get_nValues_Above (
double Threshold,
bool bEquals =
false);
770 sLong Get_nValues_Below (
double Threshold,
bool bEquals =
false);
774 void Add_Value (
double Value,
double Weight = 1.);
776 double *
Get_Values (
void)
const {
return( (
double *)m_Values.Get_Array() ); }
777 double Get_Value (
sLong i)
const {
return( i >= 0 && i < (
sLong)m_Values.Get_Size() ? Get_Values()[i] : m_Mean ); }
778 double operator [] (
sLong i)
const {
return( i >= 0 && i < (
sLong)m_Values.Get_Size() ? Get_Values()[i] : m_Mean ); }
794 double m_Weights, m_Sum, m_Sum2, m_Minimum, m_Maximum, m_Range, m_Mean, m_Variance, m_StdDev, m_Kurtosis, m_Skewness, m_Gini;
799 void _Evaluate (
int Level = 1);
817 virtual void Create (
bool bWeights =
false) { m_bWeights = bWeights; }
819 int Get_Count (
void)
const {
return( (
int)m_Count.Get_Size() ); }
821 double Get_Weight (
int i)
const {
return( m_bWeights ? m_Weight[i] : m_Count[i] ); }
823 virtual int Get_Majority (
bool bWeighted =
false)
const;
824 virtual int Get_Minority (
bool bWeighted =
false)
const;
827 virtual bool Get_Majority (
double &Value,
int &Count)
const {
return(
false ); }
829 virtual bool Get_Minority (
double &Value,
int &Count)
const {
return(
false ); }
839 bool m_bWeights{
false};
854 virtual void Create (
bool bWeights =
false);
856 void operator += (
double Value) { Add_Value(Value); }
857 void Add_Value (
double Value,
double Weight = 1.);
858 double Get_Value (
int Index)
const {
return( m_Value[Index] ); }
859 int Get_Class_Index (
double Value)
const;
860 bool Get_Class (
int Index,
double &Value,
int &Count)
const
862 if( Index < 0 || Index >=
Get_Count() )
return(
false );
864 Count = m_Count[Index];
865 Value = m_Value[Index];
889 virtual void Create (
bool bWeights =
false);
891 void operator += (
const CSG_String &Value) { Add_Value(Value); }
892 void Add_Value (
const CSG_String &Value,
double Weight = 1.);
894 int Get_Class_Index (
const CSG_String &Value)
const;
897 if( Index < 0 || Index >=
Get_Count() )
return(
false );
899 Count = m_Count[Index];
900 Value = m_Value[Index];
936 int Add_Value (
int Value);
937 int Add_Value (
double Value);
940 void operator += (
int Value) { Add_Value(Value); }
941 void operator += (
double Value) { Add_Value(Value); }
942 void operator += (
const CSG_String &Value) { Add_Value(Value); }
946 int Get_Count (
void )
const;
947 int Get_Count (
int iCategory)
const;
949 int asInt (
int iCategory)
const;
950 double asDouble (
int iCategory)
const;
953 int Get_Category (
int Value)
const;
954 int Get_Category (
double Value)
const;
955 int Get_Category (
const CSG_String &Value)
const;
959 Count = Get_Count(iCategory);
960 Value = asInt (iCategory);
962 return( iCategory >= 0 && iCategory < Get_Count() );
967 Count = Get_Count(iCategory);
968 Value = asDouble (iCategory);
970 return( iCategory >= 0 && iCategory < Get_Count() );
975 Count = Get_Count(iCategory);
976 Value = asString (iCategory);
978 return( iCategory >= 0 && iCategory < Get_Count() );
981 int Get_Majority (
void);
989 int Get_Minority (
void);
1018 bool Destroy (
void);
1023 CSG_Histogram (
size_t nClasses,
double Minimum,
double Maximum);
1024 bool Create (
size_t nClasses,
double Minimum,
double Maximum);
1026 CSG_Histogram (
size_t nClasses,
const CSG_Vector &Values ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1027 bool Create (
size_t nClasses,
const CSG_Vector &Values ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1029 CSG_Histogram (
size_t nClasses,
class CSG_Table *pTable,
int Field,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1030 bool Create (
size_t nClasses,
class CSG_Table *pTable,
int Field,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1032 CSG_Histogram (
size_t nClasses,
class CSG_Grid *pGrid ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1033 bool Create (
size_t nClasses,
class CSG_Grid *pGrid ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1035 CSG_Histogram (
size_t nClasses,
class CSG_Grids *pGrids ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1036 bool Create (
size_t nClasses,
class CSG_Grids *pGrids ,
double Minimum = 0.,
double Maximum = 0.,
size_t maxSamples = 0);
1039 void Add_Value (
double Value);
1043 bool Scale_Element_Count (
double Scale);
1047 bool is_Okay (
void)
const {
return( m_nClasses && Get_Element_Count() ); }
1055 size_t Get_Elements (
size_t i)
const {
return( i < m_nClasses ? m_Elements [i] : 0 ); }
1058 size_t Get_Cumulative (
size_t i)
const {
return( i < m_nClasses ? m_Cumulative[i] : 0 ); }
1060 double Get_Value (
double i)
const {
return( m_nClasses < 1 ? m_Minimum : m_Minimum + i * m_ClassWidth ); }
1062 double Get_Break (
int i)
const {
return( Get_Value((
double)(i)) ); }
1063 double Get_Break (
size_t i)
const {
return( Get_Value((
double)(i)) ); }
1065 double Get_Center (
int i)
const {
return( Get_Value((
double)(i + 0.5)) ); }
1066 double Get_Center (
size_t i)
const {
return( Get_Value((
double)(i + 0.5)) ); }
1071 void operator += (
double Value) { Add_Value(Value); }
1073 size_t operator [] (
int i)
const {
return( Get_Elements(i) ); }
1074 size_t operator [] (
size_t i)
const {
return( Get_Elements(i) ); }
1076 double Get_Quantile (
double Quantile)
const;
1077 double Get_Quantile_Value (
double Value)
const;
1079 double Get_Percentile (
double Percentile)
const;
1080 double Get_Percentile_Value(
double Value)
const;
1087 size_t m_nClasses = 0, m_nMaximum = 0, *m_Elements = NULL, *m_Cumulative = NULL;
1089 double m_Minimum = 0., m_Maximum = 0., m_ClassWidth = 1.;
1094 void _On_Construction (
void);
1096 bool _Create (
size_t nClasses,
double Minimum,
double Maximum);
1098 bool _Update (
sLong nElements);
1117 bool Create (
class CSG_Table *pTable,
int Field,
int nClasses,
int Histogram = 0);
1120 bool Create (
class CSG_Grid *pGrid ,
int nClasses,
int Histogram = 0);
1123 bool Create (
class CSG_Grids *pGrids ,
int nClasses,
int Histogram = 0);
1126 bool Create (
const CSG_Vector &Values ,
int nClasses,
int Histogram = 0);
1131 double operator [] (
int i)
const {
return( m_Breaks[i] ); }
1141 bool _Histogram (
int nClasses);
1143 double _Get_Value (
int i);
1145 bool _Calculate (
int nClasses);
1171 bool Create (
int nFeatures);
1172 bool Destroy (
void);
1174 bool Add_Element (
void);
1175 bool Set_Feature (
sLong iElement,
int iFeature,
double Value);
1177 sLong Get_Cluster (
sLong iElement)
const {
return( iElement >= 0 && iElement < Get_nElements() ? m_Clusters[iElement] : -1 ); }
1179 bool Execute (
int Method,
int nClusters,
int nMaxIterations = 0,
int Initialization = 0);
1187 double Get_SP (
void)
const {
return( m_SP ); }
1190 double Get_Variance (
int iCluster)
const {
return( m_Variance[iCluster] ); }
1191 double Get_Centroid (
int iCluster,
int iFeature)
const {
return( m_Centroid[iCluster][iFeature] ); }
1196 int m_Iteration, m_nFeatures;
1209 bool _Minimum_Distance (
bool bInitialize,
int nMaxIterations);
1211 bool _Hill_Climbing (
bool bInitialize,
int nMaxIterations);
1243 void Create (
int nFeatures);
1244 void Destroy (
void);
1249 bool Train_Clr_Samples (
void);
1251 bool Train (
bool bClr_Samples =
false);
1263 double Get_Class_Mean (
int iClass,
int iFeature) {
return( m_pClasses[iClass]->m_Mean[iFeature] ); }
1264 double Get_Class_Minimum (
int iClass,
int iFeature) {
return( m_pClasses[iClass]->m_Min [iFeature] ); }
1265 double Get_Class_Maximum (
int iClass,
int iFeature) {
return( m_pClasses[iClass]->m_Max [iFeature] ); }
1268 bool Get_Class (
const CSG_Vector &Features,
int &Class,
double &Quality,
int Method);
1271 void Set_Threshold_Distance (
double Value);
1272 double Get_Threshold_Distance (
void);
1274 void Set_Threshold_Angle (
double Value);
1275 double Get_Threshold_Angle (
void);
1277 void Set_Threshold_Probability (
double Value);
1278 double Get_Threshold_Probability (
void);
1280 void Set_Probability_Relative (
bool Value);
1281 bool Get_Probability_Relative (
void);
1283 void Set_WTA (
int Method,
bool bOn);
1284 bool Get_WTA (
int Method);
1286 static CSG_String Get_Name_of_Method (
int Method);
1287 static CSG_String Get_Name_of_Quality (
int Method);
1300 double m_Cov_Det, m_Mean_Spectral;
1314 int m_nFeatures, m_nClasses;
1316 double m_Threshold_Distance, m_Threshold_Probability, m_Threshold_Angle;
1320 CClass **m_pClasses;
1323 void _Get_Binary_Encoding (
const CSG_Vector &Features,
int &Class,
double &Quality);
1324 void _Get_Parallel_Epiped (
const CSG_Vector &Features,
int &Class,
double &Quality);
1325 void _Get_Minimum_Distance (
const CSG_Vector &Features,
int &Class,
double &Quality);
1326 void _Get_Mahalanobis_Distance (
const CSG_Vector &Features,
int &Class,
double &Quality);
1327 void _Get_Maximum_Likelihood (
const CSG_Vector &Features,
int &Class,
double &Quality);
1328 void _Get_Spectral_Angle_Mapping (
const CSG_Vector &Features,
int &Class,
double &Quality);
1329 void _Get_Spectral_Divergence (
const CSG_Vector &Features,
int &Class,
double &Quality);
1330 void _Get_Winner_Takes_All (
const CSG_Vector &Features,
int &Class,
double &Quality);
1345 enum ESG_mRMR_Method
1347 SG_mRMR_Method_MID = 0,
1357 virtual ~CSG_mRMR(
void);
1359 void Destroy (
void);
1366 void Set_Verbose (
bool bOn =
true) { m_bVerbose = bOn; }
1370 bool Set_Data (
CSG_Table &Data,
int ClassField = 0,
double Threshold = -1.);
1371 bool Set_Data (
CSG_Matrix &Data,
int ClassField = 0,
double Threshold = -1.);
1374 bool Get_Selection (
int nFeatures,
int Method);
1376 int Get_Count (
void)
const;
1377 int Get_Index (
int i)
const;
1379 double Get_Score (
int i)
const;
1384 bool m_bDiscretized, m_bVerbose;
1386 long m_nSamples, m_nVars;
1395 bool Get_Memory (
int nVars,
int nSamples);
1397 bool Discretize (
double Threshold);
1399 double Get_MutualInfo (
long v1,
long v2);
1400 double Get_MutualInfo (
double *pab,
long pabhei,
long pabwid);
1402 template <
class T>
double * Get_JointProb (T *img1, T *img2,
long len,
long maxstatenum,
int &nstate1,
int &nstate2);
1403 template <
class T>
void Copy_Vector (T *srcdata,
long len,
int *desdata,
int &nstate);
1406 typedef struct SPool
1414 static int Pool_Compare (
const void *a,
const void *b);
1435 void Destroy (
void);
1437 bool Create (
double *xValues,
double *yValues,
int nValues,
double yA = 1.0e30,
double yB = 1.0e30);
1438 bool Create (
double yA = 1.0e30,
double yB = 1.0e30);
1440 void Add (
double x,
double y);
1443 double Get_xMin (
void)
const {
return( m_x.Get_N() > 0 ? m_x(0 ) : 0. ); }
1444 double Get_xMax (
void)
const {
return( m_x.Get_N() > 0 ? m_x(m_x.Get_Size() - 1) : 0. ); }
1445 double Get_x (
int i)
const {
return( i >= 0 && i < m_x.Get_N() ? m_x(i) : 0. ); }
1446 double Get_y (
int i)
const {
return( i >= 0 && i < m_y.Get_N() ? m_y(i) : 0. ); }
1448 bool Get_Value (
double x,
double &y);
1449 double Get_Value (
double x);
1459 bool _Create (
double yA,
double yB);
1470 bool Destroy (
void);
1477 bool Add_Point (
double x,
double y,
double z) {
return( m_Points.Add( x, y, z) ); }
1482 if( Index >= 0 && Index < m_Points.Get_Count() )
1484 m_Points[Index].x = x;
1485 m_Points[Index].y = y;
1486 m_Points[Index].z = z;
1496 bool Create (
double Regularization = 0.,
bool bSilent =
true);
1498 bool is_Okay (
void) {
return( m_V.Get_N() > 0 ); }
1500 double Get_Value (
double x,
double y);
1511 double _Get_Base_Funtion (
double x);
1512 double _Get_Base_Funtion (
TSG_Point_3D A,
double x,
double y);
1546 static double Get_Norm_P (
double Z);
1547 static double Get_Norm_Z (
double P);
1552 static double Get_Gamma (
double F,
double dfn,
double dfd);
1553 static double Get_Log_Gamma (
double a);
1555 static double Get_T_P (
double T,
int df);
1556 static double Get_T_Z (
double T,
int df);
1557 static double Get_T_Inv (
double p,
int df);
1621 void Destroy (
void);
1623 bool Set_Values (
int nValues,
double *x,
double *y);
1624 bool Add_Values (
double x,
double y);
1626 int Get_Count (
void)
const {
return( (
int)m_x.Get_Size() ); }
1628 double Get_xValue (
int i)
const {
return( i >= 0 && i < Get_Count() ? m_x[i] : 0. ); }
1629 double Get_yValue (
int i)
const {
return( i >= 0 && i < Get_Count() ? m_y[i] : 0. ); }
1632 if( i >= 0 && i < Get_Count() )
1647 double Get_x (
double y)
const;
1653 double Get_y (
double x)
const;
1657 double Get_R (
void)
const {
return( m_R ); }
1658 double Get_R2 (
void)
const {
return( m_R2 ); }
1660 double Get_P (
void)
const {
return( m_P ); }
1663 const SG_Char * asString (
void);
1673 double m_RConst, m_RCoeff, m_R, m_R2, m_R2_Adj, m_P,
m_SE,
1682 double _Y_Transform (
double x);
1683 double _X_Transform (
double y);
1714 void Destroy (
void);
1724 bool Get_Model_Stepwise (
const CSG_Matrix &Samples,
double P_in,
double P_out,
CSG_Strings *pNames = NULL);
1726 bool Get_Model (
void);
1727 bool Get_Model_Forward (
double P_in);
1728 bool Get_Model_Backward (
double P_out);
1729 bool Get_Model_Stepwise (
double P_in,
double P_out);
1731 bool Get_CrossValidation (
int nSubSamples = 0);
1738 double Get_R2 (
void)
const;
1739 double Get_R2_Adj (
void)
const;
1740 double Get_StdError (
void)
const;
1741 double Get_F (
void)
const;
1742 double Get_P (
void)
const;
1743 double Get_CV_RMSE (
void)
const;
1744 double Get_CV_NRMSE (
void)
const;
1745 double Get_CV_R2 (
void)
const;
1746 int Get_CV_nSamples (
void)
const;
1747 int Get_DegFreedom (
void)
const;
1748 int Get_nSamples (
void)
const;
1749 int Get_nPredictors (
void)
const;
1750 int Get_Predictor (
int i)
const {
return( i >= 0 && i < Get_nPredictors() ? m_Predictor[i] : -1 ); }
1752 double Get_RConst (
void)
const;
1759 double Get_T (
int iVariable)
const {
return( Get_Parameter(iVariable,
MLR_VAR_T ) ); }
1762 double Get_Parameter (
int iVariable,
int Parameter)
const;
1767 double Get_Residual (
int iSample)
const;
1768 bool Get_Residual (
int iSample,
double &Residual)
const;
1770 bool Get_Residuals (
CSG_Vector &Residuals)
const;
1786 bool _Initialize (
bool bInclude);
1788 double _Get_F (
int nPredictors,
int nSamples,
double r2_full,
double r2_reduced);
1789 double _Get_P (
int nPredictors,
int nSamples,
double r2_full,
double r2_reduced);
1791 bool _Get_Regression (
const class CSG_Matrix &Samples);
1794 int _Get_Step_Out (
CSG_Matrix &X,
double P_out,
double &R2);
1797 bool _Set_Step_Info (
const CSG_Matrix &X,
double R2_prev,
int iVariable,
bool bIn);
1813 bool Destroy (
void);
1815 bool Add_Sample (
double Weight,
double Dependent,
const CSG_Vector &Predictors);
1820 bool Calculate (
bool bLogistic =
false);
1822 double Get_R2 (
void)
const {
return( m_r2 ); }
1825 double operator [] (
int i)
const {
return( m_b[i] ); }
1832 bool Set_Log_maxIter (
int maxIter );
1833 bool Set_Log_Epsilon (
double Epsilon );
1834 bool Set_Log_Difference (
double Difference);
1837 bool Get_CrossValidation (
int nSubSamples = 0);
1847 int m_Log_maxIter, m_CV_nSamples;
1849 double m_r2, m_Log_Epsilon, m_Log_Difference, m_CV_RMSE, m_CV_NRMSE, m_CV_R2;
1886 bool Destroy (
void);
1888 static CSG_String Get_Help_Operators (
bool bHTML =
true,
const CSG_String Additional[][2] = NULL);
1892 bool Add_Function (
const char *Name,
TSG_Formula_Function_1 Function,
int nParameters,
bool bVarying =
false);
1894 bool Set_Formula (
const CSG_String &Formula);
1897 void Set_Variable (
char Variable,
double Value);
1899 double Get_Value (
void )
const;
1900 double Get_Value (
double x )
const;
1901 double Get_Value (
const CSG_Vector &Values )
const;
1902 double Get_Value (
double *Values,
int nValues)
const;
1903 double Get_Value (
const char *Arguments, ... )
const;
1905 const char * Get_Used_Variables (
void);
1925 typedef struct SSG_Formula
1935 bool m_bError, m_Vars_Used[256];
1937 int m_Error_Position, m_Length;
1939 TSG_Formula m_Formula;
1941 TSG_Function *m_Functions;
1946 const char *m_error;
1950 double m_Parameters[32], *m_ctable;
1953 void _Set_Error (
const CSG_String &Error =
"");
1955 double _Get_Value (
const double *Parameters, TSG_Formula Function)
const;
1957 int _is_Operand (
char c);
1958 int _is_Operand_Code (
char c);
1959 int _is_Number (
char c);
1961 int _Get_Function (
int i,
char *Name,
int *nParameters,
int *bVarying);
1962 int _Get_Function (
const char *Name);
1964 TSG_Formula _Translate (
const char *source,
const char *args,
int *length,
int *error);
1966 char * _i_trans (
char *
function,
char *begin,
char *end);
1967 char * _comp_time (
char *
function,
char *fend,
int npars);
1968 int _max_size (
const char *source);
1969 char * _my_strtok (
char *s);
1996 bool Set_Formula (
const CSG_String &Formula);
2001 bool Init_Parameter (
const SG_Char &Variable,
double Value);
2003 void Clr_Data (
void);
2004 bool Add_Data (
double x,
double y);
2005 void Set_Data (
double *x,
double *y,
int n,
bool bAdd =
false);
2006 void Set_Data (
const CSG_Points &Data ,
bool bAdd =
false);
2017 bool Set_Max_Iterations (
int Iterations);
2019 bool Set_Max_Lambda (
double Lambda);
2022 bool Get_Trend (
double *x,
double *y,
int n,
const CSG_String &Formula);
2025 bool Get_Trend (
void);
2032 double Get_R2 (
void)
const {
return( m_bOkay ? m_ChiSqr_o : 0. ); }
2034 double Get_Value (
double x)
const {
return( m_bOkay ? m_Formula.Get_Value(x) : 0. ); }
2046 bool Destroy (
void);
2048 int Get_Count (
void)
const {
return( (
int)m_Variables.Length() ); }
2065 double m_ChiSqr, m_ChiSqr_o, m_Lambda, m_Lambda_Max;
2074 bool _Fit_Function (
void);
2075 bool _Get_Gaussj (
void);
2078 void _Get_Function (
double &y,
double *dy_da,
double x,
const double *Parameters);
2095 bool Destroy (
void);
2097 bool Set_Order (
int Order = 1);
2099 bool Clr_Data (
void);
2100 bool Set_Data (
double *x,
double *y,
int n,
bool bAdd =
false);
2101 bool Add_Data (
double x,
double y);
2106 bool Get_Trend (
void);
2111 double Get_R2 (
void)
const {
return( m_r2 ); }
2113 double Get_Value (
double x)
const;
2134 #endif // #ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H
double Get_StdError(int iVariable) const
bool Get_Majority(CSG_String &Value, int &Count)
double Get_Max_Lambda(void) const
double Get_RCoeff(int iVariable) const
size_t Get_Cumulative(int i) const
TSG_Regression_Type Get_Type(void) const
sLong Get_Cluster(sLong iElement) const
size_t Get_Cumulative(size_t i) const
int Get_Parameter_Count(void) const
double Get_Data_Y(int i) const
bool Get_Minority(int &Value)
double Get_Class_Minimum(int iClass, int iFeature)
CSG_Simple_Statistics & Get_Data_YStats(void)
virtual bool Get_Majority(CSG_String &Value, int &Count) const
bool Get_Class(int Index, double &Value, int &Count) const
int Get_Predictor_Count(void) const
bool Get_Category(int iCategory, CSG_String &Value, int &Count) const
virtual ~CSG_Unique_Value_Statistics(void)
CSG_Matrix m_Samples_Model
const_iterator cend(void) const
int Get_nMembers(int iCluster) const
double * Get_Data(void) const
virtual int Compare(CSG_PriorityQueueItem *pItem)=0
virtual bool Get_Value(sLong Index, int Field, CSG_String &Value) const
double Get_Point(int iRadius, int iPoint, int xOffset, int yOffset, int &x, int &y)
bool Add_Point(const TSG_Point &p, double z)
double Get_R2_Partial(int iVariable) const
double Get_Sum_Of_Squares(void)
bool Set_Point_Count(int Count)
virtual bool Get_Minority(CSG_String &Value, int &Count) const
int Get_Predictor(int i) const
double Get_Data_X(int i) const
sLong Get_NRows(void) const
double Get_y(int i) const
virtual bool Get_Minority(double &Value) const
double Get_Variance(void)
double Get_Break(int i) const
const CSG_Vector & Get_RCoeff(void) const
virtual bool Get_Minority(CSG_String &Value) const
int Get_Count(int i) const
int Get_Count(void) const
double Get_Data_Y(int i) const
sLong Get_Index(sLong Position, bool Ascending=true) const
CSG_PriorityQueueItem * Get_Item(size_t i) const
double Get_xVariance(void) const
virtual int Get_Minority(bool bWeighted=false) const
size_t Get_uSize(void) const
size_t Get_Elements(size_t i) const
double Get_R2(void) const
int Get_Log_maxIter(void) const
int Get_Feature_Count(void)
virtual int Compare(const sLong a, const sLong b)=0
double Get_R2_Partial_Adj(int iVariable) const
const SG_Char * Get_Name(void) const
int Get_Iteration(void) const
virtual bool Get_Majority(double &Value) const
double Get_xMax(void) const
double Get_R2(void) const
double Get_yMin(void) const
virtual bool Get_Majority(CSG_String &Value) const
bool Get_Minority(double &Value, int &Count)
double Get_Break(int i) const
double Get_P(int iVariable) const
double Get_xMean(void) const
double Get_yVariance(void) const
virtual bool Get_Minority(CSG_String &Value, int &Count) const
bool Get_Minority(int &Value, int &Count)
double Get_Kurtosis(void)
double Get_R2_Adj(void) const
int Get_Point_Count(void)
bool Get_Minority(CSG_String &Value)
double Get_R2(void) const
double ** Get_Data(void) const
size_t Get_Element_Count(void) const
double Get_ID(int iVariable) const
double Get_Center(int i) const
double Get_Data_YMax(void)
bool Get_Minority(CSG_String &Value, int &Count)
double Get_R2(void) const
double Get_Coefficient(int i) const
sLong Get_NCols(void) const
bool Get_Majority(int &Value)
double Get_x(int i) const
class CSG_Table * Get_Info_Steps(void) const
double Get_Center(size_t i) const
virtual ~CSG_Unique_String_Statistics(void)
double Get_Data_XMax(void)
bool Get_Majority(int &Value, int &Count)
sLong Get_Count(void) const
int Get_Count(void) const
sLong Get_nElements(void) const
double Get_Data_X(int i) const
virtual bool Get_Majority(double &Value) const
const CSG_String & Get_Class_ID(int iClass)
double Get_T(int iVariable) const
virtual bool Get_Minority(double &Value, int &Count) const
double Get_RCoeff(int i) const
double * Get_Parameters(void) const
double Get_Weights(void) const
double Get_Log_Difference(void) const
CSG_Unique_Number_Statistics(bool bWeights=false)
double Get_CV_RMSE(void) const
double Get_xMax(void) const
bool Get_Majority(double &Value)
double Get_CV_R2(void) const
double Get_Break(size_t i) const
bool Get_Values(int i, double &x, double &y) const
int Get_Class_Count(void)
CSG_PriorityQueueItem * Peek(void) const
double Get_Variance(int iCluster) const
virtual bool Get_Minority(double &Value, int &Count) const
double Get_yValue(int i) const
TSG_Regression_Type m_Type
int Get_nCoefficients(void) const
double Get_Data_XMin(void)
int is_Evaluated(void) const
#define SAGA_API_DLL_EXPORT
const_iterator cbegin(void) const
double Get_Class_Maximum(int iClass, int iFeature)
double Get_Constant(void) const
const_iterator end(void) const
virtual ~CSG_Unique_Number_Statistics(void)
int Get_nPoints(int iRadius)
double Get_Skewness(void)
double Get_CV_NRMSE(void) const
int Get_Count(void) const
bool Get_Minority(double &Value)
size_t Get_Class_Count(void) const
bool Get_With_Intercept(void) const
double Get_Value(int Index) const
double Get_Data(sLong x) const
void Set_With_Intercept(bool bOn=true)
double Get_SP(void) const
bool is_Square(void) const
int Get_nFeatures(void) const
sLong Get_Size(void) const
virtual bool Get_Majority(double &Value, int &Count) const
virtual bool Get_Majority(CSG_String &Value, int &Count) const
double Get_xMin(void) const
int Get_CV_nSamples(void) const
size_t Get_Size(void) const
CSG_Points_3D & Get_Points(void)
double Get_xMin(void) const
double Get_Class_Mean(int iClass, int iFeature)
CSG_PriorityQueueItem * Minimum(void) const
double Get_Weight(int i) const
double * Get_Values(void) const
double Get_Value(sLong i) const
class CSG_Table * m_pSteps
double Get_Coefficient(void) const
bool is_Empty(void) const
bool Get_Majority(double &Value, int &Count)
virtual bool Get_Minority(double &Value) const
class CSG_Table * Get_Info_Model(void) const
virtual int Get_Majority(bool bWeighted=false) const
int Get_nClusters(void) const
bool Get_Category(int iCategory, double &Value, int &Count) const
double Get_Centroid(int iCluster, int iFeature) const
virtual void Create(bool bWeights=false)
double Get_Point(int iPoint, int &x, int &y)
int Get_Data_Count(void) const
double Get_StdError(void) const
virtual bool Get_Majority(CSG_String &Value) const
virtual bool Get_Majority(double &Value, int &Count) const
virtual bool Get_Minority(CSG_String &Value) const
double Get_Value(double x) const
int Get_Data_Count(void) const
CSG_PriorityQueueItem(void)
double Get_Data_YMin(void)
const SG_Char * Get_Value(int Index) const
CSG_Unique_Value_Statistics(void)
double Get_Point(int iPoint, int xOffset, int yOffset, int &x, int &y)
const_iterator begin(void) const
bool Get_Class(int Index, CSG_String &Value, int &Count) const
bool Set_Point(int Index, double x, double y, double z)
bool Get_Majority(CSG_String &Value)
double Get_Point(int iRadius, int iPoint, int &x, int &y)
CSG_PriorityQueueItem * Maximum(void) const
double Get_Log_Epsilon(void) const
int Get_Count(void) const
sLong Get_Count(void) const
CSG_Simple_Statistics & Get_Data_XStats(void)
size_t Get_Element_Maximum(void) const
bool Set_Point(int Index, const TSG_Point &p, double z)
bool Get_Category(int iCategory, int &Value, int &Count) const
virtual ~CSG_Index_Compare(void)
int Get_Max_Iterations(void) const
size_t Get_Elements(int i) const
double Get_ChiSquare(void) const
double Get_Value(double i) const
CSG_Unique_String_Statistics(bool bWeights=false)
class CSG_Table * Get_Info_Regression(void) const
double Get_yMax(void) const
sLong Get_Row_Count(void) const
const CSG_Simple_Statistics & Get_Statistics(void) const
double Get_yMean(void) const
bool Add_Point(double x, double y, double z)
int Get_Sample_Count(void) const
double const * const_iterator
int Get_Order(void) const
double Get_xValue(int i) const
SAGA_API_DLL_EXPORT CSG_String operator+(const char *A, const CSG_String &B)