gstlearn  0.3.3
CCC
vario.cpp File Reference
#include "geoslib_f.h"
#include "geoslib_old_f.h"
#include "Enum/EJustify.hpp"
#include "Enum/ECalcVario.hpp"
#include "Enum/EDrift.hpp"
#include "Variogram/Vario.hpp"
#include "Variogram/VarioParam.hpp"
#include "Anamorphosis/AAnam.hpp"
#include "Anamorphosis/AnamHermite.hpp"
#include "Polynomials/Hermite.hpp"
#include "Polygon/Polygons.hpp"
#include "Morpho/Morpho.hpp"
#include "Basic/AStringable.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/NamingConvention.hpp"
#include "Basic/File.hpp"
#include "Basic/String.hpp"
#include "Basic/OptDbg.hpp"
#include "Db/Db.hpp"
#include "Model/Model.hpp"
#include "Stats/PCA.hpp"
#include "Stats/PCAStringFormat.hpp"
#include "Matrix/MatrixSquareGeneral.hpp"
#include <string.h>
#include <math.h>

Functions

void vario_fix_codir (int ndim, VectorDouble &codir)
 
int variogram_maximum_dist1D_reached (Db *db, int iech, int jech, double maxdist)
 
double _variogram_convert_angular_tolerance (double tolang)
 
int variogram_get_lag (const DirParam &dirparam, int idir, double ps, double psmin, double *dist, bool flag_asym)
 
void variogram_scale (Vario *vario, int idir)
 
int code_comparable (const Db *db1, const Db *db2, int iech, int jech, int opt_code, int tolcode)
 
bool variogram_reject_fault (const Db *db, int iech, int jech, const Faults *faults)
 
int variogram_reject_pair (const Db *db, int iech, int jech, double dist, double psmin, double bench, double cylrad, const VectorDouble &codir, double *ps)
 
void vardir_print (Vario *vario, int idir, int verbose)
 
int variovect_compute (Db *db, Vario *vario, int ncomp)
 
void variogram_extension (const Vario *vario, int ivar, int jvar, int idir0, int flag_norm, int flag_vars, double distmin, double distmax, double varmin, double varmax, int *flag_hneg, int *flag_gneg, double *c0, double *hmin, double *hmax, double *gmin, double *gmax)
 
int variogram_direction_add (VarioParam *varioparam, int npas, int opt_code, int idate, double dpas, double toldis, double tolang, double bench, double cylrad, double tolcode, const VectorDouble &breaks, const VectorDouble &codir)
 
int correlation_f (Db *db1, Db *db2, DbGrid *dbgrid, int flag_same, int icol1, int icol2, int flag_verbose, double dmin, double dmax, double tolang, double bench, double cylrad, VectorDouble &codir, int opt_code, int tolcode, int *nindice, int **indices, double *correl)
 
int correlation_ident (Db *db1, Db *db2, int icol1, int icol2, Polygons *polygon)
 
void variogram_cloud_ident (Db *db, DbGrid *dbgrid, Vario *vario, Polygons *polygon)
 
int variogram_cloud (const Db *db, const VarioParam *varioparam, DbGrid *dbgrid, const NamingConvention &namconv)
 
int variogram_cloud_dim (Db *db, const VarioParam *varioparam, double *vmax)
 
int vario_extract (Vario *vario, ECalcVario *calcul_type, int *ndim, int *nvar, int *ndir, int *ndate, double *scale, double **dates)
 
int vario_get_rank (Vario *vario, int idir, int idate)
 
void vardir_copy (VarioParam *vario_in, int idir_in, VarioParam *vario_out, int idir_out)
 
int geometry_compute (Db *db, Vario *vario, Vario_Order *vorder, int *npair)
 
void variogram_trans_cut (Vario *vario, int nh, double ycut)
 
int variogram_mlayers (Db *db, int *seltab, Vario *vario, Vario_Order *vorder)
 
int variogram_y2z (Vario *vario, AAnam *anam, Model *model)
 
void condexp (Db *db1, Db *db2, int icol1, int icol2, double mini, double maxi, int nclass, int verbose, int *ncond, double *xcond, double *ycond)
 
int _variogram_compute (Db *db, Vario *vario, int flag_gen, int flag_sample, int verr_mode, Model *model, int verbose)
 
ECalcVario vario_identify_calcul_type (const String &calcul_name)
 
DbGriddb_variogram_cloud (Db *db, const VarioParam *varioparam, double lagmax, double varmax, int lagnb, int varnb, const NamingConvention &namconv)
 
int vmap_compute (Db *db, DbGrid *dbmap, const ECalcVario &calcul_type, int radius, bool flag_FFT, const NamingConvention &namconv)
 
Dbdb_variogram (Db *db, const VarioParam *varioparam)
 
DbGriddb_vmap_compute (Db *db, const ECalcVario &calcul_type, const VectorInt &nx_arg, const VectorDouble &dxx, int radius, bool flag_FFT, const NamingConvention &namconv)
 
int dbgrid_model (DbGrid *dbgrid, Model *model, const NamingConvention &namconv)
 

Function Documentation

◆ _variogram_compute()

int _variogram_compute ( Db db,
Vario vario,
int  flag_gen,
int  flag_sample,
int  verr_mode,
Model model,
int  verbose 
)

Evaluate the experimental variogram

Returns
Error return code
Parameters
[in]dbDb descriptor
[in]varioVario structure
[in]flag_gen1 for calculation of generalized variogram
[in]flag_samplecalculate the variogram per sample
[in]verr_modeMode of variogram correction (1, 2 or 3)
[in]modelModel structure (triggers the KU option)
[in]verboseVerbose flag
Note
The number of iterations in KU is given can be updated using the
keypair technique with name "KU_Niter".

◆ _variogram_convert_angular_tolerance()

double _variogram_convert_angular_tolerance ( double  tolang)

Returns the cosine of the angular tolerance

Parameters
[in]tolangAngular tolerance

This method is not documented on purpose. It should remain private

◆ code_comparable()

int code_comparable ( const Db db1,
const Db db2,
int  iech,
int  jech,
int  opt_code,
int  tolcode 
)

Check if a pair must be kept according to code criterion

Returns
1 if the codes are not comparable
Parameters
[in]db1First Db structure
[in]db2Second Db structure
[in]iechRank of the first sample
[in]jechRank of the second sample
[in]opt_codecode selection option
  • 0 : no use of the code selection
  • 1 : codes must be close enough
  • 2 : codes must be different
[in]tolcodeCode tolerance
Remarks
When used in variogram calculation, pairs are discarded then the
resulting value is 1.

◆ condexp()

void condexp ( Db db1,
Db db2,
int  icol1,
int  icol2,
double  mini,
double  maxi,
int  nclass,
int  verbose,
int *  ncond,
double *  xcond,
double *  ycond 
)

Evaluate the experimental conditional expectation

Parameters
[in]db1Db descriptor (for target variable)
[in]db2Db descriptor (for auxiliary variables)
[in]icol1Rank of the target variable
[in]icol2Rank of the explanatory variable
[in]miniMinimum value for the explanaroty variable
[in]maxiMaximum value for the explanaroty variable
[in]nclassNumber of classes
[in]verboseVerbose flag
[out]ncondArray of number of samples per class
[out]xcondArray of conditional expectation along X
[out]ycondArray of conditional expectation along Y

◆ correlation_f()

int correlation_f ( Db db1,
Db db2,
DbGrid dbgrid,
int  flag_same,
int  icol1,
int  icol2,
int  flag_verbose,
double  dmin,
double  dmax,
double  tolang,
double  bench,
double  cylrad,
VectorDouble codir,
int  opt_code,
int  tolcode,
int *  nindice,
int **  indices,
double *  correl 
)

Evaluate the correlation (according to argument flag_same):

  • the standard correlation (flag_same = 1) Correl(Z1(x) , Z2(x))
  • the shifted correlation calculated as follows: Correl(Z1(x) , Z2(x+h))
Returns
Error return code
Parameters
[in]db1Db descriptor (first variable)
[in]db2Db descriptor (second variable for flag.same=T)
[in]dbgridDiscretization Grid descriptor
[in]flag_same1 if the two samples must coincide
[in]icol1Rank of the first column
[in]icol2Rank of the second column
[in]flag_verbose1 for a verbose output
[in]dminMinimum distance
[in]dmaxMaximum distance
[in]tolangAngular tolerance (in degrees)
[in]benchSlicing bench
[in]cylradSlicing radius
[in]codirCalculation direction
[in]opt_codecode selection option
  • 0 : no use of the code selection
  • 1 : codes must be close enough
  • 2 : codes must be different
[in]tolcodeTolerance on the code
[out]nindiceNumber of pairs
[out]indicesArray of the indices of pairs of samples (Dimension: 2 * nindice)
[out]correlCorrelation coefficient
Remarks
The two input Db must match exactly (same number of samples with
same set of coordinates and same optional selection)
The returned array 'indices' contain the set of indices of the
pairs of samples. Its contents is i1,j1,i2,j2,...
The indices are numbered starting from 1
The number of pairs is 'nindice'.
This array must be freed by the calling function

◆ correlation_ident()

int correlation_ident ( Db db1,
Db db2,
int  icol1,
int  icol2,
Polygons polygon 
)

Identify samples from scatter plot when included within a polygon

Returns
Error return code
Parameters
[in]db1Db descriptor (first variable)
[in]db2Db descriptor (second variable for flag.same=T)
[in]icol1Rank of the first column
[in]icol2Rank of the second column
[in]polygonPolygons structure
Remarks
The two input Db must match exactly (same number of samples with
same set of coordinates and same optional selection)

◆ db_variogram()

Db* db_variogram ( Db db,
const VarioParam varioparam 
)

Establish a new Db containing the pairs of the Variogram

Returns
Pointer to the newly created Db
Parameters
[in]dbDb structure
[in]varioparamVarioParam structure

◆ db_variogram_cloud()

DbGrid* db_variogram_cloud ( Db db,
const VarioParam varioparam,
double  lagmax,
double  varmax,
int  lagnb,
int  varnb,
const NamingConvention namconv 
)

Evaluate the experimental variogram cloud

Returns
Error return code
Parameters
[in]dbDb descriptor
[in]varioparamVarioParam structure
[in]lagmaxMaximum distance
[in]varmaxMaximum Variance value
[in]lagnbNumber of discretization steps along distance axis
[in]varnbNumber of discretization steps along variance axis
[in]namconvNaming convention

◆ db_vmap_compute()

DbGrid* db_vmap_compute ( Db db,
const ECalcVario &  calcul_type,
const VectorInt nx_arg,
const VectorDouble dxx,
int  radius,
bool  flag_FFT,
const NamingConvention namconv 
)

Calculate the variogram map

Returns
Error return code
Parameters
[in]dbDb containing the data
[in]calcul_typeType of calculation (ECalcVario)
[in]nx_argVector of (Half-) number of nodes for Vmap (def:20)
[in]dxxVector of mesh for Vmap (see details)
[in]radiusDilation radius (mooth resulting maps) only on points
[in]flag_FFTUse FFT method (only valid on grid)
[in]namconvNaming convention
Remarks
For calculating the default values:
- for nx: it is set to 20 in all directions
- for dx:
. If 'Db' is a grid, the mesh of the grid is used
- Otherwise, the mesh is set to the field extension / nx

◆ dbgrid_model()

int dbgrid_model ( DbGrid dbgrid,
Model model,
const NamingConvention namconv 
)

Calculate the variogram map from a Model (presented as Variogram, not Covariance)

Returns
Error return code
Parameters
[in]dbgridGrid structure
[in]modelModel structure
[in]namconvNaming convention

◆ geometry_compute()

int geometry_compute ( Db db,
Vario vario,
Vario_Order vorder,
int *  npair 
)

Calculate the geometry for a given direction

Returns
Error return code
Parameters
[in]dbDb description
[in]varioVario structure
[out]vorderVario_Order structure
[out]npairNumber of pairs

◆ vardir_copy()

void vardir_copy ( VarioParam vario_in,
int  idir_in,
VarioParam vario_out,
int  idir_out 
)

Copy a direction from one Vario to another Vario

Parameters
[in]vario_inInput Vario structure
[in]idir_inRank of the Input Direction
[in]vario_outOutput Vario structure
[in]idir_outRank of the Output Direction

◆ vardir_print()

void vardir_print ( Vario vario,
int  idir,
int  verbose 
)

Print the experimental variograms in one direction

Parameters
[in]varioVario structure
[in]idirRank of the direction
[in]verbose0 for brief output; 1 for a long output

◆ vario_extract()

int vario_extract ( Vario vario,
ECalcVario *  calcul_type,
int *  ndim,
int *  nvar,
int *  ndir,
int *  ndate,
double *  scale,
double **  dates 
)

Ask the characteristics of the Vario structure

Returns
Error returned code
Parameters
[in]varioVario structure
[out]calcul_typeType of calculation (ECalcVario)
[out]ndimSpace dimension
[out]nvarNumber of variables
[out]ndirNumber of calculation directions
[out]ndateNumber of Date Intervals
[out]scaleScaling factor for the transitive covariogram
[out]datesArray of bounds for Date Intervals
Remarks
The array 'dates' must be freed by calling function.
The following code shows how to extract the calculation results
from a variogram

◆ vario_fix_codir()

void vario_fix_codir ( int  ndim,
VectorDouble codir 
)

Fix plausible values for the Direction coefficients. They must be defined and with norm equal to 1

Parameters
[in]ndimSpace dimension
[in,out]codirInput/Output Direction coefficients

◆ vario_get_rank()

int vario_get_rank ( Vario vario,
int  idir,
int  idate 
)

Ask for the rank of the 'vardir' structure, given direction and date

Returns
Absolute rank (or -1 for error)
Parameters
[in]varioVario structure
[in]idirRank for the direction (starting from 0)
[in]idateRank for the Date (starting from 0)
Remarks
An error occurs if 'idir' is negative or larger than 'ndir'
or if 'idate' is negative or larger than 'ndate'

◆ vario_identify_calcul_type()

ECalcVario vario_identify_calcul_type ( const String calcul_name)

◆ variogram_cloud()

int variogram_cloud ( const Db db,
const VarioParam varioparam,
DbGrid dbgrid,
const NamingConvention namconv 
)

Evaluate the experimental variogram cloud on irregular data

Returns
Error return code
Parameters
[in]dbDb descriptor
[in]varioparamVarioParam structure
[in]dbgridOutput grid for storing the variogram cloud
[in]namconvNaming convention

◆ variogram_cloud_dim()

int variogram_cloud_dim ( Db db,
const VarioParam varioparam,
double *  vmax 
)

Evaluate the bounds for the experimental variogram cloud

Returns
Error return code
Parameters
[in]dbDb descriptor
[in]varioparamVarioParam structure
[out]vmaxMaximum variogram value

◆ variogram_cloud_ident()

void variogram_cloud_ident ( Db db,
DbGrid dbgrid,
Vario vario,
Polygons polygon 
)

Check the samples which are involved in the pairs which are located within the polygon

Parameters
[in]dbDb descriptor
[in]dbgridDiscretization Grid descriptor
[in]varioVario structure
[in]polygonPolygons structure

◆ variogram_direction_add()

int variogram_direction_add ( VarioParam varioparam,
int  npas,
int  opt_code,
int  idate,
double  dpas,
double  toldis,
double  tolang,
double  bench,
double  cylrad,
double  tolcode,
const VectorDouble breaks,
const VectorDouble codir 
)

Initialize a new calculation direction

Returns
Error return code
Parameters
[in]varioparamVarioParam structure
[in]npasnumber of lags
[in]opt_codecode selection option
  • 0 : no use of the code selection
  • 1 : codes must be close enough
  • 2 : codes must be different
[in]idateRank of the Date interval
[in]dpaslag value
[in]toldistolerance on distance (proportion of the lag)
[in]tolangangular tolerance (in degrees)
[in]benchSlicing bench
[in]cylradSlicing radius
[in]tolcodeTolerance on the code
[in]breaksarray for irregular lags
[in]codircalculation direction (Dimension = ndim)

◆ variogram_extension()

void variogram_extension ( const Vario vario,
int  ivar,
int  jvar,
int  idir0,
int  flag_norm,
int  flag_vars,
double  distmin,
double  distmax,
double  varmin,
double  varmax,
int *  flag_hneg,
int *  flag_gneg,
double *  c0,
double *  hmin,
double *  hmax,
double *  gmin,
double *  gmax 
)

Calculate the variogram extension for a pair of variables

Parameters
[in]varioVario structure
[in]ivarRank of the first variable
[in]jvarRank of the second variable
[in]idir0Rank of the direction (-1 for all)
[in]flag_norm1 if the variogram must be normalized by variance
[in]flag_vars1 if the global statistics must be taken into account
[in]distminMinimum along the distance axis
[in]distmaxMaximum along the distance axis
[in]varminMinimum along the variogram (or covariance) axis
[in]varmaxMaximum along the variogram (or covariance) axis
[out]flag_hneg1 if the distance scale can be negative
[out]flag_gneg1 if the variogram scale can be negative
[out]c0Value of the variogram at the origin
[out]hminMinimum distance
[out]hmaxMaximum distance
[out]gminMinimum variogram value
[out]gmaxMaximum variogram value

◆ variogram_get_lag()

int variogram_get_lag ( const DirParam dirparam,
int  idir,
double  ps,
double  psmin,
double *  dist,
bool  flag_asym 
)

Return the rank of the lag

Returns
Rank of the lag or ITEST
Parameters
[in]dirparamDirparam structure
[in]idirDir rank
[in]psCosinus of the angle
[in]psminAngular tolerance
[in]distDistance
[in]flag_asymTrue for asymetric calculation

◆ variogram_maximum_dist1D_reached()

int variogram_maximum_dist1D_reached ( Db db,
int  iech,
int  jech,
double  maxdist 
)

Checks if the maximum variogram distance has been passed

Returns
1 if the maximum distance has been passed and 0 otherwise IDIRLOC = idir;
Parameters
[in]dbDb descriptor
[in]iechRank of the first sample
[in]jechRank of the second sample
[in]maxdistMaximum distance

◆ variogram_mlayers()

int variogram_mlayers ( Db db,
int *  seltab,
Vario vario,
Vario_Order vorder 
)
Determine the samples used for a variogram in multilayers framework
Returns
Error return code
Parameters
[in]dbDb description
[in]seltabNumber of sample definition (0, 1 or 2)
[in]varioVario structure
[out]vorderVario_Order struct ure

◆ variogram_reject_fault()

bool variogram_reject_fault ( const Db db,
int  iech,
int  jech,
const Faults faults 
)

Check if a pair must be rejected or not due to Faulting

Returns
True if the pair must be rejected
Parameters
[in]dbDb description
[in]iechRank of the first sample
[in]jechRank of the second sample
[in]faultsPointer to Faults

◆ variogram_reject_pair()

int variogram_reject_pair ( const Db db,
int  iech,
int  jech,
double  dist,
double  psmin,
double  bench,
double  cylrad,
const VectorDouble codir,
double *  ps 
)

Check if a pair must be rejected or not

Returns
1 if the pair must be rejected
Parameters
[in]dbDb description
[in]iechRank of the first sample
[in]jechRank of the second sample
[in]distDistance between the two samples
[in]psminDirection cosine
[in]benchSlicing bench
[in]cylradSlicing radius
[in]codirDirection
[out]psThe cosine between the vector of data and the direction

◆ variogram_scale()

void variogram_scale ( Vario vario,
int  idir 
)

Scale the variogram calculations

Parameters
[in]varioVario structure
[in]idirRank of the Direction

◆ variogram_trans_cut()

void variogram_trans_cut ( Vario vario,
int  nh,
double  ycut 
)

Calculate the experimental variogram of the completed variable starting from the experimental variogram of the truncated variable

Parameters
[in,out]varioVario structure
[in]nhNumber of Hermite polynomials
[in]ycutTruncation (lowest) value

◆ variogram_y2z()

int variogram_y2z ( Vario vario,
AAnam anam,
Model model 
)

Calculate the experimental variogram of the Raw starting from the Model of the Gaussian variable

Returns
Error return code
Parameters
[in,out]varioExperimental variogram
[in]anamPoint anamorphosis
[in]modelModel of the Punctual Gaussian
Remarks
At entrance, the input variogram only serves in providing
the calculation parameters

◆ variovect_compute()

int variovect_compute ( Db db,
Vario vario,
int  ncomp 
)

Evaluate the experimental covariance for directional variables

Returns
Error return code
Parameters
[in]dbDb descriptor
[in]varioVario structure
[in]ncompNumber of components

◆ vmap_compute()

int vmap_compute ( Db db,
DbGrid dbmap,
const ECalcVario &  calcul_type,
int  radius,
bool  flag_FFT,
const NamingConvention namconv 
)

Calculate the variogram map

Returns
Error return code
Parameters
[in]dbDb containing the data
[in]dbmapVMAP grid structure
[in]calcul_typeType of calculation (ECalcVario)
[in]radiusDilation radius (mooth resulting maps) only on points
[in]flag_FFTUse FFT method (only valid on grid)
[in]namconvNaming convention