1.4.0
CCC
 
stats.cpp File Reference
#include "geoslib_old_f.h"
#include "Morpho/Morpho.hpp"
#include "Basic/VectorNumT.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/Law.hpp"
#include "Basic/String.hpp"
#include "Basic/OptDbg.hpp"
#include "Db/Db.hpp"
#include "Db/DbGrid.hpp"
#include "Stats/Classical.hpp"
#include "Basic/Memory.hpp"
#include "Basic/Grid.hpp"
#include "Core/Keypair.hpp"
#include <math.h>
#include <string.h>

Functions

static double st_extract_subgrid (int verbose, int flag_ffff, int iech0, int nech0, int ntot, DbGrid *dbgrid, int *ind0, int *ixyz, int *nxyz, double *numtab1, double *valtab1)
 
static int st_divide_by_2 (int *nxyz, int orient)
 
static void st_mean_arith (int idim, const int *nxyz1, const int *nxyz2, const double *numtab1, double *numtab2, double *valtab1, double *valtab2)
 
static void st_mean_harmo (int idim, const int *nxyz1, const int *nxyz2, const double *numtab1, double *numtab2, double *valtab1, double *valtab2)
 
static int st_recopy (const int *nxyz1, const double *numtab1, const double *valtab1, int *nxyz2, double *numtab2, double *valtab2)
 
static void st_print_grid (const char *subtitle, int nxyz[3], double *numtab, double *valtab)
 
static void st_print_upscale (const char *title, int *nxyz, const double *valtab)
 
static void st_upscale (int orient, int *nxyz, int flag_save, double *numtab0, double *numtab1, double *numtab2, double *valtab0, double *valtab1, double *valtab2, double *res1, double *res2)
 
static int st_is_subgrid (int verbose, const char *title, DbGrid *dbgrid1, DbGrid *dbgrid2, int *ind0, int *nxyz, int *ntot)
 
int db_upscale (DbGrid *dbgrid1, DbGrid *dbgrid2, int orient, int verbose)
 
static double st_squared_distance (int orient, int ndim, const int *locini, const int *loccur)
 
static void st_sample_to_grid (int ndim, int ntot, const int *nxyz, int iech, int *indg)
 
static int st_grid_to_sample (int ndim, const int *nxyz, const int *indg)
 
static int st_fixed_position (int ntot, const double *tab, int cell)
 
static int st_find_cell (int ntot, const double *tab, double proba)
 
static void st_migrate_seed (int ndim, int n_nbgh, int *nxyz, const int *nbgh, double *valwrk, const double *valtab0, int *locwrk, int *loccur)
 
static void st_print_position (int ndim, int iseed, int iter, int *tab)
 
static void st_updiff (int orient, int ndim, int ntot, int nseed, int niter, int n_nbgh, int flag_save, double probtot, int *nxyz, int *nbgh, int *tabini, int *tabcur, int *tabwrk, double *valwrk, double *valtab0, int verbose, double *cvdist2, double *trsave)
 
static void st_update_regression (double x, double y, double *count, double *sum_x, double *sum_y, double *sum_xx, double *sum_xy)
 
static double st_get_diff_coeff (int niter, int verbose, double pmid, int flag_save, double *cvdist2, double *cvsave)
 
int db_diffusion (DbGrid *dbgrid1, DbGrid *dbgrid2, int orient, int niter, int nseed, int seed, int verbose)
 
int stats_residuals (int verbose, int nech, const double *tab, int ncut, double *zcut, int *nsorted, double *mean, double *residuals, double *T, double *Q)
 

Variables

static int DEBUG = 0
 

Function Documentation

◆ db_diffusion()

int db_diffusion ( DbGrid dbgrid1,
DbGrid dbgrid2,
int  orient,
int  niter,
int  nseed,
int  seed,
int  verbose 
)

Calculate the diffusion factor from a grid Db into another grid Db

Returns
Error return code
Parameters
[in]dbgrid1Db for the input grid
[in]dbgrid2Db for the output grid
[in]orientDiffusion orientation (0 or the space rank dimension)
[in]niterNumber of iterations
[in]nseedNumber of seeds
[in]seedSeed for the random number generation
[in]verboseVerbose Option
Remarks
The user may specify the type of storage
0: average squared distance; 1: slope; 2: origin
get.keypair("Diffusion.Converge.Option",0)
The neighborhood is Block(0) or Cross(1) according to
get.keypair("Diffusion.Converge.Morpho",0)
The rank of the convergence if measured from a Starting to an Ending
percentages of the 'niter' iterations. The 'Mid' percentage gives
the value assigned to the output block
get.keypair("Diffusion.Converge.PMid",70)
The user can specify the block of interest by using:
get.keypair("Diffusion.Converge.Block")
For the target block, the array of squared distances as a function
of the iteration is returned using the keypair mechanism:
set.keypair("Diffusion.Converge")
For the target block, the trajectories are saved using keypair;
set.keypair("Diffusion.Trajectory.XX")

◆ db_upscale()

int db_upscale ( DbGrid dbgrid1,
DbGrid dbgrid2,
int  orient,
int  verbose 
)

Upscale one variable from a grid Db into another grid Db

Returns
Error return code
Parameters
[in]dbgrid1Db for the input grid
[in]dbgrid2Db for the output grid
[in]orientUpscaling direction (0 to 2)
[in]verboseVerbose flag

◆ st_divide_by_2()

static int st_divide_by_2 ( int *  nxyz,
int  orient 
)
static

Divide by 2 in integer (upper rounded value)

Returns
1 if the input value is larger than 2; 0 otherwise
Parameters
[in]nxyzDimensions of the subgrid
[in]orientRank of the target direction

◆ st_extract_subgrid()

static double st_extract_subgrid ( int  verbose,
int  flag_ffff,
int  iech0,
int  nech0,
int  ntot,
DbGrid dbgrid,
int *  ind0,
int *  ixyz,
int *  nxyz,
double *  numtab1,
double *  valtab1 
)
static

Load the subgrid from the Input Db

Returns
Return the total probability of finding joins
Parameters
[in]verboseVerbose flag
[in]flag_ffff1 replace masked values by 0 0 replace masked values by FFFF
[in]iech0Rank of the output grid cell
[in]nech0Number of cells of the output grid
[in]ntotDimension of arrays 'numtab1' and 'valtab1'
[in]dbgridDb for the input grid
[in]ind0Origin of the Output Db within the Input Db
[in]nxyzMesh of the Output Db (expressed in Input Db)
[in]ixyzIndices of the starting node of the Output Db
[out]numtab1Array containing the sample count
[out]valtab1Array containing the sample value
Remarks
The array ind0, ixyz and nxyz are dimensioned to ndim

◆ st_find_cell()

static int st_find_cell ( int  ntot,
const double *  tab,
double  proba 
)
static

Find the cell linked to the probability

Returns
Rank of the cell
Parameters
[in]ntotNumber of possibilities
[in]tabArray containing the sample value
[in]probaLocal probability

◆ st_fixed_position()

static int st_fixed_position ( int  ntot,
const double *  tab,
int  cell 
)
static

Find the location of the cell (within the possible cells) which is the closest to the target cell provided as argument

Returns
Rank of the cell
Parameters
[in]ntotNumber of possibilities
[in]tabArray containing the sample value
[in]cellCell location

◆ st_get_diff_coeff()

static double st_get_diff_coeff ( int  niter,
int  verbose,
double  pmid,
int  flag_save,
double *  cvdist2,
double *  cvsave 
)
static

Derive the diffusion factor from the serie of squared distance as a function of time

Returns
The diffusion coefficient
Parameters
[in]niterNumber of iterations
[in]verboseVerbose flag
[in]pmidPercentage of niter to store convergence
[in]flag_saveIf the array must be saved for keypair
[in]cvdist2Array containing the squared distances
[out]cvsaveArray containing the storage (Dimension: 3 * niter)

◆ st_grid_to_sample()

static int st_grid_to_sample ( int  ndim,
const int *  nxyz,
const int *  indg 
)
static

Converts from grid indices into sample index

Returns
The absolute index
Parameters
[in]ndimSpace dimension
[in]nxyzDimensions of the subgrid
[in]indgGrid indices

◆ st_is_subgrid()

static int st_is_subgrid ( int  verbose,
const char *  title,
DbGrid dbgrid1,
DbGrid dbgrid2,
int *  ind0,
int *  nxyz,
int *  ntot 
)
static

Check if the first grid is a subgrid of the second one

Returns
1 if grids are multiple
Parameters
[in]verboseVerbose flag
[in]titleTitle of the work (used only for verbose case)
[in]dbgrid1Db for the input grid
[in]dbgrid2Db for the output grid
[out]ind0Starting address
[out]nxyzNumber of subdivisions
[out]ntotTotal number of grid nodes

◆ st_mean_arith()

static void st_mean_arith ( int  idim,
const int *  nxyz1,
const int *  nxyz2,
const double *  numtab1,
double *  numtab2,
double *  valtab1,
double *  valtab2 
)
static

Perform the arithmetic mean

Parameters
[in]idimDirection of calculation
[in]nxyz1Dimensions of the initial subgrid
[in]nxyz2Dimensions of the final subgrid
[out]numtab1Array containing the sample count
[out]numtab2Array containing the sample count
[out]valtab1Array containing the sample value
[out]valtab2Array containing the sample value

◆ st_mean_harmo()

static void st_mean_harmo ( int  idim,
const int *  nxyz1,
const int *  nxyz2,
const double *  numtab1,
double *  numtab2,
double *  valtab1,
double *  valtab2 
)
static

Perform the harmonic mean

Parameters
[in]idimDirection of calculation
[in]nxyz1Dimensions of the initial subgrid
[in]nxyz2Dimensions of the final subgrid
[out]numtab1Array containing the input sample count
[out]numtab2Array containing the output sample count
[out]valtab1Array containing the input sample value
[out]valtab2Array containing the output sample value

◆ st_migrate_seed()

static void st_migrate_seed ( int  ndim,
int  n_nbgh,
int *  nxyz,
const int *  nbgh,
double *  valwrk,
const double *  valtab0,
int *  locwrk,
int *  loccur 
)
static

Migrate the seed to one of the available neighboring cells

Parameters
[in]ndimSpace dimension
[in]n_nbghNumber of neighboring cells
[in]nxyzDimensions of the subgrid
[in]nbghArray giving the neighboring cell location
[in]valwrkWorking array (Dimension: n_nbgh)
[in]valtab0Array containing the sample value
[in]locwrkWorking array for shifted seed positions
[in,out]loccurCurrent seed position

◆ st_print_grid()

static void st_print_grid ( const char *  subtitle,
int  nxyz[3],
double *  numtab,
double *  valtab 
)
static

Print the generated grids (for counts and values)

Parameters
[in]subtitleSubtitle
[in]nxyzDimensions of the grid
[out]numtabArray containing the sample count
[out]valtabArray containing the sample value

◆ st_print_position()

static void st_print_position ( int  ndim,
int  iseed,
int  iter,
int *  tab 
)
static

Print the position (debug option)

Parameters
[in]ndimSpace dimension
[in]iseedRank of the trajectory (from 0)
[in]iterRank of the iteration (from 0)
[in]tabArray containing the coordinates of the position
Remarks
This very verbose option only functions if verbose is TRUE
and the internal flag DEBUG is TRUE (this requires compiling)

◆ st_print_upscale()

static void st_print_upscale ( const char *  title,
int *  nxyz,
const double *  valtab 
)
static

Print statistics after basic upscaling operation

Parameters
[in]titleTitle for the printout
[in]nxyzGrid dimension
[out]valtabArray containing the sample value

◆ st_recopy()

static int st_recopy ( const int *  nxyz1,
const double *  numtab1,
const double *  valtab1,
int *  nxyz2,
double *  numtab2,
double *  valtab2 
)
static

Update the dimensions and calculate the current number of cells

Returns
Number of cells
Parameters
[in]nxyz1Dimensions of the initial subgrid
[in]numtab1Array containing the sample count
[in]valtab1Array containing the sample value
[out]nxyz2Dimensions of the final subgrid
[out]numtab2Array containing the sample count
[out]valtab2Array containing the sample value

◆ st_sample_to_grid()

static void st_sample_to_grid ( int  ndim,
int  ntot,
const int *  nxyz,
int  iech,
int *  indg 
)
static

Converts from sample index into grid indices

Parameters
[in]ndimSpace dimension
[in]ntotTotal number of cells in subgrid
[in]nxyzDimensions of the subgrid
[in]iechRank of the sample
[out]indgGrid indices

◆ st_squared_distance()

static double st_squared_distance ( int  orient,
int  ndim,
const int *  locini,
const int *  loccur 
)
static

Calculate the euclidean distance between current and initial seed locations

Returns
Calculated squared distance
Parameters
[in]orientDiffusion orientation (0 or the space rank dimension)
[in]ndimSpace dimension
[in]lociniInitial seed positions
[in]loccurCurrent seed positions

◆ st_update_regression()

static void st_update_regression ( double  x,
double  y,
double *  count,
double *  sum_x,
double *  sum_y,
double *  sum_xx,
double *  sum_xy 
)
static

Update the quantities needed for calculating the linear regression amongst a set of 2-D points

Parameters
[in]xX value
[in]yY value
[in,out]countNumber of samples
[in,out]sum_xSum of the X variable
[in,out]sum_ySum of the Y variable
[in,out]sum_xxSum of the X*X variable
[in,out]sum_xySum of the X*Y variable

◆ st_updiff()

static void st_updiff ( int  orient,
int  ndim,
int  ntot,
int  nseed,
int  niter,
int  n_nbgh,
int  flag_save,
double  probtot,
int *  nxyz,
int *  nbgh,
int *  tabini,
int *  tabcur,
int *  tabwrk,
double *  valwrk,
double *  valtab0,
int  verbose,
double *  cvdist2,
double *  trsave 
)
static

Calculate the average squared distance as a function of the iteration

Parameters
[in]orientDiffusion orientation (0 or the space rank dimension)
[in]ndimSpace dimension
[in]ntotTotal number of cells in the subgrid
[in]nseedNumber of seeds
[in]niterNumber of iterations
[in]n_nbghNumber of neighboring cells
[in]flag_saveIf the array must be saved for keypair
[in]probtotTotal probability of joins
[in]nxyzDimensions of the subgrid
[in]nbghArray giving the neighboring cell location
[in]tabiniArray of initial seed positions Dimension: nseed * ndim
[in]tabcurArray of current seed positions Dimension: nseed * ndim
[in]tabwrkArray of shifted seed positions Dimension: ndim
[in]valwrkWorking array Dimension: n_nbgh
[in]valtab0Array containing the sample value
[in]verboseVerbose option
[out]cvdist2Array of squared distances by iteration
[out]trsaveArray of trajectories (saved only if defined)
Remarks
If the starting position is fixed, it is specified using: set_keypair("Fixed_Position",...)

◆ st_upscale()

static void st_upscale ( int  orient,
int *  nxyz,
int  flag_save,
double *  numtab0,
double *  numtab1,
double *  numtab2,
double *  valtab0,
double *  valtab1,
double *  valtab2,
double *  res1,
double *  res2 
)
static

Upscale the variable defined on a subgrid into one value

Parameters
[in]orientUpscaling orientation (0 to 2)
[in]nxyzDimensions of the subgrid
[in]flag_saveIf the array must be saved for keypair
[out]numtab0Array containing the sample count
[out]numtab1Array containing the sample count
[out]numtab2Array containing the sample count
[out]valtab0Array containing the sample value
[out]valtab1Array containing the sample value
[out]valtab2Array containing the sample value
[out]res1First result (Harmonic first)
[out]res2First result (Arithmetic first)

◆ stats_residuals()

int stats_residuals ( int  verbose,
int  nech,
const double *  tab,
int  ncut,
double *  zcut,
int *  nsorted,
double *  mean,
double *  residuals,
double *  T,
double *  Q 
)

Create residuals

Returns
Error returned code
Parameters
[in]verboseVerbose flag
[in]nechNumber of samples
[in]tabArray of sample values (Dimension: nech)
[in]ncutNumber of cutoffs
[in]zcutArray of cutoff values (Dimension: ncut)
[out]nsortedNumber of sorted samples
[out]meanAverage of the active data
[out]residualsArray of residuals (Dimension: ncut * nech)
[out]TArray of for tonnage
[out]QArray of for metal quantity

Variable Documentation

◆ DEBUG

int DEBUG = 0
static