2.1.24.4.4 ocmath_2d_binning_ex


Version

Minimum Origin Version Required: Origin 2016 SR0

Description

Compute descriptive statistics for 2D binning on three arrays pX, pY and pQuantity.

Syntax

int ocmath_2d_binning_ex( int nSize, const double * pX, const double * pY, const double * pQuantity, BinningStatsResult * pResult, int nStats, BinningOption * pOptionX = NULL, BinningOption * pOptionY = NULL )

Parameters

nSize
[input]size of the X and Y array
pX
[input]pointer to buffer of the X array data
pY
[input]pointer to buffer of the Y array data
pQuantity
[input]pointer to buffer of the quantity to communicate, it can be NULL for nStats equals to OCMATH_2D_BINNING_COUNT or OCMATH_2D_BINNING_PERCENTAGES
pResult
[output]pointer to result structure
nStats
[input]One of the following:
enum{
OCMATH_2D_BINNING_MIN,
OCMATH_2D_BINNING_MAX,
OCMATH_2D_BINNING_MEAN,
OCMATH_2D_BINNING_SUM,
OCMATH_2D_BINNING_MEDIAN,
OCMATH_2D_BINNING_COUNT,
OCMATH_2D_BINNING_PERCENTAGES,
};
pOptionX
[input]pointer to the structure of BinningOption for X array
pOptionY
[input]pointer to the structure of BinningOption for Y array
typedef struct
{
   double    dMin;    // the minimum of the range
   double    dMax;    // the maximum of the range
   double    dInc;    // the bin increment of the range
   int	     wIncludeOutliers;    // flag indicating whether or not to include outliers in first and last bins, values are defined in enum FrequncyAccounOutBin, default value is FAB_NOT_INCLUDE_OUTLIERS
   double    dPeriod;  //period for the data		
   int       wIncludeMinMax; // reuse flag in wIncludeOutliers, left for Min, right for Max
   int	     nMode;    // BIN_MODE_INC, BIN_MODE_VALS
   double*   pdVals;   // Double Array for BIN_MODE_VALS, for example, fill with 3 7 12 20, min=0, max=30, then the bins should be 0-3, 3-7, 7-12, 12-20, 20-30, >=30
   int	     nValsSize;// The size of pdVals
}BinningOption;

Return

Returns 0 on success. Otherwise returns error code:

-1: Empty pointer or invalid value for nStats.

BINNING_ERR_SIZE: nSize less than 1

BINNING_ERR_RANGE: range is invalid(dMin > dMax)

BINNING_ERR_INC: dInc <= 0 or dInc > dMax - dMin

BINNING_ERR_FLAG: wIncludeOutliers is not defined in the enum

BINNING_ERR_PERIOD: error period.

BINNING_ERR_BUFFER_TOO_SMALL: size of pResult->pMatrix is less than needed

Examples

EX1

//This function will output the 2D Binning result into a new Matrix.
void ocmath_2d_binning_ex_ex1()
{
    vector vX,vY,vZ;
    vX.Data(1,30,1);
    vY.Normal(30);
    vZ.Normal(30);
    int     nSize = vY.GetSize();

    MatrixLayer    mResultLayer;
    mResultLayer.Create();
    mResultLayer.SetInternalData(FSI_DOUBLE);
    Matrix    matResult(mResultLayer);

    BinningOption    OptionX, OptionY;
    vX.GetMinMax(OptionX.dMin, OptionX.dMax);
    RoundLimits(&OptionX.dMin, &OptionX.dMax, &OptionX.dInc);
    OptionX.wIncludeOutliers = FAB_NOT_INCLUDE_OUTLIERS;
    int iSizeX = ceil( (OptionX.dMax - OptionX.dMin) / OptionX.dInc ) ;

    vY.GetMinMax(OptionY.dMin, OptionY.dMax);
    RoundLimits(&OptionY.dMin, &OptionY.dMax, &OptionY.dInc);
    OptionY.wIncludeOutliers = FAB_NOT_INCLUDE_OUTLIERS;
    int iSizeY = ceil( (OptionY.dMax - OptionY.dMin) / OptionY.dInc ) ;

    BinningStatsResult    Result;
    matrix    mResult(iSizeX, iSizeY);
    Result.iMatSize = iSizeX * iSizeY;
    Result.pMatrix = mResult;
    int iRet = ocmath_2d_binning_ex(nSize, vX, vY, vZ, &Result, OCMATH_2D_BINNING_MEAN, &OptionX, &OptionY);

    if(iRet)
    {
        printf("Error code is %d", iRet);
        return;
    }
    matResult = mResult;
}

Remark

See Also

Header to Included

origin.h

Reference