INGOR
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BNRC Class Reference

The BNRC score function. More...

#include <BNRC.h>

Public Member Functions

void * BNRC_init (ytData *data, ytKeyValues *args)
 Initializes the BNRC score.
 
void BNRC_reinit (void *buff, ytData *data)
 Re-initializes the score function.
 
double BNRC_score (void *buff, const int j, const int *parents, const int q)
 BNRC score function.
 
void BNRC_Data_finalize (BNRC_Data *D, int allocXY)
 Releases memory allocated by BNRC_Data_alloc().
 
size_t BNRC_Work_alloc (BNRC_Work *W, int p, int n, int mp, int H, int M, int level, int T1_size, int dry)
 Allocates memory for BNRC_Work.
 
void BNRC_prepare_beta (double hyper_bg, double hyper_inc, int hyper_num, double *beta, double *log_beta, int verbose)
 Prepares the hyperparamters.
 
void BNRC_calc_Bj (BNRC_Data *D, int ofs, int j, int bj, int n, int M, double *T1)
 Calculates the design matrix of B-splines.
 
void BNRC_calc_B (BNRC_Data *D, int ofs, const char *type, int n, int M, BNRC_Work *W)
 Calculates B-spline design matrices for all the variables.
 
void BNRC_calc_Lambda_j (BNRC_Data *D, int ofs, int j, int n, int M, const double *beta, int H, double *K, BNRC_Work *W, double *logDetLambda, double *LambdaInv, double *LambdaInvBt)
 Calculates Λ related values for the j-th variable.
 
void BNRC_calc_Lambda (BNRC_Data *D, BNRC_Global *G, int p, int n, const char *type, BNRC_Work *W, int level)
 Calculates Λ related values for all the variables.
 
void BNRC_prepare_Lambda (BNRC_Data *D, int ofs, const int *parents, int q, int n, int level, BNRC_Work *W, BNRC_Global *G)
 Prepares Lambda.
 
double BNRC_calc (BNRC_Data *D, int ofs, int j, const int *parents, int q, int n, int nn, int level, BNRC_Work *W, BNRC_Model *P, BNRC_Global *G)
 Calculates BNRC score.
 
void BNRC_setEdgeProp (void *buff, const int j, const int *parents, const int q, const int k, const ytEdge *edge)
 Sets parameters from ytEdge.
 
void BNRC_calcRelContrib (void *buff, int j, const int *parents, int q, double *ar)
 Calculates relative contribution.
 
void BNRC_range (BNRC_Data *D, const ytDoubleArray *xlar, const ytDoubleArray *xrar, const char *type, double outer)
 Sets the value range xl and xr.
 

Detailed Description

The BNRC score function.

The BNRC score function accepts only the continuous variables. Missing values are acceptable. The BNRC score function supports changing the number of B-splines for non-parametric regression. Use "M" arguments when initializing the score function.

See also
BNDC

Member Function Documentation

◆ BNRC_calc_B()

void BNRC_calc_B ( BNRC_Data D,
int  ofs,
const char *  type,
int  n,
int  M,
BNRC_Work W 
)

Calculates B-spline design matrices for all the variables.

This does not perform the calculation for type[j] == 1.

This is thread-enabled.

◆ BNRC_calc_Bj()

void BNRC_calc_Bj ( BNRC_Data D,
int  ofs,
int  j,
int  bj,
int  n,
int  M,
double *  T1 
)

Calculates the design matrix of B-splines.

Calculates the design matrix for the j -th variable (column) of D->X of n samples. The starting position of the input matrix can be offset by specifying ofs.

The calculated design matrix has 4 × n non-zero values and is stored at bj -th position of D->B and D->Bindex both offset by ofs.

The missing values specified by D->Xm are converted to zero values so that these affect nothing in modeling. This also replaces missing values in D->X with zero values.

Parameters
ofsOffset position for D->X, D->Xm, D->B, and D->Bindex.

◆ BNRC_calc_Lambda()

void BNRC_calc_Lambda ( BNRC_Data D,
BNRC_Global G,
int  p,
int  n,
const char *  type,
BNRC_Work W,
int  level 
)

Calculates Λ related values for all the variables.

Λ = BT B + n β K

This is applicable to only the calculation in BNRC_init() and BNRC_reinit() for level >= 2.

◆ BNRC_calc_Lambda_j()

void BNRC_calc_Lambda_j ( BNRC_Data D,
int  ofs,
int  j,
int  n,
int  M,
const double *  beta,
int  H,
double *  K,
BNRC_Work W,
double *  logDetLambda,
double *  LambdaInv,
double *  LambdaInvBt 
)

Calculates Λ related values for the j-th variable.

This calculates Λ = BTB + n β K, |Λ-1| (determinant of Λ), Λ-1, and Λ-1 BT.

Parameters
LambdaInvThis can be NULL. This is to store ΛT for level = 2 calculation.

◆ BNRC_calcRelContrib()

void BNRC_calcRelContrib ( void *  buff,
int  j,
const int *  parents,
int  q,
double *  ar 
)

Calculates relative contribution.

gamma[0] needs to be set before calling this.

Parameters
ar(n x q) matrix where q is the number of parents of the j-th variable. ar[i + k * n] represents the value for the k-th parent of the j-th variable at the i-th sample.

◆ BNRC_Data_finalize()

void BNRC_Data_finalize ( BNRC_Data D,
int  allocXY 
)

Releases memory allocated by BNRC_Data_alloc().

Parameters
allocXYSet the same value used when calling BNDC_Data_alloc().

◆ BNRC_init()

void * BNRC_init ( ytData data,
ytKeyValues args 
)

Initializes the BNRC score.

M=n

The number of B-splines for nonparametric regression. By default, n=20.

max_parents=n
mp=n

Maximum parents

prop=n

Property output type. This changes properties to be stored in edges and nodes after the estimation.
0: standard.
1: less information (simple) for the contitous or discrete only variable data set.

hyper_bg=x
hb=x
hb value for the hyperparameter range. The hyperparameter β is determined by the grid search. The grid search starts from β = 10hb and then decreases the value such as β = 10hb − (i × hi ), where i = 1, 2, ...., hn. (default: x = 2.0)
hyper_inc=x
hi=x
hi value for hyperparameter range. See explanation of hyper_bg. (default: x = 0.4)
hyper_n=n
hn=n
hn value for hyperparameter range. See explanation of hyper_bg. (default: n = 21)
linear
Linear mode. This is short for "hb=2.0,hi=1.0,hn=2".
max_loops=n
The maximum number of loops for parameter estimation by the back fitting algorithm. (default: n = 100)
stop
If specified, the algorithm stops if the parameter estimation is not converged.
verbose=n
v=n
Verbose level. By defalt, n=0.

The following keys are used internally.

xl
DoubleArray instance that defines the minimum (left-most) values of the value ranges for modeling with B-splines.
xr
DoubleArray instance that defines the maximum (right-most) values of the value ranges for modeling with B-splines.
Parameters
data
args
Returns
Pointer to the score buffer.

◆ BNRC_prepare_beta()

void BNRC_prepare_beta ( double  hyper_bg,
double  hyper_inc,
int  hyper_num,
double *  beta,
double *  log_beta,
int  verbose 
)

Prepares the hyperparamters.

Parameters
betahyper_num length array.
log_betahyper_num length array.

◆ BNRC_prepare_Lambda()

void BNRC_prepare_Lambda ( BNRC_Data D,
int  ofs,
const int *  parents,
int  q,
int  n,
int  level,
BNRC_Work W,
BNRC_Global G 
)

Prepares Lambda.

Parameters
ofsoffset. This is ignored for level ≤ 2 calculation.

◆ BNRC_range()

void BNRC_range ( BNRC_Data D,
const ytDoubleArray xlar,
const ytDoubleArray xrar,
const char *  type,
double  outer 
)

Sets the value range xl and xr.

Finds the min and max values for every variable. Sets these values in D->xl[j] and D->xr[j] for the j-th variable. These are used in calculating the B-spline design matrix.

If xlar and xrar values are set, this uses them. Otherwise, this finds the min and max values from the data.

Parameters
xlar
xrar

◆ BNRC_reinit()

void BNRC_reinit ( void *  buff,
ytData data 
)

Re-initializes the score function.

This is only applicable if only the values in data are changed.

Parameters
buffpointer to the buffere returned by BNRC_init().
dataOnly ytData::X and ytData::Y are used.

◆ BNRC_score()

double BNRC_score ( void *  buff,
const int  j,
const int *  parents,
const int  q 
)

BNRC score function.

This is thread-safe with OpenMP multi-threading. Thread-dependent working memory is allocated in buff returned by BNRC_init(). Therefore, you do not need to initialize and obtain the score buffer for different threads.

Parameters
buffscore buffer returned by BNRC_init().
jtarget node.
parentsparent indices.
qlength of parents.
Returns
BNRC score

◆ BNRC_setEdgeProp()

void BNRC_setEdgeProp ( void *  buff,
const int  j,
const int *  parents,
const int  q,
const int  k,
const ytEdge edge 
)

Sets parameters from ytEdge.

Sets coefficients (gamma) from "bspline" properties, and calculates B gamma (B_gamma) where B represents the design matrix.

By calling this, BNRC_partialResidual() can calculates valid partial residuals without the score calculation.

◆ BNRC_Work_alloc()

size_t BNRC_Work_alloc ( BNRC_Work W,
int  p,
int  n,
int  mp,
int  H,
int  M,
int  level,
int  T1_size,
int  dry 
)

Allocates memory for BNRC_Work.

Parameters
workwhether this allocates BNRC_Work::logDetLambdaWork and BNRC_Work::LambdaInvBtWork.

The documentation for this class was generated from the following file: