SAGA API Version 9.14
Loading...
Searching...
No Matches
mat_tools.h
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// mat_tools.h //
15// //
16// Copyright (C) 2005 by Olaf Conrad //
17// //
18//-------------------------------------------------------//
19// //
20// This file is part of 'SAGA - System for Automated //
21// Geoscientific Analyses'. //
22// //
23// This library is free software; you can redistribute //
24// it and/or modify it under the terms of the GNU Lesser //
25// General Public License as published by the Free //
26// Software Foundation, either version 2.1 of the //
27// License, or (at your option) any later version. //
28// //
29// This library is distributed in the hope that it will //
30// be useful, but WITHOUT ANY WARRANTY; without even the //
31// implied warranty of MERCHANTABILITY or FITNESS FOR A //
32// PARTICULAR PURPOSE. See the GNU Lesser General Public //
33// License for more details. //
34// //
35// You should have received a copy of the GNU Lesser //
36// General Public License along with this program; if //
37// not, see <http://www.gnu.org/licenses/>. //
38// //
39//-------------------------------------------------------//
40// //
41// contact: Olaf Conrad //
42// Institute of Geography //
43// University of Goettingen //
44// Goldschmidtstr. 5 //
45// 37077 Goettingen //
46// Germany //
47// //
48// e-mail: oconrad@saga-gis.org //
49// //
51
52//---------------------------------------------------------
53#ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H
54#define HEADER_INCLUDED__SAGA_API__mat_tools_H
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
78
79
81// //
83
84//---------------------------------------------------------
85#include "geo_tools.h"
86
87
89// //
90// //
91// //
93
94//---------------------------------------------------------
95#ifndef M_PI
96#define M_PI 3.141592653589793
97#endif
98
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.)
107
108#define M_RAD_TO_DEG (180. / M_PI)
109#define M_DEG_TO_RAD (M_PI / 180.)
110
111//---------------------------------------------------------
112#define M_EULER 2.718281828459045
113
114//---------------------------------------------------------
115#define N_MEGABYTE_BYTES 0x100000
116
117//---------------------------------------------------------
118#ifdef FLT_EPSILON
119 #define M_FLT_EPSILON FLT_EPSILON
120#else
121 #define M_FLT_EPSILON 1.192092896e-07F
122#endif
123
124#ifdef DBL_EPSILON
125 #define M_DBL_EPSILON DBL_EPSILON
126#else
127 #define M_DBL_EPSILON 2.2204460492503131e-016
128#endif
129
130// >>> DEPRECATED >>> //
131#define M_ALMOST_ZERO (1.e-03)
132#define M_TINY (1.e-20)
133// <<< DEPRECATED <<< //
134
135
136//---------------------------------------------------------
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)))
140
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; }
144
145#define M_SET_SIGN(x, sign) ((sign) < 0 ? (x < 0 ? x : -x) : (x > 0 ? x : -x))
146
147#define M_HAS_DECIMALS(x) (x - floor(x) > 0.)
148
149//---------------------------------------------------------
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))
159
160
162// //
163// //
164// //
166
167//---------------------------------------------------------
168SAGA_API_DLL_EXPORT double SG_Get_Square (double Value);
169
170SAGA_API_DLL_EXPORT double SG_Get_Rounded (double Value, int Decimals = 0);
171SAGA_API_DLL_EXPORT double SG_Get_Rounded_To_SignificantFigures (double Value, int Decimals);
172
173//---------------------------------------------------------
175
176//---------------------------------------------------------
177SAGA_API_DLL_EXPORT CSG_String SG_Get_Double_asString (double Number, int Width = -1, int Precision = -1, bool bScientific = false);
178
179//---------------------------------------------------------
180SAGA_API_DLL_EXPORT int SG_Compare_Int (const void *a, const void *b);
181SAGA_API_DLL_EXPORT int SG_Compare_Double (const void *a, const void *b);
182SAGA_API_DLL_EXPORT int SG_Compare_Char_Ptr (const void *a, const void *b);
183
184//---------------------------------------------------------
185SAGA_API_DLL_EXPORT double SG_Degree_To_Decimal ( double Deg, double Min, double Sec);
186SAGA_API_DLL_EXPORT void SG_Decimal_To_Degree (double Value, double &Deg, double &Min, double &Sec);
187
188
190// //
191// //
192// //
194
195//---------------------------------------------------------
196typedef int (* TSG_PFNC_Compare) (const sLong a, const sLong b);
197
198//---------------------------------------------------------
200{
201public:
203 {
204 public:
206 virtual ~CSG_Index_Compare(void) {}
207
208 virtual int Compare (const sLong a, const sLong b) = 0;
209 };
210
211
212public:
213 CSG_Index(void);
214 virtual ~CSG_Index(void);
215
216 CSG_Index (sLong nValues, CSG_Index_Compare &Compare);
217 bool Create (sLong nValues, CSG_Index_Compare &Compare);
218
219 CSG_Index (sLong nValues, CSG_Index_Compare *pCompare);
220 bool Create (sLong nValues, CSG_Index_Compare *pCompare);
221
222 CSG_Index (sLong nValues, int *Values, bool bAscending = true);
223 bool Create (sLong nValues, int *Values, bool bAscending = true);
224
225 CSG_Index (sLong nValues, double *Values, bool bAscending = true);
226 bool Create (sLong nValues, double *Values, bool bAscending = true);
227
228 CSG_Index (sLong nValues, TSG_PFNC_Compare fCompare);
229 bool Create (sLong nValues, TSG_PFNC_Compare fCompare);
230
231 bool Destroy (void);
232
233 bool Invert (void);
234
235 void Show_Progress (bool bProgress = true);
236
237 bool Add_Entry (sLong Position = -1);
238 bool Del_Entry (sLong Position = -1);
239
240 bool is_Okay (void) const { return( m_nValues > 0 ); }
241 sLong Get_Count (void) const { return( m_nValues ); }
242
243 sLong Get_Index (sLong Position, bool Ascending = true) const
244 {
245 return( Position < 0 || Position >= m_nValues ? -1 : m_Index[Ascending ? Position : m_nValues - 1 - Position] );
246 }
247
248 sLong operator [] (sLong Position) const
249 {
250 return( Position < 0 || Position >= m_nValues ? -1 : m_Index[Position] );
251 }
252
253
254private:
255
256 bool m_bProgress;
257
258 sLong m_nValues, *m_Index;
259
260
261 void _On_Construction (void);
262
263 bool _Set_Array (sLong nValues);
264 bool _Set_Index (CSG_Index_Compare *pCompare);
265
266};
267
268
270// //
271// //
272// //
274
275//---------------------------------------------------------
277{
278public:
279
280 //-----------------------------------------------------
282 {
283 public:
285
286 virtual int Compare (CSG_PriorityQueueItem *pItem) = 0;
287
288 };
289
290 //-----------------------------------------------------
291 CSG_PriorityQueue(size_t maxSize = 256);
292
293 virtual ~CSG_PriorityQueue(void);
294
295 void Create (size_t maxSize = 256);
296 void Destroy (void);
297
298 //-----------------------------------------------------
299 bool is_Empty (void) const { return( m_nItems == 0 ); }
300 size_t Get_Size (void) const { return( m_nItems ); }
301 CSG_PriorityQueueItem * Get_Item (size_t i) const { return( m_Items[i] ); }
302
303 void Add (CSG_PriorityQueueItem *pItem);
304
305 CSG_PriorityQueueItem * Peek (void) const { return( Minimum() ); }
306 CSG_PriorityQueueItem * Poll (void);
307
308 //-----------------------------------------------------
310 {
311 if( m_nItems )
312 {
313 if( m_pLeaf[0] )
314 {
315 return( m_pLeaf[0]->Minimum() );
316 }
317
318 return( m_Items[0] );
319 }
320
321 return( NULL );
322 }
323
325 {
326 if( m_nItems )
327 {
328 if( m_pLeaf[1] )
329 {
330 return( m_pLeaf[1]->Maximum() );
331 }
332
333 return( m_Items[m_nItems - 1] );
334 }
335
336 return( NULL );
337 }
338
339
340private:
341
342 size_t m_nItems, m_maxSize;
343
344 CSG_PriorityQueue *m_pLeaf[2];
345
346 CSG_PriorityQueueItem **m_Items;
347
348
349 size_t _Insert_Position (CSG_PriorityQueueItem *pItem);
350
351};
352
353
355// //
356// //
357// //
359
360//---------------------------------------------------------
362{
363public:
364 CSG_Vector(void);
365 virtual ~CSG_Vector(void);
366
367 CSG_Vector (const CSG_Vector &Vector);
368 bool Create (const CSG_Vector &Vector);
369
370 CSG_Vector (sLong n, const double *Data = NULL);
371 bool Create (sLong n, const double *Data = NULL);
372
373 bool Destroy (void);
374
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);
380
381 sLong Get_Row_Count (void) const { return( m_Array.Get_Size () ); }
382 sLong Get_Size (void) const { return( m_Array.Get_Size () ); }
383 size_t Get_uSize (void) const { return( m_Array.Get_uSize() ); }
384 int Get_N (void) const { return( (int)m_Array.Get_Size() ); }
385
386 double * Get_Data (void) const { return( (double *)m_Array.Get_Array() ); }
387 double Get_Data (sLong x) const { return( Get_Data()[x] ); }
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() ); }
396
397 CSG_String to_String (int Width = -1, int Precision = -1, bool bScientific = false, const SG_Char *Separator = NULL) const;
398 bool from_String (const CSG_String &String);
399
400 bool is_Null (void) const;
401 bool is_Equal (const CSG_Vector &Vector) const;
402 bool is_Collinear (const CSG_Vector &Vector) const;
403
404 bool Assign (double Scalar);
405 bool Assign (const CSG_Vector &Vector);
406 bool Add (double Scalar);
407 bool Add (const CSG_Vector &Vector);
408 bool Subtract (const CSG_Vector &Vector);
409 bool Multiply (double Scalar);
410 bool Multiply (const CSG_Vector &Vector);
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);
414
415 bool operator == (const CSG_Vector &Vector) const { return( is_Equal(Vector) ); }
416 bool operator != (const CSG_Vector &Vector) const { return( !is_Equal(Vector) ); }
417 CSG_Vector & operator = (double Scalar);
418 CSG_Vector & operator = (const CSG_Vector &Vector);
419 CSG_Vector & operator += (double Scalar);
420 CSG_Vector & operator += (const CSG_Vector &Vector);
421 CSG_Vector & operator -= (double Scalar);
422 CSG_Vector & operator -= (const CSG_Vector &Vector);
423 CSG_Vector & operator *= (double Scalar);
424 CSG_Vector & operator *= (const CSG_Vector &Vector);
425 CSG_Vector & operator *= (const class CSG_Matrix &Matrix);
426 CSG_Vector operator + (double Scalar) const;
427 CSG_Vector operator + (const CSG_Vector &Vector) const;
428 CSG_Vector operator - (double Scalar) const;
429 CSG_Vector operator - (const CSG_Vector &Vector) const;
430 CSG_Vector operator * (double Scalar) const;
431 double operator * (const CSG_Vector &Vector) const;
432
433 bool Set_Zero (void);
434 bool Set_Unity (void);
435
436 bool Flip_Values (void);
437
438 bool Sort (bool bAscending = true);
439
440 double Get_Length (void) const;
441 CSG_Vector Get_Scalar_Product (const CSG_Vector &Vector) const;
442 CSG_Vector Get_Cross_Product (const CSG_Vector &Vector) const;
443 double Get_Angle (const CSG_Vector &Vector) const;
444 CSG_Vector Get_Unity (void) const;
445
446 typedef double const * const_iterator;
447
448 const_iterator begin (void) const { return( Get_Data() ); }
449 const_iterator end (void) const { return( Get_Data() + Get_Size() ); }
450 const_iterator cbegin (void) const { return( Get_Data() ); }
451 const_iterator cend (void) const { return( Get_Data() + Get_Size() ); }
452
453
454private:
455
456 CSG_Array m_Array;
457
458};
459
460//---------------------------------------------------------
461SAGA_API_DLL_EXPORT CSG_Vector operator * (double Scalar, const CSG_Vector &Vector);
462
463//---------------------------------------------------------
464SAGA_API_DLL_EXPORT bool SG_VectorR2_Rotate (double &x, double &y, double Angle);
465SAGA_API_DLL_EXPORT bool SG_VectorR2_Rotate (double Vector[2], double Angle);
466SAGA_API_DLL_EXPORT bool SG_VectorR2_Rotate (CSG_Vector &Vector , double Angle);
467
468SAGA_API_DLL_EXPORT bool SG_VectorR3_Rotate (double Vector[3], size_t Axis, double Angle);
469SAGA_API_DLL_EXPORT bool SG_VectorR3_Rotate (CSG_Vector &Vector , size_t Axis, double Angle);
470
471
473// //
474// //
475// //
477
478//---------------------------------------------------------
480{
481public:
482 CSG_Matrix(void);
483 virtual ~CSG_Matrix(void);
484
485 CSG_Matrix (const CSG_Matrix &Matrix);
486 bool Create (const CSG_Matrix &Matrix);
487
488 CSG_Matrix (sLong nCols, sLong nRows, const double *Data = NULL);
489 bool Create (sLong nCols, sLong nRows, const double *Data = NULL);
490
491 CSG_Matrix (sLong nCols, sLong nRows, const double **Data);
492 bool Create (sLong nCols, sLong nRows, const double **Data);
493
494 bool Destroy (void);
495
496 bool Set_Size (sLong nRows, sLong nCols);
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);
504 bool Add_Col ( const CSG_Vector &Data);
505 bool Add_Row ( const double *Data = NULL);
506 bool Add_Row ( const CSG_Vector &Data);
507 bool Ins_Col (sLong Col, const double *Data = NULL);
508 bool Ins_Col (sLong Col, const CSG_Vector &Data);
509 bool Ins_Row (sLong Row, const double *Data = NULL);
510 bool Ins_Row (sLong Row, const CSG_Vector &Data);
511 bool Set_Col (sLong Col, const double *Data);
512 bool Set_Col (sLong Col, const CSG_Vector &Data);
513 bool Set_Col ( const CSG_Vector &Data);
514 bool Set_Row (sLong Row, const double *Data);
515 bool Set_Row (sLong Row, const CSG_Vector &Data);
516 bool Set_Row ( const CSG_Vector &Data);
517 bool Del_Col (sLong Col);
518 bool Del_Row (sLong Row);
519 CSG_Vector Get_Col (sLong Col) const;
520 CSG_Vector Get_Row (sLong Row) const;
521
522 int Get_NX (void) const { return( (int)m_nx ); }
523 int Get_NY (void) const { return( (int)m_ny ); }
524 sLong Get_NCols (void) const { return( m_nx ); }
525 sLong Get_NRows (void) const { return( m_ny ); }
526
527 operator const double ** (void) const { return( (const double **)m_z ); }
528 double ** Get_Data (void) const { return( m_z ); }
529
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] ); }
534
535 CSG_String to_String (int Width = -1, int Precision = -1, bool bScientific = false, const SG_Char *Separator = NULL) const;
536 bool from_String (const CSG_String &String);
537
538 bool is_Square (void) const { return( m_nx > 0 && m_nx == m_ny ); }
539 bool is_Equal (const CSG_Matrix &Matrix) const;
540
541 bool Assign (double Scalar);
542 bool Assign (const CSG_Matrix &Matrix);
543 bool Add (double Scalar);
544 bool Add (const CSG_Matrix &Matrix);
545 bool Subtract (const CSG_Matrix &Matrix);
546 bool Multiply (double Scalar);
547 CSG_Vector Multiply (const CSG_Vector &Vector) const;
548 CSG_Matrix Multiply (const CSG_Matrix &Matrix) const;
549
550 bool operator == (const CSG_Matrix &Matrix) const;
551 CSG_Matrix & operator = (double Scalar);
552 CSG_Matrix & operator = (const CSG_Matrix &Matrix);
553 CSG_Matrix & operator += (double Scalar);
554 CSG_Matrix & operator += (const CSG_Matrix &Matrix);
555 CSG_Matrix & operator -= (double Scalar);
556 CSG_Matrix & operator -= (const CSG_Matrix &Matrix);
557 CSG_Matrix & operator *= (double Scalar);
558 CSG_Matrix & operator *= (const CSG_Matrix &Matrix);
559 CSG_Matrix operator + (double Scalar) const;
560 CSG_Matrix operator + (const CSG_Matrix &Matrix) const;
561 CSG_Matrix operator - (double Scalar) const;
562 CSG_Matrix operator - (const CSG_Matrix &Matrix) const;
563 CSG_Matrix operator * (double Scalar) const;
564 CSG_Vector operator * (const CSG_Vector &Vector) const;
565 CSG_Matrix operator * (const CSG_Matrix &Matrix) const;
566
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);
571
572 double Get_Determinant (void) const;
573 CSG_Matrix Get_Transpose (void) const;
574 CSG_Matrix Get_Inverse (bool bSilent = true, int nSubSquare = 0) const;
575
576
577private:
578
579 sLong m_nx, m_ny;
580
581 double **m_z;
582
583
584 void _On_Construction (void);
585
586};
587
588//---------------------------------------------------------
589SAGA_API_DLL_EXPORT CSG_Matrix operator * (double Scalar, const CSG_Matrix &Matrix);
590
591//---------------------------------------------------------
592SAGA_API_DLL_EXPORT CSG_Matrix SG_Matrix_Get_Rotation (double R , bool bDegree = false);
593SAGA_API_DLL_EXPORT CSG_Matrix SG_Matrix_Get_Rotation (double Rx, double Ry, double Rz, bool bDegree = false);
594
595//---------------------------------------------------------
596SAGA_API_DLL_EXPORT bool SG_Matrix_LU_Decomposition (int n, int *Permutation, double **Matrix , bool bSilent = true, int *nRowChanges = NULL);
597SAGA_API_DLL_EXPORT bool SG_Matrix_LU_Solve (int n, const int *Permutation, const double **Matrix, double *Vector, bool bSilent = true);
598
599SAGA_API_DLL_EXPORT bool SG_Matrix_Solve (CSG_Matrix &Matrix, CSG_Vector &Vector, bool bSilent = true);
600SAGA_API_DLL_EXPORT bool SG_Matrix_Eigen_Reduction (const CSG_Matrix &Matrix, CSG_Matrix &Eigen_Vectors, CSG_Vector &Eigen_Values, bool bSilent = true);
601
602
604// //
605// //
606// //
608
609//---------------------------------------------------------
611{
612public:
613 CSG_Grid_Radius(int maxRadius = 0);
614 ~CSG_Grid_Radius(void);
615
616 bool Create (int maxRadius);
617 void Destroy (void);
618
619 int Get_Maximum (void) { return( m_maxRadius ); }
620
621 int Get_nPoints (void) { return( m_nPoints ); }
622 int Get_nPoints (int iRadius) { return( iRadius >= 0 && iRadius < m_maxRadius ? m_nPoints_R[iRadius] : 0 ); }
623
624 double Get_Point (int iPoint, int &x, int &y)
625 {
626 if( iPoint >= 0 && iPoint < m_nPoints )
627 {
628 x = m_Points[iPoint].x;
629 y = m_Points[iPoint].y;
630
631 return( m_Points[iPoint].d ); // Distance...
632 }
633
634 return( -1. );
635 }
636
637 double Get_Point (int iPoint, int xOffset, int yOffset, int &x, int &y)
638 {
639 double d;
640
641 if( (d = Get_Point(iPoint, x, y)) >= 0. )
642 {
643 x += xOffset;
644 y += yOffset;
645 }
646
647 return( d );
648 }
649
650 double Get_Point (int iRadius, int iPoint, int &x, int &y)
651 {
652 if( iRadius >= 0 && iRadius <= m_maxRadius && iPoint >= 0 && iPoint < m_nPoints_R[iRadius] )
653 {
654 x = m_Points_R[iRadius][iPoint].x;
655 y = m_Points_R[iRadius][iPoint].y;
656
657 return( m_Points_R[iRadius][iPoint].d ); // Distance...
658 }
659
660 return( -1. );
661 }
662
663 double Get_Point (int iRadius, int iPoint, int xOffset, int yOffset, int &x, int &y)
664 {
665 double d;
666
667 if( (d = Get_Point(iRadius, iPoint, x, y)) >= 0. )
668 {
669 x += xOffset;
670 y += yOffset;
671 }
672
673 return( d );
674 }
675
676
677private:
678
679 int m_maxRadius, m_nPoints, *m_nPoints_R;
680
681 typedef struct SSG_Grid_Radius
682 {
683 int x, y;
684
685 double d;
686 }
687 TSG_Grid_Radius;
688
689 TSG_Grid_Radius *m_Points, **m_Points_R;
690
691};
692
693
695// //
696// //
697// //
699
700//---------------------------------------------------------
702{
703public:
704 CSG_Random(void);
705
706 static void Initialize (void);
707 static void Initialize (unsigned int Value);
708
709 static double Get_Uniform (void);
710 static double Get_Uniform (double min, double max);
711
712 static double Get_Gaussian (double mean, double stddev);
713
714};
715
716
718// //
719// //
720// //
722
723//---------------------------------------------------------
725{
726public:
728 CSG_Simple_Statistics(bool bHoldValues);
730 CSG_Simple_Statistics(double Mean, double StdDev, sLong Count = 1000);
731 CSG_Simple_Statistics(const CSG_Vector &Values, bool bHoldValues = false);
732
733 bool Create (bool bHoldValues = false);
734 bool Create (const CSG_Simple_Statistics &Statistics);
735 bool Create (double Mean, double StdDev, sLong Count = 1000);
736 bool Create (const CSG_Vector &Values, bool bHoldValues = false);
737
738 void Invalidate (void);
739 bool Evaluate (void);
740
741 int is_Evaluated (void) const { return( m_bEvaluated ); }
742
743 bool Set_Count (sLong Count);
744
745 sLong Get_Count (void) const { return( m_nValues ); }
746 double Get_Weights (void) const { return( m_Weights ); }
747
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 ); }
752 double Get_Sum_Of_Squares (void) { if( m_bEvaluated < 1 ) _Evaluate(1); return( m_Sum2 ); }
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 ); }
756
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);
760
761 double Get_Quantile (double Quantile);
762 double Get_Percentile (double Percentile);
763 double Get_Median (void);
764 double Get_Gini (void);
765
766 sLong Get_IndexOfMinimum (void);
767 sLong Get_IndexOfMaximum (void);
768
769 sLong Get_nValues_Above (double Threshold, bool bEquals = false);
770 sLong Get_nValues_Below (double Threshold, bool bEquals = false);
771
772 void Add (const CSG_Simple_Statistics &Statistics);
773
774 void Add_Value (double Value, double Weight = 1.);
775
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 ); }
779
780
781 CSG_Simple_Statistics & operator = (const CSG_Simple_Statistics &Statistics) { Create(Statistics); return( *this ); }
782 CSG_Simple_Statistics & operator += (const CSG_Simple_Statistics &Statistics) { Add(Statistics); return( *this ); }
783 CSG_Simple_Statistics & operator += (double Value) { Add_Value(Value); return( *this ); }
784
785
786protected:
787
789
791
793
795
797
798
799 void _Evaluate (int Level = 1);
800
801};
802
803
805// //
806// //
807// //
809
810//---------------------------------------------------------
812{
813public:
816
817 virtual void Create (bool bWeights = false) { m_bWeights = bWeights; }
818
819 int Get_Count (void) const { return( (int)m_Count.Get_Size() ); }
820 int Get_Count (int i) const { return( m_Count[i] ); }
821 double Get_Weight (int i) const { return( m_bWeights ? m_Weight[i] : m_Count[i] ); }
822
823 virtual int Get_Majority (bool bWeighted = false) const;
824 virtual int Get_Minority (bool bWeighted = false) const;
825
826 virtual bool Get_Majority (double &Value ) const { return( false ); }
827 virtual bool Get_Majority (double &Value, int &Count) const { return( false ); }
828 virtual bool Get_Minority (double &Value ) const { return( false ); }
829 virtual bool Get_Minority (double &Value, int &Count) const { return( false ); }
830
831 virtual bool Get_Majority (CSG_String &Value ) const { return( false ); }
832 virtual bool Get_Majority (CSG_String &Value, int &Count) const { return( false ); }
833 virtual bool Get_Minority (CSG_String &Value ) const { return( false ); }
834 virtual bool Get_Minority (CSG_String &Value, int &Count) const { return( false ); }
835
836
837protected:
838
839 bool m_bWeights{false};
840
842
844
845};
846
847//---------------------------------------------------------
849{
850public:
851 CSG_Unique_Number_Statistics (bool bWeights = false) { Create(bWeights); }
853
854 virtual void Create (bool bWeights = false);
855
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
861 {
862 if( Index < 0 || Index >= Get_Count() ) return( false );
863
864 Count = m_Count[Index];
865 Value = m_Value[Index];
866
867 return( true );
868 }
869
870 virtual bool Get_Majority (double &Value ) const { int Count; return( Get_Class(CSG_Unique_Value_Statistics::Get_Majority(), Value, Count) ); }
871 virtual bool Get_Majority (double &Value, int &Count) const { return( Get_Class(CSG_Unique_Value_Statistics::Get_Majority(), Value, Count) && Count > 0 ); }
872 virtual bool Get_Minority (double &Value ) const { int Count; return( Get_Class(CSG_Unique_Value_Statistics::Get_Minority(), Value, Count) ); }
873 virtual bool Get_Minority (double &Value, int &Count) const { return( Get_Class(CSG_Unique_Value_Statistics::Get_Minority(), Value, Count) && Count > 0 ); }
874
875
876private:
877
878 CSG_Vector m_Value;
879
880};
881
882//---------------------------------------------------------
884{
885public:
886 CSG_Unique_String_Statistics (bool bWeights = false) { Create(bWeights); }
888
889 virtual void Create (bool bWeights = false);
890
891 void operator += (const CSG_String &Value) { Add_Value(Value); }
892 void Add_Value (const CSG_String &Value, double Weight = 1.);
893 const SG_Char * Get_Value (int Index) const { return( m_Value[Index] ); }
894 int Get_Class_Index (const CSG_String &Value) const;
895 bool Get_Class (int Index, CSG_String &Value, int &Count) const
896 {
897 if( Index < 0 || Index >= Get_Count() ) return( false );
898
899 Count = m_Count[Index];
900 Value = m_Value[Index];
901
902 return( true );
903 }
904
905 virtual bool Get_Majority (CSG_String &Value ) const { int Count; return( Get_Class(CSG_Unique_Value_Statistics::Get_Majority(), Value, Count) ); }
906 virtual bool Get_Majority (CSG_String &Value, int &Count) const { return( Get_Class(CSG_Unique_Value_Statistics::Get_Majority(), Value, Count) && Count > 0 ); }
907 virtual bool Get_Minority (CSG_String &Value ) const { int Count; return( Get_Class(CSG_Unique_Value_Statistics::Get_Minority(), Value, Count) ); }
908 virtual bool Get_Minority (CSG_String &Value, int &Count) const { return( Get_Class(CSG_Unique_Value_Statistics::Get_Minority(), Value, Count) && Count > 0 ); }
909
910
911private:
912
913 CSG_Strings m_Value;
914
915};
916
917
919// //
920// //
921// //
923
924//---------------------------------------------------------
926{
927public:
929 virtual ~CSG_Category_Statistics (void);
930
932 void Destroy (void);
933
934 TSG_Data_Type Get_Category_Type (void) const;
935
936 int Add_Value (int Value);
937 int Add_Value (double Value);
938 int Add_Value (const CSG_String &Value);
939
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); }
943
944 bool Sort (void);
945
946 int Get_Count (void ) const;
947 int Get_Count (int iCategory) const;
948
949 int asInt (int iCategory) const;
950 double asDouble (int iCategory) const;
951 CSG_String asString (int iCategory) const;
952
953 int Get_Category (int Value) const;
954 int Get_Category (double Value) const;
955 int Get_Category (const CSG_String &Value) const;
956
957 bool Get_Category (int iCategory, int &Value, int &Count) const
958 {
959 Count = Get_Count(iCategory);
960 Value = asInt (iCategory);
961
962 return( iCategory >= 0 && iCategory < Get_Count() );
963 }
964
965 bool Get_Category (int iCategory, double &Value, int &Count) const
966 {
967 Count = Get_Count(iCategory);
968 Value = asDouble (iCategory);
969
970 return( iCategory >= 0 && iCategory < Get_Count() );
971 }
972
973 bool Get_Category (int iCategory, CSG_String &Value, int &Count) const
974 {
975 Count = Get_Count(iCategory);
976 Value = asString (iCategory);
977
978 return( iCategory >= 0 && iCategory < Get_Count() );
979 }
980
981 int Get_Majority (void);
982 bool Get_Majority (int &Value ) { int Count; return( Get_Category(Get_Majority(), Value, Count) ); }
983 bool Get_Majority (double &Value ) { int Count; return( Get_Category(Get_Majority(), Value, Count) ); }
984 bool Get_Majority (CSG_String &Value ) { int Count; return( Get_Category(Get_Majority(), Value, Count) ); }
985 bool Get_Majority (int &Value, int &Count) { return( Get_Category(Get_Majority(), Value, Count) && Count > 0 ); }
986 bool Get_Majority (double &Value, int &Count) { return( Get_Category(Get_Majority(), Value, Count) && Count > 0 ); }
987 bool Get_Majority (CSG_String &Value, int &Count) { return( Get_Category(Get_Majority(), Value, Count) && Count > 0 ); }
988
989 int Get_Minority (void);
990 bool Get_Minority (int &Value ) { int Count; return( Get_Category(Get_Minority(), Value, Count) ); }
991 bool Get_Minority (double &Value ) { int Count; return( Get_Category(Get_Minority(), Value, Count) ); }
992 bool Get_Minority (CSG_String &Value ) { int Count; return( Get_Category(Get_Minority(), Value, Count) ); }
993 bool Get_Minority (int &Value, int &Count) { return( Get_Category(Get_Minority(), Value, Count) && Count > 0 ); }
994 bool Get_Minority (double &Value, int &Count) { return( Get_Category(Get_Minority(), Value, Count) && Count > 0 ); }
995 bool Get_Minority (CSG_String &Value, int &Count) { return( Get_Category(Get_Minority(), Value, Count) && Count > 0 ); }
996
997
998private:
999
1000 class CSG_Table *m_pTable;
1001
1002};
1003
1004
1006// //
1007// //
1008// //
1010
1011//---------------------------------------------------------
1013{
1014public:
1015 CSG_Histogram(void);
1016 virtual ~CSG_Histogram(void);
1017
1018 bool Destroy (void);
1019
1020 CSG_Histogram (const CSG_Histogram &Histogram);
1021 bool Create (const CSG_Histogram &Histogram);
1022
1023 CSG_Histogram (size_t nClasses, double Minimum, double Maximum);
1024 bool Create (size_t nClasses, double Minimum, double Maximum);
1025
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);
1028
1029 CSG_Histogram (size_t nClasses, class CSG_Table *pTable, int Field, double Minimum = 0., double Maximum = 0., size_t maxSamples = 0, int Normalize = -1, double Scale = 1.);
1030 bool Create (size_t nClasses, class CSG_Table *pTable, int Field, double Minimum = 0., double Maximum = 0., size_t maxSamples = 0, int Normalize = -1, double Scale = 1.);
1031
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);
1034
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);
1037
1038 //-----------------------------------------------------
1039 void Add_Value (double Value);
1040
1041 bool Add_Histogram (const CSG_Histogram &Histogram );
1042
1043 bool Scale_Element_Count (double Scale);
1044
1045 bool Update (void);
1046
1047 bool is_Okay (void) const { return( m_nClasses && Get_Element_Count() ); }
1048
1049 size_t Get_Class_Count (void) const { return( m_nClasses ); }
1050
1051 size_t Get_Element_Count (void) const { return( m_nClasses ? m_Cumulative[m_nClasses - 1] : 0 ); }
1052 size_t Get_Element_Maximum (void) const { return( m_nMaximum ); }
1053
1054 size_t Get_Elements (int i) const { return( Get_Elements ((size_t)i) ); }
1055 size_t Get_Elements (size_t i) const { return( i < m_nClasses ? m_Elements [i] : 0 ); }
1056
1057 size_t Get_Cumulative (int i) const { return( Get_Cumulative((size_t)i) ); }
1058 size_t Get_Cumulative (size_t i) const { return( i < m_nClasses ? m_Cumulative[i] : 0 ); }
1059
1060 double Get_Value (double i) const { return( m_nClasses < 1 ? m_Minimum : m_Minimum + i * m_ClassWidth ); }
1061
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)) ); }
1064
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)) ); }
1067
1068 //-----------------------------------------------------
1069 CSG_Histogram & operator = (const CSG_Histogram &Histogram);
1070
1071 void operator += (double Value) { Add_Value(Value); }
1072
1073 size_t operator [] (int i) const { return( Get_Elements(i) ); }
1074 size_t operator [] (size_t i) const { return( Get_Elements(i) ); }
1075
1076 double Get_Quantile (double Quantile) const;
1077 double Get_Quantile_Value (double Value) const;
1078
1079 double Get_Percentile (double Percentile) const;
1080 double Get_Percentile_Value(double Value) const;
1081
1082 const CSG_Simple_Statistics & Get_Statistics (void) const { return( m_Statistics ); }
1083
1084
1085private:
1086
1087 size_t m_nClasses = 0, m_nMaximum = 0, *m_Elements = NULL, *m_Cumulative = NULL;
1088
1089 double m_Minimum = 0., m_Maximum = 0., m_ClassWidth = 1.;
1090
1091 CSG_Simple_Statistics m_Statistics;
1092
1093
1094 void _On_Construction (void);
1095
1096 bool _Create (size_t nClasses, double Minimum, double Maximum);
1097
1098 bool _Update (sLong nElements);
1099
1100};
1101
1102
1104// //
1105// //
1106// //
1108
1109//---------------------------------------------------------
1111{
1112public:
1113 typedef enum EInterval
1114 {
1116 }
1118
1119 //-----------------------------------------------------
1120 CSG_Scaler(void);
1121
1122 CSG_Scaler (const CSG_Scaler &Scaler);
1123 bool Create (const CSG_Scaler &Scaler);
1124
1125 CSG_Scaler (double Minimum, double Maximum, int Mode = 0, double LogScale = 1.);
1126 bool Create (double Minimum, double Maximum, int Mode = 0, double LogScale = 1.);
1127
1128 CSG_Scaler & operator = (const CSG_Scaler &Scaler);
1129
1130 //-----------------------------------------------------
1131 bool Set_Range (double Minimum, double Maximum);
1132 double Get_Range (void) const { return( m_Range ); }
1133 double Get_Minimum (void) const { return( m_Minimum ); }
1134 double Get_Maximum (void) const { return( m_Minimum + m_Range ); }
1135
1136 bool Set_Mode (int Mode);
1137 TMode Get_Mode (void) const { return( m_Mode ); }
1138
1139 bool Set_LogScale (double LogScale);
1140 double Get_LogScale (void) const { return( m_LogScale[0] ); }
1141
1142 //-----------------------------------------------------
1143 bool Set_Linear (CSG_Table *pTable, int Field, double Minimum, double Maximum , int Mode = 0, double LogScale = 1.);
1144 bool Set_StdDev (CSG_Table *pTable, int Field, double StdDev, bool bKeepInRange, int Mode = 0, double LogScale = 1.);
1145 bool Set_Percentile (CSG_Table *pTable, int Field, double Minimum, double Maximum , int Mode = 0, double LogScale = 1.);
1146
1147 bool Set_Linear (CSG_Data_Object *pObject , double Minimum, double Maximum , int Mode = 0, double LogScale = 1.);
1148 bool Set_StdDev (CSG_Data_Object *pObject , double StdDev, bool bKeepInRange, int Mode = 0, double LogScale = 1.);
1149 bool Set_Percentile (CSG_Data_Object *pObject , double Minimum, double Maximum , int Mode = 0, double LogScale = 1.);
1150
1151 bool Set_Histogram (CSG_Table *pTable, int Field, int Normalize = -1, double Scale = 1.);
1152 bool Set_Histogram (CSG_Data_Object *pObject );
1153
1154 //-----------------------------------------------------
1155 double to_Relative (double Value) const
1156 {
1157 if( m_Range > 0. )
1158 {
1159 switch( m_Mode )
1160 {
1161 default : return( (Value - m_Minimum) / m_Range );
1162 case INCREASING: Value = (Value - m_Minimum) / m_Range; return( Value <= 0. ? 0. : (log(1. + m_LogScale[1] * ( Value)) / m_LogScale[2]) );
1163 case DECREASING: Value = (Value - m_Minimum) / m_Range; return( Value >= 1. ? 1. : 1. - (log(1. + m_LogScale[1] * (1. - Value)) / m_LogScale[2]) );
1164 case EQUALIZE : return( m_Histogram.Get_Quantile_Value(Value) );
1165 }
1166 }
1167
1168 return( 0. );
1169 }
1170
1171 //-----------------------------------------------------
1172 double from_Relative (double Value) const
1173 {
1174 if( m_Range > 0. )
1175 {
1176 switch( m_Mode )
1177 {
1178 default : break;
1179 case INCREASING: Value = ((exp(m_LogScale[2] * ( Value)) - 1.) / m_LogScale[1]); break;
1180 case DECREASING: Value = 1. - ((exp(m_LogScale[2] * (1. - Value)) - 1.) / m_LogScale[1]); break;
1181 case EQUALIZE : return( m_Histogram.Get_Quantile(Value) );
1182 }
1183
1184 return( m_Minimum + (m_Range * Value) );
1185 }
1186
1187 return( m_Minimum );
1188 }
1189
1190
1191protected:
1192
1194
1196
1197 double m_Minimum = 0., m_Range = 0., m_LogScale[3] = { 1., 10., 2.302585093 };
1198
1199
1200 bool _Update (CSG_Table *pTable, int Field, double Minimum, double Maximum, int Mode, double LogScale);
1201 bool _Update (CSG_Data_Object *pObject , double Minimum, double Maximum, int Mode, double LogScale);
1202
1203};
1204
1205
1207// //
1208// //
1209// //
1211
1212//---------------------------------------------------------
1214{
1215public:
1216 CSG_Natural_Breaks(void);
1217 virtual ~CSG_Natural_Breaks(void);
1218
1219 CSG_Natural_Breaks (class CSG_Table *pTable, int Field, int nClasses, int Histogram = 0);
1220 bool Create (class CSG_Table *pTable, int Field, int nClasses, int Histogram = 0);
1221
1222 CSG_Natural_Breaks (class CSG_Grid *pGrid , int nClasses, int Histogram = 0);
1223 bool Create (class CSG_Grid *pGrid , int nClasses, int Histogram = 0);
1224
1225 CSG_Natural_Breaks (class CSG_Grids *pGrids , int nClasses, int Histogram = 0);
1226 bool Create (class CSG_Grids *pGrids , int nClasses, int Histogram = 0);
1227
1228 CSG_Natural_Breaks (const CSG_Vector &Values , int nClasses, int Histogram = 0);
1229 bool Create (const CSG_Vector &Values , int nClasses, int Histogram = 0);
1230
1231 int Get_Count (void) const { return( m_Breaks.Get_N() ); }
1232 double Get_Break (int i) const { return( m_Breaks[i] ); }
1233
1234 double operator [] (int i) const { return( m_Breaks[i] ); }
1235
1236
1237private:
1238
1239 CSG_Histogram m_Histogram;
1240
1241 CSG_Vector m_Breaks, m_Values;
1242
1243
1244 bool _Histogram (int nClasses);
1245
1246 double _Get_Value (int i);
1247
1248 bool _Calculate (int nClasses);
1249
1250};
1251
1252
1254// //
1255// //
1256// //
1258
1259//---------------------------------------------------------
1266
1267//---------------------------------------------------------
1269{
1270public:
1272 virtual ~CSG_Cluster_Analysis(void);
1273
1274 bool Create (int nFeatures);
1275 bool Destroy (void);
1276
1277 bool Add_Element (void);
1278 bool Set_Feature (sLong iElement, int iFeature, double Value);
1279
1280 sLong Get_Cluster (sLong iElement) const { return( iElement >= 0 && iElement < Get_nElements() ? m_Clusters[iElement] : -1 ); }
1281
1282 bool Execute (int Method, int nClusters, int nMaxIterations = 0, int Initialization = 0);
1283
1284 sLong Get_nElements (void) const { return( m_Features.Get_Size() ); }
1285 int Get_nFeatures (void) const { return( m_nFeatures ); }
1286 int Get_nClusters (void) const { return( (int)m_nMembers.Get_Size() ); }
1287
1288 int Get_Iteration (void) const { return( m_Iteration ); }
1289
1290 double Get_SP (void) const { return( m_SP ); }
1291 double Get_WCSS (void) const { return( m_WCSS ); }
1292 double Get_Distortion (void) const { return( m_Distortion ); }
1293 double Get_Inertia (void) const { return( m_Inertia ); }
1294
1295 int Get_nMembers (int iCluster) const { return( m_nMembers[iCluster] ); }
1296 double Get_Variance (int iCluster) const { return( m_Variance[iCluster] ); }
1297 double Get_Centroid (int iCluster, int iFeature) const { return( m_Centroid[iCluster][iFeature] ); }
1298
1299
1300private:
1301
1302 int m_Iteration = 0, m_nFeatures = 0;
1303
1304 double m_SP = 0., m_WCSS = 0., m_Distortion = 0., m_Inertia = 0.;
1305
1306 CSG_Array_Int m_Clusters, m_nMembers;
1307
1308 CSG_Array m_Features;
1309
1310 CSG_Vector m_Variance;
1311
1312 CSG_Matrix m_Centroid;
1313
1314
1315 bool _Update_Clusters (void);
1316
1317 bool _Minimum_Distance (bool bInitialize, int nMaxIterations);
1318
1319 bool _Hill_Climbing (bool bInitialize, int nMaxIterations);
1320
1321};
1322
1323
1325// //
1326// //
1327// //
1329
1330//---------------------------------------------------------
1343
1344//---------------------------------------------------------
1346{
1347public:
1349 virtual ~CSG_Classifier_Supervised(void);
1350
1351 void Create (int nFeatures);
1352 void Destroy (void);
1353
1354 bool Load (const CSG_String &File);
1355 bool Save (const CSG_String &File, const SG_Char *Feature_Info = NULL);
1356
1357 bool Train_Clr_Samples (void);
1358 bool Train_Add_Sample (const CSG_String &Class_ID, const CSG_Vector &Features);
1359 bool Train (bool bClr_Samples = false);
1360
1361 bool Add_Class (const CSG_String &Class_ID, const CSG_Vector &Mean, const CSG_Vector &Min, const CSG_Vector &Max, const CSG_Matrix &Cov);
1362
1363 CSG_String Print (void);
1364
1365 //-----------------------------------------------------
1366 int Get_Feature_Count (void) { return( m_nFeatures ); }
1367
1368 int Get_Class_Count (void) { return( m_nClasses ); }
1369
1370 const CSG_String & Get_Class_ID (int iClass) { return( m_pClasses[iClass]->m_ID ); }
1371 double Get_Class_Mean (int iClass, int iFeature) { return( m_pClasses[iClass]->m_Mean[iFeature] ); }
1372 double Get_Class_Minimum (int iClass, int iFeature) { return( m_pClasses[iClass]->m_Min [iFeature] ); }
1373 double Get_Class_Maximum (int iClass, int iFeature) { return( m_pClasses[iClass]->m_Max [iFeature] ); }
1374
1375 int Get_Class (const CSG_String &Class_ID);
1376 bool Get_Class (const CSG_Vector &Features, int &Class, double &Quality, int Method);
1377
1378 //-----------------------------------------------------
1379 void Set_Threshold_Distance (double Value);
1380 double Get_Threshold_Distance (void);
1381
1382 void Set_Threshold_Angle (double Value);
1383 double Get_Threshold_Angle (void);
1384
1385 void Set_Threshold_Probability (double Value);
1386 double Get_Threshold_Probability (void);
1387
1388 void Set_Probability_Relative (bool Value);
1389 bool Get_Probability_Relative (void);
1390
1391 void Set_WTA (int Method, bool bOn);
1392 bool Get_WTA (int Method);
1393
1394 static CSG_String Get_Name_of_Method (int Method);
1395 static CSG_String Get_Name_of_Quality (int Method);
1396
1397
1398private:
1399
1400 //-----------------------------------------------------
1401 class CClass
1402 {
1403 public:
1404 CClass(const CSG_String &ID) : m_ID(ID) {}
1405
1406 CSG_String m_ID;
1407
1408 double m_Cov_Det = 0., m_Mean_Spectral = 0.;
1409
1410 CSG_Vector m_Mean, m_Min, m_Max;
1411
1412 CSG_Matrix m_Cov, m_Cov_Inv, m_Samples;
1413
1414
1415 bool Train (void);
1416
1417 };
1418
1419 //-----------------------------------------------------
1420 bool m_Probability_Relative, m_bWTA[SG_CLASSIFY_SUPERVISED_WTA];
1421
1422 int m_nFeatures, m_nClasses;
1423
1424 double m_Threshold_Distance, m_Threshold_Probability, m_Threshold_Angle;
1425
1426 CSG_String m_Info;
1427
1428 CClass **m_pClasses;
1429
1430
1431 void _Get_Binary_Encoding (const CSG_Vector &Features, int &Class, double &Quality);
1432 void _Get_Parallel_Epiped (const CSG_Vector &Features, int &Class, double &Quality);
1433 void _Get_Minimum_Distance (const CSG_Vector &Features, int &Class, double &Quality);
1434 void _Get_Mahalanobis_Distance (const CSG_Vector &Features, int &Class, double &Quality);
1435 void _Get_Maximum_Likelihood (const CSG_Vector &Features, int &Class, double &Quality);
1436 void _Get_Spectral_Angle_Mapping (const CSG_Vector &Features, int &Class, double &Quality);
1437 void _Get_Spectral_Divergence (const CSG_Vector &Features, int &Class, double &Quality);
1438 void _Get_Winner_Takes_All (const CSG_Vector &Features, int &Class, double &Quality);
1439
1440};
1441
1442
1444// //
1445// //
1446// //
1448
1449//---------------------------------------------------------
1450#ifdef WITH_MRMR
1451
1452//---------------------------------------------------------
1453enum ESG_mRMR_Method
1454{
1455 SG_mRMR_Method_MID = 0, // Mutual Information Difference (MID)
1456 SG_mRMR_Method_MIQ // Mutual Information Quotient (MIQ)
1457};
1458
1459//---------------------------------------------------------
1460class SAGA_API_DLL_EXPORT CSG_mRMR
1461{
1462public:
1463
1464 CSG_mRMR(void);
1465 virtual ~CSG_mRMR(void);
1466
1467 void Destroy (void);
1468
1469 static CSG_String Get_Description (void);
1470
1471 static bool Parameters_Add (class CSG_Parameters *pParameters, class CSG_Parameter *pNode = NULL);
1472 static int Parameters_Enable (class CSG_Parameters *pParameters, class CSG_Parameter *pParameter);
1473
1474 void Set_Verbose (bool bOn = true) { m_bVerbose = bOn; }
1475
1476 bool Set_Data (CSG_Table &Data, int ClassField, class CSG_Parameters *pParameters);
1477 bool Set_Data (CSG_Matrix &Data, int ClassField, class CSG_Parameters *pParameters);
1478 bool Set_Data (CSG_Table &Data, int ClassField = 0, double Threshold = -1.);
1479 bool Set_Data (CSG_Matrix &Data, int ClassField = 0, double Threshold = -1.);
1480
1481 bool Get_Selection (class CSG_Parameters *pParameters);
1482 bool Get_Selection (int nFeatures, int Method);
1483
1484 int Get_Count (void) const;
1485 int Get_Index (int i) const;
1486 CSG_String Get_Name (int i) const;
1487 double Get_Score (int i) const;
1488
1489
1490private:
1491
1492 bool m_bDiscretized, m_bVerbose;
1493
1494 long m_nSamples, m_nVars;
1495
1496 double **m_Samples;
1497
1498 CSG_Strings m_VarNames;
1499
1500 class CSG_Table *m_pSelection;
1501
1502
1503 bool Get_Memory (int nVars, int nSamples);
1504
1505 bool Discretize (double Threshold);
1506
1507 double Get_MutualInfo (long v1, long v2);
1508 double Get_MutualInfo (double *pab, long pabhei, long pabwid);
1509
1510 template <class T> double * Get_JointProb (T *img1, T *img2, long len, long maxstatenum, int &nstate1, int &nstate2);
1511 template <class T> void Copy_Vector (T *srcdata, long len, int *desdata, int &nstate);
1512
1513
1514 typedef struct SPool
1515 {
1516 char Mask;
1517 long Index;
1518 double mival;
1519 }
1520 TPool;
1521
1522 static int Pool_Compare (const void *a, const void *b);
1523
1524};
1525
1526//---------------------------------------------------------
1527#endif // WITH_MRMR
1528
1529
1531// //
1532// //
1533// //
1535
1536//---------------------------------------------------------
1538{
1539public:
1540 CSG_Spline(void);
1541 virtual ~CSG_Spline(void);
1542
1543 void Destroy (void);
1544
1545 bool Create (double *xValues, double *yValues, int nValues, double yA = 1.0e30, double yB = 1.0e30);
1546 bool Create (double yA = 1.0e30, double yB = 1.0e30);
1547
1548 void Add (double x, double y);
1549
1550 int Get_Count (void) const { return( m_x.Get_N() ); }
1551 double Get_xMin (void) const { return( m_x.Get_N() > 0 ? m_x(0 ) : 0. ); }
1552 double Get_xMax (void) const { return( m_x.Get_N() > 0 ? m_x(m_x.Get_Size() - 1) : 0. ); }
1553 double Get_x (int i) const { return( i >= 0 && i < m_x.Get_N() ? m_x(i) : 0. ); }
1554 double Get_y (int i) const { return( i >= 0 && i < m_y.Get_N() ? m_y(i) : 0. ); }
1555
1556 bool Get_Value (double x, double &y);
1557 double Get_Value (double x);
1558
1559
1560protected:
1561
1563
1565
1566
1567 bool _Create (double yA, double yB);
1568
1569};
1570
1571//---------------------------------------------------------
1573{
1574public:
1576 virtual ~CSG_Thin_Plate_Spline(void);
1577
1578 bool Destroy (void);
1579
1580 bool Set_Point_Count (int Count) { return( m_Points.Set_Count(Count) ); }
1581 int Get_Point_Count (void) { return( (int)m_Points.Get_Count() ); }
1582
1583 CSG_Points_3D & Get_Points (void) { return( m_Points ); }
1584
1585 bool Add_Point (double x, double y, double z) { return( m_Points.Add( x, y, z) ); }
1586 bool Add_Point (const TSG_Point &p, double z) { return( m_Points.Add(p.x, p.y, z) ); }
1587
1588 bool Set_Point (int Index, double x, double y, double z)
1589 {
1590 if( Index >= 0 && Index < m_Points.Get_Count() )
1591 {
1592 m_Points[Index].x = x;
1593 m_Points[Index].y = y;
1594 m_Points[Index].z = z;
1595
1596 return( true );
1597 }
1598
1599 return( false );
1600 }
1601
1602 bool Set_Point (int Index, const TSG_Point &p, double z) { return( Set_Point(Index, p.x, p.y, z) ); }
1603
1604 bool Create (double Regularization = 0., bool bSilent = true);
1605
1606 bool is_Okay (void) { return( m_V.Get_N() > 0 ); }
1607
1608 double Get_Value (double x, double y);
1609
1610
1611private:
1612
1613 CSG_Points_3D m_Points;
1614
1615 CSG_Vector m_V;
1616
1617
1618 double _Get_hDistance (TSG_Point_3D A, TSG_Point_3D B);
1619 double _Get_Base_Funtion (double x);
1620 double _Get_Base_Funtion (TSG_Point_3D A, double x, double y);
1621
1622};
1623
1624
1626// //
1627// //
1628// //
1630
1631//---------------------------------------------------------
1640
1641//---------------------------------------------------------
1643{
1644public:
1645
1646 static double Get_F_Tail_from_R2 (double R2, int nPredictors, int nSamples, TSG_Test_Distribution_Type Type = TESTDIST_TYPE_Right);
1647
1648 static double Get_F_Tail (double F , int dfn, int dfd, TSG_Test_Distribution_Type Type = TESTDIST_TYPE_Right);
1649 static double Get_F_Inverse (double alpha, int dfn, int dfd, TSG_Test_Distribution_Type Type = TESTDIST_TYPE_Right);
1650
1651 static double Get_T_Tail (double T , int df, TSG_Test_Distribution_Type Type = TESTDIST_TYPE_Right);
1652 static double Get_T_Inverse (double alpha, int df, TSG_Test_Distribution_Type Type = TESTDIST_TYPE_Right);
1653
1654 static double Get_Norm_P (double Z);
1655 static double Get_Norm_Z (double P);
1656
1657
1658private:
1659
1660 static double Get_Gamma (double F, double dfn, double dfd);
1661 static double Get_Log_Gamma (double a);
1662
1663 static double Get_T_P (double T, int df);
1664 static double Get_T_Z (double T, int df);
1665 static double Get_T_Inv (double p, int df);
1666
1667 static double _Change_Tail_Type (double p, TSG_Test_Distribution_Type from, TSG_Test_Distribution_Type to, bool bNegative);
1668
1669};
1670
1671
1673// //
1674// //
1675// //
1677
1678//---------------------------------------------------------
1679// Values: (matrix) array with number of variables = number of rows (x), number of samples = number of columns (y)
1680SAGA_API_DLL_EXPORT CSG_Matrix SG_Get_Correlation_Matrix (const CSG_Matrix &Values, bool bCovariances = false);
1681
1682
1684// //
1685// //
1686// //
1688
1689//---------------------------------------------------------
1701
1702//---------------------------------------------------------
1703SAGA_API_DLL_EXPORT double SG_Regression_Get_Adjusted_R2 (double R2, int nSamples, int nPredictors, TSG_Regression_Correction Correction = REGRESSION_CORR_Wherry_1);
1704
1705
1707// //
1709
1710//---------------------------------------------------------
1711typedef enum
1712{
1713 REGRESSION_Linear = 0, // Y = a + b * X
1714 REGRESSION_Rez_X, // Y = a + b / X
1715 REGRESSION_Rez_Y, // Y = a / (b - X)
1716 REGRESSION_Pow, // Y = a * X^b
1717 REGRESSION_Exp, // Y = a * e^(b * X)
1718 REGRESSION_Log // Y = a + b * ln(X)
1719}
1721
1722//---------------------------------------------------------
1724{
1725public:
1726 CSG_Regression(void);
1727 virtual ~CSG_Regression(void);
1728
1729 void Destroy (void);
1730
1731 bool Set_Values (int nValues, double *x, double *y);
1732 bool Add_Values (double x, double y);
1733
1734 int Get_Count (void) const { return( (int)m_x.Get_Size() ); }
1735
1736 double Get_xValue (int i) const { return( i >= 0 && i < Get_Count() ? m_x[i] : 0. ); }
1737 double Get_yValue (int i) const { return( i >= 0 && i < Get_Count() ? m_y[i] : 0. ); }
1738 bool Get_Values (int i, double &x, double &y) const
1739 {
1740 if( i >= 0 && i < Get_Count() )
1741 {
1742 x = m_x[i];
1743 y = m_y[i];
1744
1745 return( true );
1746 }
1747
1748 return( false );
1749 }
1750
1751 double Get_xMin (void) const { return( m_xMin ); }
1752 double Get_xMax (void) const { return( m_xMax ); }
1753 double Get_xMean (void) const { return( m_xMean ); }
1754 double Get_xVariance (void) const { return( m_xVar ); }
1755 double Get_x (double y) const; // returns INF on error, this can be checked using the _finite() function (libc, include <float.h>)...
1756
1757 double Get_yMin (void) const { return( m_yMin ); }
1758 double Get_yMax (void) const { return( m_yMax ); }
1759 double Get_yMean (void) const { return( m_yMean ); }
1760 double Get_yVariance (void) const { return( m_yVar ); }
1761 double Get_y (double x) const; // returns INF on error, this can be checked using the _finite() function (libc, include <float.h>)...
1762
1763 double Get_Constant (void) const { return( m_RConst ); }
1764 double Get_Coefficient (void) const { return( m_RCoeff ); }
1765 double Get_R (void) const { return( m_R ); }
1766 double Get_R2 (void) const { return( m_R2 ); }
1767 double Get_R2_Adj (void) const { return( m_R2_Adj ); }
1768 double Get_P (void) const { return( m_P ); }
1769 double Get_StdError (void) const { return( m_SE ); }
1770
1771 const SG_Char * asString (void);
1772
1773 TSG_Regression_Type Get_Type (void) const { return( m_Type ); }
1774
1775 bool Calculate ( TSG_Regression_Type Type = REGRESSION_Linear, bool bStdError = false);
1776 bool Calculate (int nValues, double *x, double *y, TSG_Regression_Type Type = REGRESSION_Linear, bool bStdError = false);
1777
1778
1779protected:
1780
1784
1786
1788
1789
1790 double _Y_Transform (double x);
1791 double _X_Transform (double y);
1792
1793};
1794
1795
1797// //
1799
1800//---------------------------------------------------------
1814
1815//---------------------------------------------------------
1817{
1818public:
1819 CSG_Regression_Multiple(bool bIntercept = true);
1820 virtual ~CSG_Regression_Multiple(void);
1821
1822 void Destroy (void);
1823
1824 bool Set_Data (const CSG_Matrix &Samples, CSG_Strings *pNames = NULL);
1825
1826 void Set_With_Intercept (bool bOn = true) { m_bIntercept = bOn; }
1827 bool Get_With_Intercept (void) const { return( m_bIntercept ); }
1828
1829 bool Get_Model (const CSG_Matrix &Samples , CSG_Strings *pNames = NULL);
1830 bool Get_Model_Forward (const CSG_Matrix &Samples, double P_in , CSG_Strings *pNames = NULL);
1831 bool Get_Model_Backward (const CSG_Matrix &Samples, double P_out , CSG_Strings *pNames = NULL);
1832 bool Get_Model_Stepwise (const CSG_Matrix &Samples, double P_in, double P_out, CSG_Strings *pNames = NULL);
1833
1834 bool Get_Model (void);
1835 bool Get_Model_Forward (double P_in);
1836 bool Get_Model_Backward (double P_out);
1837 bool Get_Model_Stepwise (double P_in, double P_out);
1838
1839 bool Get_CrossValidation (int nSubSamples = 0);
1840
1841 CSG_String Get_Info (void) const;
1842 class CSG_Table * Get_Info_Regression (void) const { return( m_pRegression ); }
1843 class CSG_Table * Get_Info_Model (void) const { return( m_pModel ); }
1844 class CSG_Table * Get_Info_Steps (void) const { return( m_pSteps ); }
1845
1846 double Get_R2 (void) const;
1847 double Get_R2_Adj (void) const;
1848 double Get_StdError (void) const;
1849 double Get_F (void) const;
1850 double Get_P (void) const;
1851 double Get_CV_RMSE (void) const;
1852 double Get_CV_NRMSE (void) const;
1853 double Get_CV_R2 (void) const;
1854 int Get_CV_nSamples (void) const;
1855 int Get_DegFreedom (void) const;
1856 int Get_nSamples (void) const;
1857 int Get_nPredictors (void) const;
1858 int Get_Predictor (int i) const { return( i >= 0 && i < Get_nPredictors() ? m_Predictor[i] : -1 ); }
1859
1860 double Get_RConst (void) const;
1861 const SG_Char * Get_Name (int iVariable) const;
1862 double Get_ID (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_ID ) ); }
1863 double Get_RCoeff (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_RCOEFF) ); }
1864 double Get_R2_Partial (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_R2 ) ); }
1865 double Get_R2_Partial_Adj (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_R2_ADJ) ); }
1866 double Get_StdError (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_SE ) ); }
1867 double Get_T (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_T ) ); }
1868 double Get_P (int iVariable) const { return( Get_Parameter(iVariable, MLR_VAR_SIG ) ); }
1869
1870 double Get_Parameter (int iVariable, int Parameter) const;
1871
1872 double Get_Value (const CSG_Vector &Predictors) const;
1873 bool Get_Value (const CSG_Vector &Predictors, double &Value) const;
1874
1875 double Get_Residual (int iSample) const;
1876 bool Get_Residual (int iSample, double &Residual) const;
1877
1878 bool Get_Residuals (CSG_Vector &Residuals) const;
1879
1880
1881protected:
1882
1884
1886
1888
1890
1892
1893
1894 bool _Initialize (bool bInclude);
1895
1896 double _Get_F (int nPredictors, int nSamples, double r2_full, double r2_reduced);
1897 double _Get_P (int nPredictors, int nSamples, double r2_full, double r2_reduced);
1898
1899 bool _Get_Regression (const class CSG_Matrix &Samples);
1900
1901 int _Get_Step_In (CSG_Matrix &X, double P_in , double &R2, const CSG_Matrix &Samples);
1902 int _Get_Step_Out (CSG_Matrix &X, double P_out, double &R2);
1903
1904 bool _Set_Step_Info (const CSG_Matrix &X);
1905 bool _Set_Step_Info (const CSG_Matrix &X, double R2_prev, int iVariable, bool bIn);
1906
1907};
1908
1909
1911// //
1913
1914//---------------------------------------------------------
1916{
1917public:
1919 virtual ~CSG_Regression_Weighted(void);
1920
1921 bool Destroy (void);
1922
1923 bool Add_Sample (double Weight, double Dependent, const CSG_Vector &Predictors);
1924 int Get_Sample_Count (void) const { return( m_X.Get_NY() ); }
1925 int Get_Predictor_Count (void) const { return( m_X.Get_NX() - 1 ); }
1926
1927 bool Calculate (const CSG_Vector &Weights, const CSG_Vector &Dependents, const CSG_Matrix &Predictors, bool bLogistic = false);
1928 bool Calculate (bool bLogistic = false);
1929
1930 double Get_R2 (void) const { return( m_r2 ); }
1931 const CSG_Vector & Get_RCoeff (void) const { return( m_b ); }
1932 double Get_RCoeff (int i) const { return( m_b[i] ); }
1933 double operator [] (int i) const { return( m_b[i] ); }
1934
1935 //-----------------------------------------------------
1936 int Get_Log_maxIter (void) const { return( m_Log_maxIter ); }
1937 double Get_Log_Epsilon (void) const { return( m_Log_Epsilon ); }
1938 double Get_Log_Difference (void) const { return( m_Log_Difference ); }
1939
1940 bool Set_Log_maxIter (int maxIter );
1941 bool Set_Log_Epsilon (double Epsilon );
1942 bool Set_Log_Difference (double Difference);
1943
1944 //-----------------------------------------------------
1945 bool Get_CrossValidation (int nSubSamples = 0);
1946
1947 int Get_CV_nSamples (void) const { return( m_CV_nSamples ); }
1948 double Get_CV_RMSE (void) const { return( m_CV_RMSE ); }
1949 double Get_CV_NRMSE (void) const { return( m_CV_NRMSE ); }
1950 double Get_CV_R2 (void) const { return( m_CV_R2 ); }
1951
1952
1953private:
1954
1955 int m_Log_maxIter, m_CV_nSamples;
1956
1957 double m_r2, m_Log_Epsilon, m_Log_Difference, m_CV_RMSE, m_CV_NRMSE, m_CV_R2;
1958
1959 CSG_Vector m_y, m_w, m_b;
1960
1961 CSG_Matrix m_X;
1962
1963
1964 CSG_Vector _Log_Get_Beta (const CSG_Matrix &X, const CSG_Vector &y, const CSG_Vector &w);
1965 CSG_Vector _Log_Get_Beta (const CSG_Vector &b, const CSG_Matrix &X, const CSG_Vector &y, const CSG_Vector &w, const CSG_Vector &p);
1966 CSG_Matrix _Log_Get_Xwp (const CSG_Vector &p, const CSG_Matrix &X, const CSG_Vector &w);
1967 CSG_Vector _Log_Get_Ywp (const CSG_Vector &p, const CSG_Vector &y, const CSG_Vector &w);
1968 CSG_Vector _Log_Get_Props (const CSG_Matrix &X, const CSG_Vector &b);
1969 bool _Log_NoChange (const CSG_Vector &b_old, const CSG_Vector &b_new);
1970 bool _Log_OutOfControl (const CSG_Vector &b_old, const CSG_Vector &b_new);
1971
1972};
1973
1974
1976// //
1977// Formula Parser (A. Ringeler) //
1978// //
1980
1981//---------------------------------------------------------
1982typedef double (*TSG_Formula_Function_0)(void);
1983typedef double (*TSG_Formula_Function_1)(double);
1984typedef double (*TSG_Formula_Function_2)(double, double);
1985typedef double (*TSG_Formula_Function_3)(double, double, double);
1986
1987//---------------------------------------------------------
1989{
1990public:
1991 CSG_Formula(void);
1992 virtual ~CSG_Formula(void);
1993
1994 bool Destroy (void);
1995
1996 static CSG_String Get_Help_Operators (bool bHTML = true, const CSG_String Additional[][2] = NULL);
1997
1998 bool Get_Error (CSG_String &Message);
1999
2000 bool Add_Function (const char *Name, TSG_Formula_Function_1 Function, int nParameters, bool bVarying = false);
2001
2002 bool Set_Formula (const CSG_String &Formula);
2003 CSG_String Get_Formula (void) const { return( m_sFormula ); }
2004
2005 void Set_Variable (char Variable, double Value);
2006
2007 double Get_Value (void ) const;
2008 double Get_Value (double x ) const;
2009 double Get_Value (const CSG_Vector &Values ) const;
2010 double Get_Value (double *Values, int nValues) const;
2011 double Get_Value (const char *Arguments, ... ) const;
2012
2013 const char * Get_Used_Variables (void);
2014
2015
2016 //-----------------------------------------------------
2017 typedef struct SSG_Function
2018 {
2019 const char *Name;
2020
2022
2024
2026 }
2028
2029
2030private:
2031
2032 //-----------------------------------------------------
2033 typedef struct SSG_Formula
2034 {
2035 char *code;
2036
2037 double *ctable;
2038 }
2039 TSG_Formula;
2040
2041
2042 //-----------------------------------------------------
2043 bool m_bError, m_Vars_Used[256];
2044
2045 int m_Error_Position, m_Length;
2046
2047 TSG_Formula m_Formula;
2048
2049 TSG_Function *m_Functions;
2050
2051
2052 CSG_String m_sFormula, m_sError;
2053
2054 const char *m_error;
2055
2056 int m_pctable;
2057
2058 double m_Parameters[32], *m_ctable;
2059
2060
2061 void _Set_Error (const CSG_String &Error = "");
2062
2063 double _Get_Value (const double *Parameters, TSG_Formula Function) const;
2064
2065 int _is_Operand (char c);
2066 int _is_Operand_Code (char c);
2067 int _is_Number (char c);
2068
2069 int _Get_Function (int i, char *Name, int *nParameters, int *bVarying);
2070 int _Get_Function (const char *Name);
2071
2072 TSG_Formula _Translate (const char *source, const char *args, int *length, int *error);
2073
2074 char * _i_trans (char *function, char *begin, char *end);
2075 char * _comp_time (char *function, char *fend, int npars);
2076 int _max_size (const char *source);
2077 char * _my_strtok (char *s);
2078
2079};
2080
2081
2083// //
2084// //
2085// //
2087
2088//---------------------------------------------------------
2097
2098//---------------------------------------------------------
2100{
2101public:
2102 CSG_Trend(void);
2103
2104 bool Set_Formula (const CSG_String &Formula);
2106
2107 int Get_Parameter_Count (void) const { return( m_Params .Get_Count() ); }
2108 double * Get_Parameters (void) const { return( m_Params.m_A.Get_Data() ); }
2109 bool Init_Parameter (const SG_Char &Variable, double Value);
2110
2111 void Clr_Data (void);
2112 bool Add_Data (double x, double y);
2113 void Set_Data (double *x, double *y, int n, bool bAdd = false);
2114 void Set_Data (const CSG_Points &Data , bool bAdd = false);
2115 int Get_Data_Count (void) const { return( (int)m_Data[0].Get_Count() ); }
2116 double Get_Data_X (int i) const { return( m_Data[0][i] ); }
2117 double Get_Data_XMin (void) { return( m_Data[0].Get_Minimum() ); }
2118 double Get_Data_XMax (void) { return( m_Data[0].Get_Maximum() ); }
2119 CSG_Simple_Statistics & Get_Data_XStats (void) { return( m_Data[0] ); }
2120 double Get_Data_Y (int i) const { return( m_Data[1][i] ); }
2121 double Get_Data_YMin (void) { return( m_Data[1].Get_Minimum() ); }
2122 double Get_Data_YMax (void) { return( m_Data[1].Get_Maximum() ); }
2123 CSG_Simple_Statistics & Get_Data_YStats (void) { return( m_Data[1] ); }
2124
2125 bool Set_Max_Iterations (int Iterations);
2126 int Get_Max_Iterations (void) const { return( m_Iter_Max); }
2127 bool Set_Max_Lambda (double Lambda);
2128 double Get_Max_Lambda (void) const { return( m_Lambda_Max); }
2129
2130 bool Get_Trend (double *x, double *y, int n, const CSG_String &Formula);
2131 bool Get_Trend (const CSG_Points &Data , const CSG_String &Formula);
2132 bool Get_Trend (const CSG_String &Formula);
2133 bool Get_Trend (void);
2134
2135 bool is_Okay (void) const { return( m_bOkay ); }
2136
2137 CSG_String Get_Error (void);
2138
2139 double Get_ChiSquare (void) const { return( m_bOkay ? m_ChiSqr : 0. ); }
2140 double Get_R2 (void) const { return( m_bOkay ? m_ChiSqr_o : 0. ); }
2141
2142 double Get_Value (double x) const { return( m_bOkay ? m_Formula.Get_Value(x) : 0. ); }
2143
2144
2145private:
2146
2147 //-----------------------------------------------------
2148 class SAGA_API_DLL_EXPORT CParams
2149 {
2150 public:
2151 CParams(void) {}
2152
2153 bool Create (const CSG_String &Variables);
2154 bool Destroy (void);
2155
2156 int Get_Count (void) const { return( (int)m_Variables.Length() ); }
2157
2158
2159 CSG_String m_Variables;
2160
2161 CSG_Vector m_A, m_Atry, m_dA, m_dA2, m_Beta;
2162
2163 CSG_Matrix m_Alpha, m_Covar;
2164
2165 };
2166
2167
2168 //-----------------------------------------------------
2169 bool m_bOkay;
2170
2171 int m_Iter_Max;
2172
2173 double m_ChiSqr, m_ChiSqr_o, m_Lambda, m_Lambda_Max;
2174
2175 CParams m_Params;
2176
2177 CSG_Simple_Statistics m_Data[2];
2178
2179 CSG_Formula m_Formula;
2180
2181
2182 bool _Fit_Function (void);
2183 bool _Get_Gaussj (void);
2184 bool _Get_mrqcof (CSG_Vector &Parameters, CSG_Matrix &Alpha, CSG_Vector &Beta);
2185
2186 void _Get_Function (double &y, double *dy_da, double x, const double *Parameters);
2187
2188};
2189
2190
2192// //
2193// //
2194// //
2196
2197//---------------------------------------------------------
2199{
2200public:
2201 CSG_Trend_Polynom(void);
2202
2203 bool Destroy (void);
2204
2205 bool Set_Order (int Order = 1);
2206
2207 bool Clr_Data (void);
2208 bool Set_Data (double *x, double *y, int n, bool bAdd = false);
2209 bool Add_Data (double x, double y);
2210 int Get_Data_Count (void) const { return( m_x.Get_N() ); }
2211 double Get_Data_X (int i) const { return( m_x(i) ); }
2212 double Get_Data_Y (int i) const { return( m_y(i) ); }
2213
2214 bool Get_Trend (void);
2215
2216 int Get_Order (void) const { return( m_Order ); }
2217 int Get_nCoefficients (void) const { return( m_Order + 1 ); }
2218 double Get_Coefficient (int i) const { return( m_a(i) ); }
2219 double Get_R2 (void) const { return( m_r2 ); }
2220
2221 double Get_Value (double x) const;
2222
2223
2224private:
2225
2226 double m_r2;
2227
2228 int m_Order;
2229
2230 CSG_Vector m_x, m_y, m_a;
2231
2232};
2233
2234
2236// //
2237// //
2238// //
2240
2241//---------------------------------------------------------
2242#endif // #ifndef HEADER_INCLUDED__SAGA_API__mat_tools_H
signed long long sLong
Definition api_core.h:158
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
TSG_Data_Type
Definition api_core.h:1043
@ SG_DATATYPE_String
Definition api_core.h:1055
#define SG_Char
Definition api_core.h:536
SAGA_API_DLL_EXPORT CSG_String operator+(const char *A, const CSG_String &B)
void Create(TSG_Data_Type Type=SG_DATATYPE_String)
bool Get_Majority(CSG_String &Value, int &Count)
Definition mat_tools.h:987
int Add_Value(int Value)
bool Get_Minority(int &Value, int &Count)
Definition mat_tools.h:993
bool Get_Majority(int &Value, int &Count)
Definition mat_tools.h:985
bool Get_Minority(double &Value)
Definition mat_tools.h:991
bool Get_Category(int iCategory, int &Value, int &Count) const
Definition mat_tools.h:957
int Get_Category(int Value) const
bool Get_Majority(CSG_String &Value)
Definition mat_tools.h:984
bool Get_Minority(CSG_String &Value)
Definition mat_tools.h:992
bool Get_Category(int iCategory, double &Value, int &Count) const
Definition mat_tools.h:965
bool Get_Minority(int &Value)
Definition mat_tools.h:990
bool Get_Majority(double &Value, int &Count)
Definition mat_tools.h:986
bool Get_Majority(double &Value)
Definition mat_tools.h:983
int asInt(int iCategory) const
bool Get_Minority(CSG_String &Value, int &Count)
Definition mat_tools.h:995
bool Get_Minority(double &Value, int &Count)
Definition mat_tools.h:994
int Get_Count(void) const
CSG_Category_Statistics(TSG_Data_Type Type=SG_DATATYPE_String)
bool Get_Category(int iCategory, CSG_String &Value, int &Count) const
Definition mat_tools.h:973
CSG_String asString(int iCategory) const
TSG_Data_Type Get_Category_Type(void) const
bool Get_Majority(int &Value)
Definition mat_tools.h:982
void Create(int nFeatures)
double Get_Class_Minimum(int iClass, int iFeature)
Definition mat_tools.h:1372
bool Add_Class(const CSG_String &Class_ID, const CSG_Vector &Mean, const CSG_Vector &Min, const CSG_Vector &Max, const CSG_Matrix &Cov)
bool Train(bool bClr_Samples=false)
const CSG_String & Get_Class_ID(int iClass)
Definition mat_tools.h:1370
bool Train_Add_Sample(const CSG_String &Class_ID, const CSG_Vector &Features)
bool Save(const CSG_String &File, const SG_Char *Feature_Info=NULL)
double Get_Class_Mean(int iClass, int iFeature)
Definition mat_tools.h:1371
bool Load(const CSG_String &File)
double Get_Class_Maximum(int iClass, int iFeature)
Definition mat_tools.h:1373
double Get_Inertia(void) const
Definition mat_tools.h:1293
bool Create(int nFeatures)
int Get_nClusters(void) const
Definition mat_tools.h:1286
int Get_nFeatures(void) const
Definition mat_tools.h:1285
double Get_WCSS(void) const
Definition mat_tools.h:1291
double Get_SP(void) const
Definition mat_tools.h:1290
sLong Get_Cluster(sLong iElement) const
Definition mat_tools.h:1280
double Get_Centroid(int iCluster, int iFeature) const
Definition mat_tools.h:1297
int Get_nMembers(int iCluster) const
Definition mat_tools.h:1295
double Get_Variance(int iCluster) const
Definition mat_tools.h:1296
bool Set_Feature(sLong iElement, int iFeature, double Value)
sLong Get_nElements(void) const
Definition mat_tools.h:1284
int Get_Iteration(void) const
Definition mat_tools.h:1288
double Get_Distortion(void) const
Definition mat_tools.h:1292
bool Set_Formula(const CSG_String &Formula)
static CSG_String Get_Help_Operators(bool bHTML=true, const CSG_String Additional[][2]=NULL)
CSG_String Get_Formula(void) const
Definition mat_tools.h:2003
bool Add_Function(const char *Name, TSG_Formula_Function_1 Function, int nParameters, bool bVarying=false)
bool Destroy(void)
bool Get_Error(CSG_String &Message)
struct CSG_Formula::SSG_Function TSG_Function
int Get_nPoints(int iRadius)
Definition mat_tools.h:622
CSG_Grid_Radius(int maxRadius=0)
double Get_Point(int iRadius, int iPoint, int xOffset, int yOffset, int &x, int &y)
Definition mat_tools.h:663
double Get_Point(int iRadius, int iPoint, int &x, int &y)
Definition mat_tools.h:650
double Get_Point(int iPoint, int &x, int &y)
Definition mat_tools.h:624
double Get_Point(int iPoint, int xOffset, int yOffset, int &x, int &y)
Definition mat_tools.h:637
bool Create(int maxRadius)
int Get_nPoints(void)
Definition mat_tools.h:621
int Get_Maximum(void)
Definition mat_tools.h:619
size_t Get_Elements(size_t i) const
Definition mat_tools.h:1055
size_t Get_Element_Maximum(void) const
Definition mat_tools.h:1052
bool Scale_Element_Count(double Scale)
const CSG_Simple_Statistics & Get_Statistics(void) const
Definition mat_tools.h:1082
double Get_Break(size_t i) const
Definition mat_tools.h:1063
double Get_Center(int i) const
Definition mat_tools.h:1065
void Add_Value(double Value)
double Get_Value(double i) const
Definition mat_tools.h:1060
size_t Get_Class_Count(void) const
Definition mat_tools.h:1049
double Get_Center(size_t i) const
Definition mat_tools.h:1066
bool is_Okay(void) const
Definition mat_tools.h:1047
size_t Get_Cumulative(int i) const
Definition mat_tools.h:1057
bool Create(const CSG_Histogram &Histogram)
bool Destroy(void)
size_t Get_Cumulative(size_t i) const
Definition mat_tools.h:1058
size_t Get_Elements(int i) const
Definition mat_tools.h:1054
bool Add_Histogram(const CSG_Histogram &Histogram)
double Get_Break(int i) const
Definition mat_tools.h:1062
bool Update(void)
size_t Get_Element_Count(void) const
Definition mat_tools.h:1051
virtual ~CSG_Index_Compare(void)
Definition mat_tools.h:206
virtual int Compare(const sLong a, const sLong b)=0
sLong Get_Index(sLong Position, bool Ascending=true) const
Definition mat_tools.h:243
bool Invert(void)
bool Destroy(void)
CSG_Index(void)
bool Del_Entry(sLong Position=-1)
bool is_Okay(void) const
Definition mat_tools.h:240
void Show_Progress(bool bProgress=true)
sLong Get_Count(void) const
Definition mat_tools.h:241
bool Create(sLong nValues, CSG_Index_Compare &Compare)
bool Add_Entry(sLong Position=-1)
sLong Get_NRows(void) const
Definition mat_tools.h:525
double ** Get_Data(void) const
Definition mat_tools.h:528
bool Del_Rows(sLong nRows)
bool Add_Row(const double *Data=NULL)
int Get_NX(void) const
Definition mat_tools.h:522
bool Ins_Row(sLong Row, const double *Data=NULL)
sLong Get_NCols(void) const
Definition mat_tools.h:524
bool Destroy(void)
bool Set_Rows(sLong nRows)
bool Create(const CSG_Matrix &Matrix)
bool Set_Size(sLong nRows, sLong nCols)
bool Set_Cols(sLong nCols)
CSG_Matrix(void)
bool Del_Row(sLong Row)
bool Ins_Col(sLong Col, const double *Data=NULL)
CSG_Vector Get_Col(sLong Col) const
int Get_NY(void) const
Definition mat_tools.h:523
bool is_Square(void) const
Definition mat_tools.h:538
bool Del_Cols(sLong nCols)
bool Add_Rows(sLong nRows)
bool Set_Col(sLong Col, const double *Data)
bool Add_Cols(sLong nCols)
bool Add_Col(const double *Data=NULL)
bool Del_Col(sLong Col)
bool Set_Row(sLong Row, const double *Data)
CSG_Vector Get_Row(sLong Row) const
bool Create(class CSG_Table *pTable, int Field, int nClasses, int Histogram=0)
int Get_Count(void) const
Definition mat_tools.h:1231
double Get_Break(int i) const
Definition mat_tools.h:1232
virtual int Compare(CSG_PriorityQueueItem *pItem)=0
size_t Get_Size(void) const
Definition mat_tools.h:300
void Create(size_t maxSize=256)
CSG_PriorityQueueItem * Get_Item(size_t i) const
Definition mat_tools.h:301
CSG_PriorityQueueItem * Minimum(void) const
Definition mat_tools.h:309
CSG_PriorityQueue(size_t maxSize=256)
CSG_PriorityQueueItem * Peek(void) const
Definition mat_tools.h:305
CSG_PriorityQueueItem * Maximum(void) const
Definition mat_tools.h:324
bool is_Empty(void) const
Definition mat_tools.h:299
CSG_Random(void)
static double Get_Gaussian(double mean, double stddev)
static void Initialize(void)
static double Get_Uniform(void)
CSG_Regression_Multiple(bool bIntercept=true)
class CSG_Table * Get_Info_Steps(void) const
Definition mat_tools.h:1844
class CSG_Table * m_pModel
Definition mat_tools.h:1891
double _Get_P(int nPredictors, int nSamples, double r2_full, double r2_reduced)
double Get_T(int iVariable) const
Definition mat_tools.h:1867
double Get_Parameter(int iVariable, int Parameter) const
class CSG_Table * Get_Info_Regression(void) const
Definition mat_tools.h:1842
double Get_StdError(int iVariable) const
Definition mat_tools.h:1866
bool _Set_Step_Info(const CSG_Matrix &X)
int _Get_Step_Out(CSG_Matrix &X, double P_out, double &R2)
void Set_With_Intercept(bool bOn=true)
Definition mat_tools.h:1826
double Get_RCoeff(int iVariable) const
Definition mat_tools.h:1863
double Get_R2_Partial(int iVariable) const
Definition mat_tools.h:1864
int Get_Predictor(int i) const
Definition mat_tools.h:1858
bool Set_Data(const CSG_Matrix &Samples, CSG_Strings *pNames=NULL)
double Get_P(int iVariable) const
Definition mat_tools.h:1868
double Get_ID(int iVariable) const
Definition mat_tools.h:1862
int _Get_Step_In(CSG_Matrix &X, double P_in, double &R2, const CSG_Matrix &Samples)
double Get_R2_Partial_Adj(int iVariable) const
Definition mat_tools.h:1865
bool _Get_Regression(const class CSG_Matrix &Samples)
bool Get_With_Intercept(void) const
Definition mat_tools.h:1827
class CSG_Table * m_pSteps
Definition mat_tools.h:1891
double _Get_F(int nPredictors, int nSamples, double r2_full, double r2_reduced)
class CSG_Table * Get_Info_Model(void) const
Definition mat_tools.h:1843
class CSG_Table * m_pRegression
Definition mat_tools.h:1891
double Get_R2(void) const
Definition mat_tools.h:1930
int Get_Log_maxIter(void) const
Definition mat_tools.h:1936
double Get_CV_R2(void) const
Definition mat_tools.h:1950
double Get_Log_Epsilon(void) const
Definition mat_tools.h:1937
int Get_Predictor_Count(void) const
Definition mat_tools.h:1925
double Get_Log_Difference(void) const
Definition mat_tools.h:1938
const CSG_Vector & Get_RCoeff(void) const
Definition mat_tools.h:1931
double Get_RCoeff(int i) const
Definition mat_tools.h:1932
double Get_CV_RMSE(void) const
Definition mat_tools.h:1948
double Get_CV_NRMSE(void) const
Definition mat_tools.h:1949
int Get_CV_nSamples(void) const
Definition mat_tools.h:1947
int Get_Sample_Count(void) const
Definition mat_tools.h:1924
bool Add_Sample(double Weight, double Dependent, const CSG_Vector &Predictors)
double Get_P(void) const
Definition mat_tools.h:1768
double _X_Transform(double y)
TSG_Regression_Type Get_Type(void) const
Definition mat_tools.h:1773
double Get_xValue(int i) const
Definition mat_tools.h:1736
double Get_Coefficient(void) const
Definition mat_tools.h:1764
bool Set_Values(int nValues, double *x, double *y)
CSG_Vector m_y
Definition mat_tools.h:1785
double Get_R(void) const
Definition mat_tools.h:1765
double _Y_Transform(double x)
double Get_Constant(void) const
Definition mat_tools.h:1763
CSG_Vector m_x
Definition mat_tools.h:1785
double Get_R2(void) const
Definition mat_tools.h:1766
bool Add_Values(double x, double y)
double Get_yValue(int i) const
Definition mat_tools.h:1737
TSG_Regression_Type m_Type
Definition mat_tools.h:1787
int Get_Count(void) const
Definition mat_tools.h:1734
double Get_xMin(void) const
Definition mat_tools.h:1751
double Get_R2_Adj(void) const
Definition mat_tools.h:1767
bool Get_Values(int i, double &x, double &y) const
Definition mat_tools.h:1738
double Get_StdError(void) const
Definition mat_tools.h:1769
double Get_yMean(void) const
Definition mat_tools.h:1759
double Get_xVariance(void) const
Definition mat_tools.h:1754
double Get_xMean(void) const
Definition mat_tools.h:1753
double Get_yMin(void) const
Definition mat_tools.h:1757
double Get_xMax(void) const
Definition mat_tools.h:1752
double Get_yMax(void) const
Definition mat_tools.h:1758
double Get_yVariance(void) const
Definition mat_tools.h:1760
double to_Relative(double Value) const
Definition mat_tools.h:1155
double Get_Range(void) const
Definition mat_tools.h:1132
double m_Range
Definition mat_tools.h:1197
bool Set_Range(double Minimum, double Maximum)
bool Create(const CSG_Scaler &Scaler)
double from_Relative(double Value) const
Definition mat_tools.h:1172
enum CSG_Scaler::EInterval TMode
double Get_Minimum(void) const
Definition mat_tools.h:1133
double Get_LogScale(void) const
Definition mat_tools.h:1140
TMode Get_Mode(void) const
Definition mat_tools.h:1137
double m_Minimum
Definition mat_tools.h:1197
CSG_Scaler(void)
double Get_Maximum(void) const
Definition mat_tools.h:1134
TMode m_Mode
Definition mat_tools.h:1193
CSG_Histogram m_Histogram
Definition mat_tools.h:1195
double m_LogScale[3]
Definition mat_tools.h:1197
void Add(const CSG_Simple_Statistics &Statistics)
double Get_Value(sLong i) const
Definition mat_tools.h:777
double Get_Weights(void) const
Definition mat_tools.h:746
int is_Evaluated(void) const
Definition mat_tools.h:741
double Get_Maximum(void)
Definition mat_tools.h:749
double * Get_Values(void) const
Definition mat_tools.h:776
double Get_Mean(void)
Definition mat_tools.h:753
double Get_Sum(void)
Definition mat_tools.h:751
double Get_Sum_Of_Squares(void)
Definition mat_tools.h:752
void _Evaluate(int Level=1)
double Get_Kurtosis(void)
Definition mat_tools.h:757
bool Create(bool bHoldValues=false)
double Get_StdDev(void)
Definition mat_tools.h:755
double Get_Skewness(void)
Definition mat_tools.h:758
sLong Get_Count(void) const
Definition mat_tools.h:745
double Get_Variance(void)
Definition mat_tools.h:754
void Add_Value(double Value, double Weight=1.)
double Get_Minimum(void)
Definition mat_tools.h:748
double Get_Range(void)
Definition mat_tools.h:750
CSG_Spline(void)
CSG_Vector m_z
Definition mat_tools.h:1564
CSG_Vector m_x
Definition mat_tools.h:1564
double Get_y(int i) const
Definition mat_tools.h:1554
bool m_bCreated
Definition mat_tools.h:1562
int Get_Count(void) const
Definition mat_tools.h:1550
CSG_Vector m_y
Definition mat_tools.h:1564
void Destroy(void)
double Get_xMin(void) const
Definition mat_tools.h:1551
double Get_xMax(void) const
Definition mat_tools.h:1552
double Get_x(int i) const
Definition mat_tools.h:1553
bool Create(double *xValues, double *yValues, int nValues, double yA=1.0e30, double yB=1.0e30)
void Add(double x, double y)
bool _Create(double yA, double yB)
static double Get_Norm_P(double Z)
static double Get_F_Inverse(double alpha, int dfn, int dfd, TSG_Test_Distribution_Type Type=TESTDIST_TYPE_Right)
static double Get_F_Tail_from_R2(double R2, int nPredictors, int nSamples, TSG_Test_Distribution_Type Type=TESTDIST_TYPE_Right)
static double Get_T_Tail(double T, int df, TSG_Test_Distribution_Type Type=TESTDIST_TYPE_Right)
static double Get_F_Tail(double F, int dfn, int dfd, TSG_Test_Distribution_Type Type=TESTDIST_TYPE_Right)
static double Get_Norm_Z(double P)
static double Get_T_Inverse(double alpha, int df, TSG_Test_Distribution_Type Type=TESTDIST_TYPE_Right)
bool Set_Point_Count(int Count)
Definition mat_tools.h:1580
int Get_Point_Count(void)
Definition mat_tools.h:1581
bool Set_Point(int Index, double x, double y, double z)
Definition mat_tools.h:1588
CSG_Points_3D & Get_Points(void)
Definition mat_tools.h:1583
bool Add_Point(double x, double y, double z)
Definition mat_tools.h:1585
bool Set_Point(int Index, const TSG_Point &p, double z)
Definition mat_tools.h:1602
bool Add_Point(const TSG_Point &p, double z)
Definition mat_tools.h:1586
bool Add_Data(double x, double y)
double Get_Data_Y(int i) const
Definition mat_tools.h:2212
bool Set_Data(double *x, double *y, int n, bool bAdd=false)
double Get_Coefficient(int i) const
Definition mat_tools.h:2218
int Get_nCoefficients(void) const
Definition mat_tools.h:2217
bool Set_Order(int Order=1)
int Get_Data_Count(void) const
Definition mat_tools.h:2210
double Get_R2(void) const
Definition mat_tools.h:2219
bool Destroy(void)
int Get_Order(void) const
Definition mat_tools.h:2216
double Get_Data_X(int i) const
Definition mat_tools.h:2211
bool Clr_Data(void)
double Get_Data_X(int i) const
Definition mat_tools.h:2116
double Get_Data_XMin(void)
Definition mat_tools.h:2117
double Get_ChiSquare(void) const
Definition mat_tools.h:2139
CSG_Trend(void)
int Get_Parameter_Count(void) const
Definition mat_tools.h:2107
CSG_Simple_Statistics & Get_Data_YStats(void)
Definition mat_tools.h:2123
bool Set_Formula(const CSG_String &Formula)
int Get_Data_Count(void) const
Definition mat_tools.h:2115
double Get_R2(void) const
Definition mat_tools.h:2140
double Get_Data_YMin(void)
Definition mat_tools.h:2121
double Get_Data_XMax(void)
Definition mat_tools.h:2118
double Get_Data_YMax(void)
Definition mat_tools.h:2122
CSG_Simple_Statistics & Get_Data_XStats(void)
Definition mat_tools.h:2119
double * Get_Parameters(void) const
Definition mat_tools.h:2108
double Get_Value(double x) const
Definition mat_tools.h:2142
double Get_Data_Y(int i) const
Definition mat_tools.h:2120
bool is_Okay(void) const
Definition mat_tools.h:2135
double Get_Max_Lambda(void) const
Definition mat_tools.h:2128
CSG_String Get_Formula(int Type=SG_TREND_STRING_Complete)
int Get_Max_Iterations(void) const
Definition mat_tools.h:2126
void Add_Value(double Value, double Weight=1.)
virtual void Create(bool bWeights=false)
virtual bool Get_Minority(double &Value) const
Definition mat_tools.h:872
CSG_Unique_Number_Statistics(bool bWeights=false)
Definition mat_tools.h:851
virtual bool Get_Majority(double &Value, int &Count) const
Definition mat_tools.h:871
virtual bool Get_Minority(double &Value, int &Count) const
Definition mat_tools.h:873
virtual bool Get_Majority(double &Value) const
Definition mat_tools.h:870
virtual ~CSG_Unique_Number_Statistics(void)
Definition mat_tools.h:852
double Get_Value(int Index) const
Definition mat_tools.h:858
bool Get_Class(int Index, double &Value, int &Count) const
Definition mat_tools.h:860
void Add_Value(const CSG_String &Value, double Weight=1.)
bool Get_Class(int Index, CSG_String &Value, int &Count) const
Definition mat_tools.h:895
virtual void Create(bool bWeights=false)
virtual bool Get_Minority(CSG_String &Value, int &Count) const
Definition mat_tools.h:908
const SG_Char * Get_Value(int Index) const
Definition mat_tools.h:893
virtual ~CSG_Unique_String_Statistics(void)
Definition mat_tools.h:887
virtual bool Get_Minority(CSG_String &Value) const
Definition mat_tools.h:907
virtual bool Get_Majority(CSG_String &Value, int &Count) const
Definition mat_tools.h:906
virtual bool Get_Majority(CSG_String &Value) const
Definition mat_tools.h:905
CSG_Unique_String_Statistics(bool bWeights=false)
Definition mat_tools.h:886
virtual bool Get_Majority(double &Value) const
Definition mat_tools.h:826
virtual bool Get_Majority(CSG_String &Value, int &Count) const
Definition mat_tools.h:832
virtual bool Get_Minority(double &Value) const
Definition mat_tools.h:828
double Get_Weight(int i) const
Definition mat_tools.h:821
virtual bool Get_Majority(CSG_String &Value) const
Definition mat_tools.h:831
virtual bool Get_Minority(double &Value, int &Count) const
Definition mat_tools.h:829
virtual bool Get_Minority(CSG_String &Value, int &Count) const
Definition mat_tools.h:834
virtual bool Get_Majority(double &Value, int &Count) const
Definition mat_tools.h:827
virtual int Get_Minority(bool bWeighted=false) const
virtual void Create(bool bWeights=false)
Definition mat_tools.h:817
virtual bool Get_Minority(CSG_String &Value) const
Definition mat_tools.h:833
int Get_Count(int i) const
Definition mat_tools.h:820
virtual ~CSG_Unique_Value_Statistics(void)
Definition mat_tools.h:815
int Get_Count(void) const
Definition mat_tools.h:819
virtual int Get_Majority(bool bWeighted=false) const
CSG_Vector(void)
size_t Get_uSize(void) const
Definition mat_tools.h:383
bool Add_Rows(sLong nRows)
double const * const_iterator
Definition mat_tools.h:446
bool Add_Row(double Value=0.)
bool Create(const CSG_Vector &Vector)
bool Del_Row(sLong Row=-1)
bool Set_Rows(sLong nRows)
double Get_Data(sLong x) const
Definition mat_tools.h:387
const_iterator cend(void) const
Definition mat_tools.h:451
sLong Get_Size(void) const
Definition mat_tools.h:382
const_iterator begin(void) const
Definition mat_tools.h:448
const_iterator cbegin(void) const
Definition mat_tools.h:450
bool is_Equal(const CSG_Vector &Vector) const
bool Destroy(void)
sLong Get_Row_Count(void) const
Definition mat_tools.h:381
int Get_N(void) const
Definition mat_tools.h:384
double * Get_Data(void) const
Definition mat_tools.h:386
const_iterator end(void) const
Definition mat_tools.h:449
bool Del_Rows(sLong nRows)
#define B
#define A
struct SSG_Point TSG_Point
struct SSG_Point_3D TSG_Point_3D
#define asDouble(i)
CSG_Vector operator*(double Scalar, const CSG_Vector &Vector)
TSG_Regression_Type
Definition mat_tools.h:1712
@ REGRESSION_Linear
Definition mat_tools.h:1713
@ REGRESSION_Rez_Y
Definition mat_tools.h:1715
@ REGRESSION_Log
Definition mat_tools.h:1718
@ REGRESSION_Exp
Definition mat_tools.h:1717
@ REGRESSION_Pow
Definition mat_tools.h:1716
@ REGRESSION_Rez_X
Definition mat_tools.h:1714
ESG_Trend_String
Definition mat_tools.h:2090
@ SG_TREND_STRING_Complete
Definition mat_tools.h:2094
@ SG_TREND_STRING_Formula_Parameters
Definition mat_tools.h:2093
@ SG_TREND_STRING_Formula
Definition mat_tools.h:2091
@ SG_TREND_STRING_Function
Definition mat_tools.h:2092
@ SG_TREND_STRING_Compact
Definition mat_tools.h:2095
SAGA_API_DLL_EXPORT bool SG_Matrix_Solve(CSG_Matrix &Matrix, CSG_Vector &Vector, bool bSilent=true)
SAGA_API_DLL_EXPORT int SG_Compare_Int(const void *a, const void *b)
SAGA_API_DLL_EXPORT CSG_Matrix SG_Matrix_Get_Rotation(double R, bool bDegree=false)
double(* TSG_Formula_Function_0)(void)
Definition mat_tools.h:1982
SAGA_API_DLL_EXPORT double SG_Get_Rounded(double Value, int Decimals=0)
Definition mat_tools.cpp:83
SAGA_API_DLL_EXPORT CSG_Vector operator*(double Scalar, const CSG_Vector &Vector)
SAGA_API_DLL_EXPORT double SG_Degree_To_Decimal(double Deg, double Min, double Sec)
int(* TSG_PFNC_Compare)(const sLong a, const sLong b)
Definition mat_tools.h:196
ESG_Multiple_Regression_Info_Vars
Definition mat_tools.h:1802
@ MLR_VAR_R2
Definition mat_tools.h:1807
@ MLR_VAR_P
Definition mat_tools.h:1812
@ MLR_VAR_R2_ADJ
Definition mat_tools.h:1808
@ MLR_VAR_ID
Definition mat_tools.h:1803
@ MLR_VAR_RCOEFF
Definition mat_tools.h:1805
@ MLR_VAR_T
Definition mat_tools.h:1810
@ MLR_VAR_SE
Definition mat_tools.h:1809
@ MLR_VAR_R
Definition mat_tools.h:1806
@ MLR_VAR_NAME
Definition mat_tools.h:1804
@ MLR_VAR_SIG
Definition mat_tools.h:1811
SAGA_API_DLL_EXPORT CSG_String SG_Get_Double_asString(double Number, int Width=-1, int Precision=-1, bool bScientific=false)
SAGA_API_DLL_EXPORT int SG_Compare_Char_Ptr(const void *a, const void *b)
TSG_Test_Distribution_Type
Definition mat_tools.h:1633
@ TESTDIST_TYPE_Right
Definition mat_tools.h:1635
@ TESTDIST_TYPE_Left
Definition mat_tools.h:1634
@ TESTDIST_TYPE_Middle
Definition mat_tools.h:1636
@ TESTDIST_TYPE_TwoTail
Definition mat_tools.h:1637
SAGA_API_DLL_EXPORT int SG_Get_Digit_Count(int Number)
SAGA_API_DLL_EXPORT bool SG_Matrix_Eigen_Reduction(const CSG_Matrix &Matrix, CSG_Matrix &Eigen_Vectors, CSG_Vector &Eigen_Values, bool bSilent=true)
double(* TSG_Formula_Function_1)(double)
Definition mat_tools.h:1983
SAGA_API_DLL_EXPORT CSG_Matrix SG_Get_Correlation_Matrix(const CSG_Matrix &Values, bool bCovariances=false)
ESG_Cluster_Analysis_Method
Definition mat_tools.h:1261
@ SG_CLUSTERANALYSIS_Combined
Definition mat_tools.h:1264
@ SG_CLUSTERANALYSIS_Hill_Climbing
Definition mat_tools.h:1263
@ SG_CLUSTERANALYSIS_Minimum_Distance
Definition mat_tools.h:1262
TSG_Regression_Correction
Definition mat_tools.h:1691
@ REGRESSION_CORR_Smith
Definition mat_tools.h:1693
@ REGRESSION_CORR_Wherry_1
Definition mat_tools.h:1694
@ REGRESSION_CORR_Pratt
Definition mat_tools.h:1697
@ REGRESSION_CORR_None
Definition mat_tools.h:1692
@ REGRESSION_CORR_Claudy_3
Definition mat_tools.h:1698
@ REGRESSION_CORR_Wherry_2
Definition mat_tools.h:1695
@ REGRESSION_CORR_Olkin_Pratt
Definition mat_tools.h:1696
SAGA_API_DLL_EXPORT void SG_Decimal_To_Degree(double Value, double &Deg, double &Min, double &Sec)
double(* TSG_Formula_Function_3)(double, double, double)
Definition mat_tools.h:1985
SAGA_API_DLL_EXPORT double SG_Regression_Get_Adjusted_R2(double R2, int nSamples, int nPredictors, TSG_Regression_Correction Correction=REGRESSION_CORR_Wherry_1)
SAGA_API_DLL_EXPORT bool SG_Matrix_LU_Decomposition(int n, int *Permutation, double **Matrix, bool bSilent=true, int *nRowChanges=NULL)
ESG_Classify_Supervised
Definition mat_tools.h:1332
@ SG_CLASSIFY_SUPERVISED_ParallelEpiped
Definition mat_tools.h:1334
@ SG_CLASSIFY_SUPERVISED_SVM
Definition mat_tools.h:1341
@ SG_CLASSIFY_SUPERVISED_MinimumDistance
Definition mat_tools.h:1335
@ SG_CLASSIFY_SUPERVISED_SAM
Definition mat_tools.h:1338
@ SG_CLASSIFY_SUPERVISED_SID
Definition mat_tools.h:1340
@ SG_CLASSIFY_SUPERVISED_Mahalonobis
Definition mat_tools.h:1336
@ SG_CLASSIFY_SUPERVISED_WTA
Definition mat_tools.h:1339
@ SG_CLASSIFY_SUPERVISED_MaximumLikelihood
Definition mat_tools.h:1337
@ SG_CLASSIFY_SUPERVISED_BinaryEncoding
Definition mat_tools.h:1333
SAGA_API_DLL_EXPORT double SG_Get_Rounded_To_SignificantFigures(double Value, int Decimals)
SAGA_API_DLL_EXPORT bool SG_VectorR3_Rotate(double Vector[3], size_t Axis, double Angle)
SAGA_API_DLL_EXPORT int SG_Compare_Double(const void *a, const void *b)
double(* TSG_Formula_Function_2)(double, double)
Definition mat_tools.h:1984
SAGA_API_DLL_EXPORT double SG_Get_Square(double Value)
Definition mat_tools.cpp:70
SAGA_API_DLL_EXPORT bool SG_VectorR2_Rotate(double &x, double &y, double Angle)
SAGA_API_DLL_EXPORT bool SG_Matrix_LU_Solve(int n, const int *Permutation, const double **Matrix, double *Vector, bool bSilent=true)
TSG_Formula_Function_1 Function
Definition mat_tools.h:2021
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129