gstlearn  0.3.3
CCC
Classical.cpp File Reference
#include "geoslib_old_f.h"
#include "Db/Db.hpp"
#include "Db/DbGrid.hpp"
#include "Stats/Classical.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/String.hpp"
#include "Basic/AStringable.hpp"
#include "Matrix/MatrixSquareSymmetric.hpp"
#include "Model/Model.hpp"
#include <math.h>
#include <Matrix/Table.hpp>
#include <string.h>

Functions

bool _operStatisticsCheck (const EStatOption &oper, int flag_multi, int flag_indic, int flag_sum, int flag_median, int flag_qt)
 
void _updateProportions (DbGrid *dbin, VectorInt &indg, int nfacies, VectorDouble &prop)
 
void _updateTransition (DbGrid *dbin, int pos, VectorInt &indg, int nfacies, int orient, VectorDouble &trans)
 
void _scaleAndAffect (Db *dbout, int iptr, int iech, int nitem, VectorDouble &tab)
 
bool _operExists (const std::vector< EStatOption > &opers, const EStatOption &refe)
 
void _refactor (int ncol, VectorDouble &tab)
 
void _copyResults (int nx, int ny, const VectorDouble &tabin, VectorDouble &tabout)
 
void _neighboringCell (int ndim, int radius, int rank0, const VectorInt &indg0, VectorInt &indg)
 
bool _regressionCheck (Db *db1, int icol0, const VectorInt &icols, int mode, Db *db2, const Model *model)
 
bool _regressionLoad (Db *db1, Db *db2, int iech, int icol0, const VectorInt &icols, int mode, int flagCste, const Model *model, double *value, VectorDouble &x)
 
void _regrprint (const ResRegr &regr)
 
VectorDouble regrDeming (const VectorDouble &x, const VectorDouble &y, double delta)
 
double _getQuantile (VectorDouble &tab, int ntab, double proba)
 
VectorString statOptionToName (const std::vector< EStatOption > &opers)
 
std::vector< EStatOption > KeysToStatOptions (const VectorString &opers)
 
void dbStatisticsVariables (Db *db, const VectorString &names, const std::vector< EStatOption > &opers, int iptr0, double proba, double vmin, double vmax)
 Store several statistics calculated on a set of variables of a Db and store them in this same Db in variables already created. These functions should not be used in Target Language. More...
 
void dbStatisticsVariablesByUID (Db *db, const VectorInt &iuids, const std::vector< EStatOption > &opers, int iptr0, double proba, double vmin, double vmax)
 Store several statistics calculated on a set of variables of a Db and store them in this same Db in variables already created. These functions should not be used in Target Language. More...
 
VectorDouble dbStatisticsMono (Db *db, const VectorString &names, const std::vector< EStatOption > &opers, bool flagIso, double proba, double vmin, double vmax)
 Compute several monovariate statistics (opers) on variables contained in a Db and produce the results in a convenient output format (Vector of values or Table). More...
 
GSTLEARN_EXPORT Table dbStatisticsMonoT (Db *db, const VectorString &names, const std::vector< EStatOption > &opers, bool flagIso, double proba, double vmin, double vmax)
 Compute several monovariate statistics (opers) on variables contained in a Db and produce the results in a convenient output format (Vector of values or Table). More...
 
VectorDouble dbStatisticsMonoByUID (Db *db, const VectorInt &iuids, const std::vector< EStatOption > &opers, bool flagIso, double proba, double vmin, double vmax)
 Compute several monovariate statistics (opers) on variables contained in a Db and produce the results in a convenient output format (Vector of values or Table). More...
 
VectorDouble dbStatisticsFacies (Db *db)
 
double dbStatisticsIndicator (Db *db)
 
VectorDouble dbStatisticsCorrel (Db *db, const VectorString &names, bool flagIso)
 Compute correlation matrix on variables contained in a Db and produce the results in a convenient output format (Vector or a Matrix). More...
 
MatrixSquareSymmetric dbStatisticsCorrelT (Db *db, const VectorString &names, bool flagIso)
 Compute correlation matrix on variables contained in a Db and produce the results in a convenient output format (Vector or a Matrix). More...
 
VectorDouble dbStatisticsCorrelByUID (Db *db, const VectorInt &iuids, bool flagIso)
 Compute correlation matrix on variables contained in a Db and produce the results in a convenient output format (Vector or a Matrix). More...
 
String statisticsMonoPrint (const VectorDouble &stats, const std::vector< EStatOption > &opers, const VectorString &names, const String &title)
 
String statisticsMultiPrint (const VectorDouble &stats, const VectorString &names, const String &title)
 
ResRegr regression (Db *db1, const String &name0, const VectorString &names, int mode, bool flagCste, Db *db2, const Model *model, bool verbose)
 
ResRegr regressionByUID (Db *db1, int icol0, const VectorInt &icols, int mode, bool flagCste, Db *db2, const Model *model, bool verbose)
 
int regressionApply (Db *db1, int iptr0, const String &name0, const VectorString &names, int mode, bool flagCste, Db *db2, const Model *model)
 
int statisticsProportion (DbGrid *dbin, DbGrid *dbout, int pos, int nfacies, int radius)
 
int statisticsTransition (DbGrid *dbin, DbGrid *dbout, int pos, int nfacies, int radius, int orient)
 
void _getRowname (const String &radix, int ncol, int icol, const String &name, char *string)
 
void dbStatisticsPrint (const Db *db, const VectorString &names, const std::vector< EStatOption > &opers, bool flagIso, bool flagCorrel, const String &title, const String &radix)
 Compute statistics on variables contained in a Db and print out the results. More...
 
void dbStatisticsPrintByUID (const Db *db, const VectorInt &iuids_arg, const std::vector< EStatOption > &opers, bool flagIso, bool flagCorrel, const String &title, const String &radix)
 Compute statistics on variables contained in a Db and print out the results. More...
 
MatrixRectangularsphering (const AMatrix *X)
 
VectorDouble dbStatisticsPerCell (Db *db, DbGrid *dbgrid, const EStatOption &oper, const String &name1, const String &name2, const VectorDouble &cuts)
 Statistics of points per cell. More...
 
VectorDouble dbStatisticsPerCellByUID (Db *db, DbGrid *dbgrid, const EStatOption &oper, int iuid, int juid, const VectorDouble &cuts)
 Statistics of points per cell. More...
 
Table dbStatisticsMultiT (Db *db, const VectorString &names, const EStatOption &oper, bool flagMono, bool verbose)
 Compute a Multivariate statistic on variables contained in a Db and return the results. More...
 
VectorDouble dbStatisticsMulti (Db *db, const VectorString &names, const EStatOption &oper, bool flagMono, bool verbose)
 Compute a Multivariate statistic on variables contained in a Db and return the results. More...
 
VectorDouble dbStatisticsMultiByColIdx (Db *db, const VectorInt &cols, const EStatOption &oper, bool flagMono, bool verbose)
 Compute a Multivariate statistic on variables contained in a Db and return the results. More...
 
int dbStatisticsInGridTool (Db *db, DbGrid *dbgrid, const VectorString &names, const EStatOption &oper, int radius, int iptr0)
 
int dbStatisticsInGridToolByUID (Db *db, DbGrid *dbgrid, const VectorInt &iuids, const EStatOption &oper, int radius, int iptr0)
 

Function Documentation

◆ _copyResults()

void _copyResults ( int  nx,
int  ny,
const VectorDouble tabin,
VectorDouble tabout 
)

Copy the multivariate or monovariate statistics into the returned array

Parameters
[in]nxFirst dimension of the matrix
[in]nyFirst dimension of the matrix
[in]tabinArray to be refactored
[out]taboutArray to be refactored

◆ _getQuantile()

double _getQuantile ( VectorDouble tab,
int  ntab,
double  proba 
)

Calculate the quantile which corresponds to a given probability

Returns
Quantile value
Parameters
[in]tabArray of outcomes per sample
[in]ntabNumber of active values
[in]probaProbability value (between 0 and 1)

◆ _getRowname()

void _getRowname ( const String radix,
int  ncol,
int  icol,
const String name,
char *  string 
)

Constitute the name of the row

Parameters
[in]radixRadix for the different variables (optional)
[in]ncolNumber of variables
[in]icolRank of the variable
[in]nameVariables name
[in]stringString array

◆ _neighboringCell()

void _neighboringCell ( int  ndim,
int  radius,
int  rank0,
const VectorInt indg0,
VectorInt indg 
)

Calculate the indices of the cell neighboring a target cell

Parameters
[in]ndimSpace dimension
[in]radiusNeighborhood radius
[in]rank0Rank of the neighbor
[in]indg0Array of indices of the target cell
[out]indgArray of indices of the neighboring cell

◆ _operExists()

bool _operExists ( const std::vector< EStatOption > &  opers,
const EStatOption &  refe 
)

Check the operator name is mentioned within a list

Returns
1 if the operator is mentioned; 0 otherwise
Parameters
[in]opersArray of operators
[in]refeReference operator
Remarks
If the array 'opers' if empty, any name is considered as valid

◆ _operStatisticsCheck()

bool _operStatisticsCheck ( const EStatOption &  oper,
int  flag_multi,
int  flag_indic,
int  flag_sum,
int  flag_median,
int  flag_qt 
)

Check the operator name

Returns
1 if the operator is valid; 0 otherwise
Parameters
[in]operA EStatOption item
[in]flag_multi1 if multivariate operator is authorized
[in]flag_indic1 if indicator ("plus","minus","zero") is authorized
[in]flag_sum1 if sum of variable is authorized
[in]flag_median1 if median is authorized
[in]flag_qt1 if QT ("ore","metal") is authorized
Remarks
If an error occurred, the message is printed

◆ _refactor()

void _refactor ( int  ncol,
VectorDouble tab 
)

Copy the multivariate into monovariate statistics (before printout)

Parameters
[in]ncolDimension of the (square) matrix
[in,out]tabArray to be refactored

◆ _regressionCheck()

bool _regressionCheck ( Db db1,
int  icol0,
const VectorInt icols,
int  mode,
Db db2,
const Model model 
)

◆ _regressionLoad()

bool _regressionLoad ( Db db1,
Db db2,
int  iech,
int  icol0,
const VectorInt icols,
int  mode,
int  flagCste,
const Model model,
double *  value,
VectorDouble x 
)

◆ _regrprint()

void _regrprint ( const ResRegr regr)

◆ _scaleAndAffect()

void _scaleAndAffect ( Db dbout,
int  iptr,
int  iech,
int  nitem,
VectorDouble tab 
)

Scale the proportions and store the proportions

Parameters
[in]dboutDb for the output grid
[in]iptrWriting pointer
[in]iechRank of the target sample
[in]nitemNumber of items
[in]tabArray of cumulative statistics

◆ _updateProportions()

void _updateProportions ( DbGrid dbin,
VectorInt indg,
int  nfacies,
VectorDouble prop 
)

Update the proportions

Parameters
[in]dbinDb for the input grid
[in]indgArray of grid indices
[in]nfaciesNumber of facies
[out]propArray of proportions

◆ _updateTransition()

void _updateTransition ( DbGrid dbin,
int  pos,
VectorInt indg,
int  nfacies,
int  orient,
VectorDouble trans 
)

Update the transitions

Parameters
[in]dbinDbGrid for the input grid
[in]posRank of the montee axis
[in]indgArray of grid indices
[in]nfaciesNumber of facies
[in]orientOrientation
[out]transArray of transitions

◆ dbStatisticsFacies()

VectorDouble dbStatisticsFacies ( Db db)

Considering that the Unique variable is a Facies (positive integer) returns the vector of proportions

Returns
The vector of proportions per Facies
Parameters
[in]dbDb structure

◆ dbStatisticsIndicator()

double dbStatisticsIndicator ( Db db)

Considering that the Unique variable is an Indicator (0 or 1) returns the proportion of 1

Returns
The vector of proportions per Facies
Parameters
[in]dbDb structure

◆ dbStatisticsInGridTool()

int dbStatisticsInGridTool ( Db db,
DbGrid dbgrid,
const VectorString names,
const EStatOption &  oper,
int  radius,
int  iptr0 
)

Calculates the monovariate statistics within cells of a grid

Returns
Error return code
Parameters
[in]dbDb for the points
[in]dbgridDb for the grid
[in]namesVector of target variable names
[in]operA EStatOption item
[in]radiusNeighborhood radius
[in]iptr0Storage address (first variable)

◆ dbStatisticsInGridToolByUID()

int dbStatisticsInGridToolByUID ( Db db,
DbGrid dbgrid,
const VectorInt iuids,
const EStatOption &  oper,
int  radius,
int  iptr0 
)

Calculates the monovariate statistics within cells of a grid

Returns
Error return code
Parameters
[in]dbDb for the points
[in]dbgridDb for the grid
[in]iuidsVector of UID for target variable
[in]operA EStatOption item
[in]radiusNeighborhood radius
[in]iptr0Storage address (first variable)

◆ KeysToStatOptions()

std::vector<EStatOption> KeysToStatOptions ( const VectorString opers)

◆ regrDeming()

VectorDouble regrDeming ( const VectorDouble x,
const VectorDouble y,
double  delta 
)

Calculate the coefficients of the Deming regression (with 2 variables)

Parameters
xVector for the first variable
yVector for the second variable
deltaratio of error variances (s_y^2 / s_x^2)
Returns
Vector of coefficients for the equation
y = beta[0] + beta[1] * x
Remarks
Both input vectors are assumed to contain valid values
From: https://en.wikipedia.org/wiki/Deming_regression

◆ regression()

ResRegr regression ( Db db1,
const String name0,
const VectorString names,
int  mode,
bool  flagCste,
Db db2,
const Model model,
bool  verbose 
)

◆ regressionApply()

int regressionApply ( Db db1,
int  iptr0,
const String name0,
const VectorString names,
int  mode,
bool  flagCste,
Db db2,
const Model model 
)

Evaluate the regression

Returns
Error return code
Parameters
[in,out]db1Db descriptor (for target variable)
[in]iptr0Storing address
[in]name0Name of the target variable
[in]namesVector of names of the explanatory variables
[in]modeType of calculation
  • 0 : standard multivariate case
  • 1 : using external drifts
  • 2 : using standard drift functions (mode==2)
[in]flagCsteThe constant is added as explanatory variable]
[in]db2Db descriptor (for auxiliary variables)
[in]modelModel structure (used for mode==2)
Remarks
The flag_mode indicates the type of regression calculation:
0 : V[icol] as a function of V[icols[i]]
1 : Z1 as a function of the different Fi's
The Db1 structure is modified: the column (iptr0) of the Db1
is added by this function; it contains the value
of the residuals at each datum (or TEST if the residual has not
been calculated).

◆ regressionByUID()

ResRegr regressionByUID ( Db db1,
int  icol0,
const VectorInt icols,
int  mode,
bool  flagCste,
Db db2,
const Model model,
bool  verbose 
)

Evaluate the regression

Returns
Error return code
Parameters
[in,out]db1Db descriptor (for target variable)
[in]icol0Rank of the target variable
[in]icolsVector of ranks of the explanatory variables
[in]modeType of calculation
  • 0 : standard multivariate case
  • 1 : using external drifts
  • 2 : using standard drift functions (in 'model')
[in]flagCsteThe constant is added as explanatory variable
[in]db2Db descriptor (for auxiliary variables)
[in]modelModel (only used for Drift functions if mode==2)
[in]verboseVerbose option
Remarks
The flag_mode indicates the type of regression calculation:
0 : V[icol] as a function of V[icols[i]]
1 : Z1 as a function of the different Fi's

◆ sphering()

MatrixRectangular* sphering ( const AMatrix X)

Sphering procedure

Parameters
XInput Data vector
Returns
The Sphering matrix (or nullptr if problem)
Remarks
When performing the (forward) sphering, you must perform the following operation
X <- prodMatrix(X, S)

◆ statisticsMonoPrint()

String statisticsMonoPrint ( const VectorDouble stats,
const std::vector< EStatOption > &  opers,
const VectorString names,
const String title 
)

Print the monovariate statistics between different variables of a Db

Returns
Error Return code
Parameters
[in]statsArray of statistics (organized by variable)
[in]opersList of the operator ranks
[in]namesList of variables
[in]titleTitle for the printout (optional)

◆ statisticsMultiPrint()

String statisticsMultiPrint ( const VectorDouble stats,
const VectorString names,
const String title 
)

Print the multivariate statistics between different variables of a Db

Returns
Error Return code
Parameters
[in]statsMatrix of variance-covariance
[in]namesVector of variable names
[in]titleTitle for the printout (optional)

◆ statisticsProportion()

int statisticsProportion ( DbGrid dbin,
DbGrid dbout,
int  pos,
int  nfacies,
int  radius 
)

Calculates the "montee" from a grid into a 1-D grid

Returns
Error return code
Parameters
[in]dbinDb for the input grid
[in]dboutDb for the output grid
[in]posRank of the montee axis (starting from 0)
[in]nfaciesNumber of facies
[in]radiusRadius of the neighborhood

◆ statisticsTransition()

int statisticsTransition ( DbGrid dbin,
DbGrid dbout,
int  pos,
int  nfacies,
int  radius,
int  orient 
)

Calculates the transition from a grid into a 1-D grid

Returns
Error return code
Parameters
[in]dbinDb for the input grid
[in]dboutDb for the output grid
[in]posRank of the montee axis (starting from 0)
[in]nfaciesNumber of facies
[in]radiusRadius of the neighborhood
[in]orientOrientation (+1 or -1)

◆ statOptionToName()

VectorString statOptionToName ( const std::vector< EStatOption > &  opers)