1.1.0
CCC
 
model.cpp File Reference

Functions

void model_nostat_update (CovInternal *covint, Model *model)
 
void model_covtab_init (int flag_init, Model *model, double *covtab)
 
void model_calcul_cov (CovInternal *covint, Model *model, const CovCalcMode *mode, int flag_init, double weight, VectorDouble d1, double *covtab)
 
const CovInternalget_external_covariance ()
 
int is_model_nostat_param (Model *model, const EConsElem &type0)
 
int model_add_cova (Model *model, const ECov &type, int flag_aniso, int flag_rotation, double range, double param, const VectorDouble &aniso_ranges, const VectorDouble &aniso_rotmat, const VectorDouble &sill, double)
 
double cova_get_scale_factor (const ECov &type, double param)
 
int model_update_coreg (Model *model, double *aic, double *valpro, double *vecpro)
 
int model_evaluate (Model *model, int ivar, int jvar, const CovCalcMode *mode, int nh, VectorDouble &codir, const double *h, double *g)
 
int model_evaluate_nostat (Model *model, int ivar, int jvar, const CovCalcMode *mode, Db *db1, int iech1, Db *db2, int iech2, int nh, VectorDouble &codir, double *h, double *g)
 
int model_grid (Model *model, Db *db, int ivar, int jvar, const CovCalcMode *mode, double *g)
 
int model_nfex (Model *model)
 
double model_cxx (Model *model, Db *db1, Db *db2, int ivar, int jvar, int seed, double eps, const CovCalcMode *mode)
 
double * model_covmat_by_ranks (Model *model, Db *db1, int nsize1, const int *ranks1, Db *db2, int nsize2, const int *ranks2, int ivar0, int jvar0, const CovCalcMode *mode)
 
int model_drift_mat (Model *model, const ECalcMember &member, Db *db, double *drfmat)
 
int model_drift_vector (Model *model, const ECalcMember &member, Db *db, int iech, double *vector)
 
Modelmodel_duplicate_for_gradient (const Model *model, double ball_radius)
 
void model_covupdt (Model *model, double *c0, int flag_verbose, int *flag_nugget, double *nugget)
 
double model_drift_evaluate (int, Model *model, const Db *db, int iech, int ivar, double *coef)
 
void model_cova_characteristics (const ECov &type, char cov_name[STRING_LENGTH], int *flag_range, int *flag_param, int *min_order, int *max_ndim, int *flag_int_1d, int *flag_int_2d, int *flag_aniso, int *flag_rotation, double *scale, double *parmax)
 
int model_sample (Vario *vario, Model *model, const CovCalcMode *mode)
 
Modelmodel_combine (const Model *model1, const Model *model2, double r)
 
int model_regularize (Model *model, Vario *vario, DbGrid *dbgrid, const CovCalcMode *mode)
 
int model_covmat_inchol (int verbose, Db *db, Model *model, double eta, int npivot_max, int nsize1, int *ranks1, double *center, int flag_sort, int *npivot_arg, int **Pret, double **Gret, const CovCalcMode *mode)
 
double model_calcul_stdev (Model *model, Db *db1, int iech1, Db *, int iech2, int verbose, double factor, const CovCalcMode *mode)
 
MatrixSparsemodel_covmat_by_ranks_Mat (Model *model, Db *db1, int nsize1, const VectorInt &ranks1, Db *db2, int nsize2, const VectorInt &ranks2, int ivar0, int jvar0, const CovCalcMode *mode)
 
int model_covmat (Model *model, Db *db1, Db *db2, int ivar0, int jvar0, double *covmat, const CovCalcMode *mode)
 
MatrixSquareSymmetric model_covmatM (Model *model, Db *db1, Db *db2, int ivar0, int jvar0, const CovCalcMode *mode)
 

Variables

int NDIM_LOCAL = 0
 
VectorDouble X1_LOCAL = VectorDouble()
 
VectorDouble X2_LOCAL = VectorDouble()
 

Function Documentation

double cova_get_scale_factor ( const ECov &  type,
double  param 
)

For a given basic structure, get the reduction factor to convert the theoretical to practical scale

Returns
Conversion factor
Parameters
[in]typeType of the basic structure
[in]paramValue of the third parameter
const CovInternal* get_external_covariance ( )

Identify the coordinates of the two end-points (used by the external covariance function)

Returns
A (protected) pointer on the Covariance Internal class
int is_model_nostat_param ( Model model,
const EConsElem &  type0 
)

Check if the non-stationary Model has a given non-stationary parameter

Returns
1 if the given non-stationary parameter is defined; 0 otherwise
Parameters
[in]modelModel structure
[in]type0Requested type (EConsElem)
int model_add_cova ( Model model,
const ECov &  type,
int  flag_aniso,
int  flag_rotation,
double  range,
double  param,
const VectorDouble aniso_ranges,
const VectorDouble aniso_rotmat,
const VectorDouble sill,
double   
)

Add a basic covariance

Returns
Error return code
Parameters
[in]modelPointer to the Model structure
[in]typeType of the basic structure
[in]flag_aniso1 if the basic structure is anisotropic
[in]flag_rotation1 if the basic structure is rotated (only when anisotropic)
[in]rangeIsotropic range of the basic structure
[in]paramAuxiliary parameter
[in]aniso_rangesArray giving the anisotropy ranges Only used when flag_aniso (Dimension = ndim)
[in]aniso_rotmatAnisotropy rotation matrix Only used when flag_aniso && flag_rotation (Dimension = ndim * ndim)
[in]sillSill matrix (optional) (Dimension = nvar * nvar)
void model_calcul_cov ( CovInternal covint,
Model model,
const CovCalcMode mode,
int  flag_init,
double  weight,
VectorDouble  d1,
double *  covtab 
)

Returns the covariances for an increment This is the generic internal function It can be called for stationary or non-stationary case

Parameters
[in]covintInternal structure for non-stationarityAddress for the next term after the drift or NULL (for stationary case)
[in]modelModel structure
[in]modeCovCalcMode structure
[in]flag_initInitialize the array beforehand
[in]weightMultiplicative weight
[out]d1Working array (dimension = ndim) or NULL
[out]covtaboutput covariance (dimension = nvar * nvar)
double model_calcul_stdev ( Model model,
Db db1,
int  iech1,
Db ,
int  iech2,
int  verbose,
double  factor,
const CovCalcMode mode 
)

Returns the standard deviation at a given increment for a given model

Parameters
[in]modelStructure containing the model
[in]db1First Db
[in]iech1Rank in the first Db
[in]iech2Rank in the second Db
[in]verboseVerbose flag
[in]factorMultiplicative factor for standard deviation
[in]modeCovCalcMode structure
Model* model_combine ( const Model model1,
const Model model2,
double  r 
)

Combine two monovariate models into a bivariate model (residuals model)

Returns
Pointer to the newly created Model structure
Parameters
[in]model1First input Model
[in]model2Second input Model
[in]rCorrelation coefficient
Remarks
: The drift is not copied into the new model
: It has been extended to the case where only one model is defined
void model_cova_characteristics ( const ECov &  type,
char  cov_name[STRING_LENGTH],
int *  flag_range,
int *  flag_param,
int *  min_order,
int *  max_ndim,
int *  flag_int_1d,
int *  flag_int_2d,
int *  flag_aniso,
int *  flag_rotation,
double *  scale,
double *  parmax 
)

Returns the characteristics of the covariance

Parameters
[in]typeType of the covariance
[out]cov_nameName of the covariance
[out]flag_rangerange definition
  • +1 if the range is defined
  • -1 if the range is redundant with the sill
[out]flag_param1 if the third parameter is defined
[out]min_orderMinimum IRF order for validity
[out]max_ndimMaximum dimension for validity
[out]flag_int_1dIntegral range in 1-D
[out]flag_int_2dIntegral range in 2-D
[out]flag_aniso1 if anisotropy is meaningful
[out]flag_rotation1 if an anisotropy rotation is meaningful
[out]scaleScaling parameter
[out]parmaxMaximum value for the third parameter
int model_covmat ( Model model,
Db db1,
Db db2,
int  ivar0,
int  jvar0,
double *  covmat,
const CovCalcMode mode 
)

Establish the covariance matrix between two Dbs

Parameters
[in]modelModel structure
[in]db1First Db
[in]db2Second Db
[in]ivar0Rank of the first variable (-1: all variables)
[in]jvar0Rank of the second variable (-1: all variables)
[in]modeCovCalcMode structure
[out]covmatThe covariance matrix (Dimension = (nactive * nvar) [squared]) nactive: Number of samples active nvar : Number of selected variables (1 or nvar)
Remarks
: If db2 is not provided, it is set to db1
double* model_covmat_by_ranks ( Model model,
Db db1,
int  nsize1,
const int *  ranks1,
Db db2,
int  nsize2,
const int *  ranks2,
int  ivar0,
int  jvar0,
const CovCalcMode mode 
)

Establish the covariance matrix between two Dbs where samples are selected by ranks

Returns
Array containing the covariance matrix
Parameters
[in]modelModel structure
[in]db1First Db
[in]nsize1Number of selected samples
[in]ranks1Array giving ranks of selected samples (optional)
[in]db2Second Db
[in]nsize2Number of selected samples
[in]ranks2Array giving ranks of selected samples (optional)
[in]ivar0Rank of the first variable (-1: all variables)
[in]jvar0Rank of the second variable (-1: all variables)
[in]modeCovCalcMode structure
Remarks
The covariance matrix (returned) must be freed by calling routine
Its dimension is nsize1 * nsize2 * nvar * nvar
where 'nvar' is the number of active variables (1 or nvar)
The covariance matrix is established for the first variable
and returned as a covariance
As the ranks are used, no test is performed on any selection
but only ranks positive or null are considered
MatrixSparse* model_covmat_by_ranks_Mat ( Model model,
Db db1,
int  nsize1,
const VectorInt ranks1,
Db db2,
int  nsize2,
const VectorInt ranks2,
int  ivar0,
int  jvar0,
const CovCalcMode mode 
)

Establish the covariance matrix between two Dbs where samples are selected by ranks The output is stored in a Sparse Matrix

Returns
Array containing the covariance matrix
Parameters
[in]modelModel structure
[in]db1First Db
[in]nsize1Number of selected samples
[in]ranks1Array giving ranks of selected samples (optional)
[in]db2Second Db
[in]nsize2Number of selected samples
[in]ranks2Array giving ranks of selected samples (optional)
[in]ivar0Rank of the first variable (-1: all variables)
[in]jvar0Rank of the second variable (-1: all variables)
[in]modeCovCalcMode structure
Remarks
The covariance matrix (returned) must be freed by calling routine
The covariance matrix is established for the first variable
and returned as a covariance
As the ranks are used, no test is performed on any selection
but only ranks positive or null are considered
int model_covmat_inchol ( int  verbose,
Db db,
Model model,
double  eta,
int  npivot_max,
int  nsize1,
int *  ranks1,
double *  center,
int  flag_sort,
int *  npivot_arg,
int **  Pret,
double **  Gret,
const CovCalcMode mode 
)

Establish and invert a covariance matrix using Incomplete Cholesky method

Parameters
[in]verboseVerbose option
[in]dbDb structure
[in]modelModel structure
[in]npivot_maxMaximum number of pivots (or 0)
[in]etaPrecision (or TEST)
[in]nsize1Number of pivots already selected
[in]ranks1Ranks of pivots already selected
[in]centerOptional Centering point (for increments)
[in]flag_sortReordering flag (see remarks)
[in]modeCovCalcMode structure
[out]npivot_argNumber of pivots
[out]PretArray of indices of the retained samples (from 1) Dimension: nech
[out]GretRectangular matrix Dimension: nech * npivot_arg
Remarks
The output arrays Pret and Gret should be freed by calling function
The array G contains as many lines as there are samples
If flag_sort = FALSE, the first lines concentrate on pivots,
and the other points are located afterwards
If flag_sort = TRUE, the lines are sorted in the same order as the
initial set of samples
The incomplete Cholsky algorithm stops when either the next pivot
value is below 'eta' or when maximum number of pivots 'npivot_max'
has been reached
If the center point is provided in 'center', the calculations
of covariance of increments are calculated instead. Then 'center'
must provide the coordinates of the origin point.
MatrixSquareSymmetric model_covmatM ( Model model,
Db db1,
Db db2,
int  ivar0,
int  jvar0,
const CovCalcMode mode 
)
void model_covtab_init ( int  flag_init,
Model model,
double *  covtab 
)

Initializes the covtab array

Parameters
[in]flag_init1 If covtab() must be initialized; 0 otherwise
[in]modelModel structure
[in]covtabArray to be initialized
void model_covupdt ( Model model,
double *  c0,
int  flag_verbose,
int *  flag_nugget,
double *  nugget 
)

Update the model for fitting Covariance or Covariogram

Parameters
[in]modelModel structure
[in]c0Array of variance values at the origin
[in]flag_verbose1 for verbose output
[out]flag_nugget1 if a nugget component must be added
[out]nuggetArray of sills for the nugget component

TODO : dead code ?

double model_cxx ( Model model,
Db db1,
Db db2,
int  ivar,
int  jvar,
int  seed,
double  eps,
const CovCalcMode mode 
)

Evaluate the average model between two Dbs

Returns
Average model value
Parameters
[in]modelModel structure
[in]db1First Db
[in]db2Second Db
[in]ivarRank of the first variable
[in]jvarRank of the second variable
[in]seedSeed for the random number generator
[in]epsEpsilon used for randomization in calculation of CVV
[in]modeCovCalcMode structure
double model_drift_evaluate ( int  ,
Model model,
const Db db,
int  iech,
int  ivar,
double *  coef 
)

Evaluate the drift with a given set of coefficients

Parameters
[in]modelModel structure
[in]dbDb structure
[in]iechRank of the sample
[in]ivarRank of the variable
[in]coefArray of coefficients (optional)
int model_drift_mat ( Model model,
const ECalcMember &  member,
Db db,
double *  drfmat 
)

Establish the drift rectangular matrix for a given Db

Returns
Error return code
Parameters
[in]modelModel structure
[in]memberMember of the Kriging System (ECalcMember)
[in]dbDb structure
[out]drfmatThe drift matrix (Dimension = nech * nvar * nfeq * nvar)
int model_drift_vector ( Model model,
const ECalcMember &  member,
Db db,
int  iech,
double *  vector 
)

Establish the drift vector for a given sample of the Db

Parameters
[in]modelModel structure
[in]memberMember of the Kriging System (ECalcMember)
[in]dbDb structure
[in]iechRank of the particular sample
[out]vectorReturned vector (Dimension = nvar * nfeq)
Model* model_duplicate_for_gradient ( const Model model,
double  ball_radius 
)

Duplicates a Model from another Model for Gradients

Returns
The modified Model structure
Parameters
[in]modelInput Model
[in]ball_radiusRadius for Gradient calculation
int model_evaluate ( Model model,
int  ivar,
int  jvar,
const CovCalcMode mode,
int  nh,
VectorDouble codir,
const double *  h,
double *  g 
)

Calculate the value of the model for a set of distances

Returns
Error return code
Parameters
[in]modelModel structure
[in]ivarRank of the first variable
[in]jvarRank of the second variable
[in]modeCovCalcMode structure
[in]nhNumber of increments
[in]codirArray giving the direction coefficients
[in]hVector of increments
[out]gArray containing the model values
Remarks
When rank_sel is positive, it indicates the rank of the only
basic structure to be accounted for
int model_evaluate_nostat ( Model model,
int  ivar,
int  jvar,
const CovCalcMode mode,
Db db1,
int  iech1,
Db db2,
int  iech2,
int  nh,
VectorDouble codir,
double *  h,
double *  g 
)

Calculate the value of the model for a set of distances (non stationary)

Returns
Error return code
Parameters
[in]modelModel structure
[in]ivarRank of the first variable
[in]jvarRank of the second variable
[in]modeCovCalcMode structure
[in]db1First Db structure
[in]iech1First sample
[in]db2Second Db structure
[in]iech2Second sample
[in]nhNumber of increments
[in]codirArray giving the direction coefficients
[in]hVector of increments
[out]gArray containing the model values
Remarks
When rank_sel is positive, it indicates the rank of the only
basic structure to be accounted for
int model_grid ( Model model,
Db db,
int  ivar,
int  jvar,
const CovCalcMode mode,
double *  g 
)

Evaluate the model on a regular grid

Parameters
[in]modelModel structure
[in]dbDb structure
[in]ivarRank of the first variable
[in]jvarRank of the second variable
[in]modeCovCalcMode structure
[out]gArray containing the model values
int model_nfex ( Model model)

Returns the number of external drift functions

Returns
Number of external drift functions
Parameters
[in]modelModel structure
void model_nostat_update ( CovInternal covint,
Model model 
)

Update the Model in the case of Non-stationary parameters This requires the knowledge of the two end-points

Parameters
[in]covintInternal structure for non-stationarity or NULL (for stationary case)
[in]modelModel structure
int model_regularize ( Model model,
Vario vario,
DbGrid dbgrid,
const CovCalcMode mode 
)

Calculate the regularized model as an experimental variogram

Returns
Error return code
Parameters
[in]modelModel structure
[in]varioVario structure
[in]dbgridDb discretization grid structure
[in]modeCovCalcMode structure
int model_sample ( Vario vario,
Model model,
const CovCalcMode mode 
)

Calculates variogram values by sampling a model

Returns
Error return code
Parameters
[in]varioVario structure
[in]modelModel structure
[in]modeCovCalcMode structure
int model_update_coreg ( Model model,
double *  aic,
double *  valpro,
double *  vecpro 
)

Calculate the linear model of coregionalization starting from the coregionalization matrix

Returns
Error return code.
Parameters
[in]modelModel structure
[out]aicarray of 'aic' values
[out]valproarray of eigen values
[out]vecproarray of eigen vectors
Remarks
In case of error, the message is printed by the routine
Warning: in the case of linked drift, the test of definite
positiveness is bypassed as we are not in the scope of the
linear model of coregionalization anymore.
As a consequence the array "aic()" is not evaluated

Variable Documentation

int NDIM_LOCAL = 0
VectorDouble X1_LOCAL = VectorDouble()
VectorDouble X2_LOCAL = VectorDouble()