INGOR
|
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_range (BNRC_Data *D, const ytDoubleArray *xlar, const ytDoubleArray *xrar, const char *type, double outer) |
Sets the value range xl and xr. | |
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.
Calculates B-spline design matrices for all the variables.
This does not perform the calculation for type[j] == 1.
This is thread-enabled.
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.
ofs | Offset position for D->X, D->Xm, D->B, and D->Bindex. |
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.
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.
LambdaInv | This can be NULL. This is to store ΛT for level = 2 calculation. |
void BNRC_Data_finalize | ( | BNRC_Data * | D, |
int | allocXY | ||
) |
Releases memory allocated by BNRC_Data_alloc().
allocXY | Set the same value used when calling BNDC_Data_alloc(). |
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 10
hb and then decreases the value such as β = 10
hb − (i × hi ), where i = 1, 2, ...., hn. (default: x = 2.0) hyper_inc=
x hi=
x hyper_bg
. (default: x = 0.4) hyper_n=
n hn=
n hyper_bg
. (default: n = 21) linear
hb=2.0,hi=1.0,hn=2
". max_loops=
n stop
verbose=
n v=
n The following keys are used internally.
xl
xr
data | |
args |
void BNRC_prepare_beta | ( | double | hyper_bg, |
double | hyper_inc, | ||
int | hyper_num, | ||
double * | beta, | ||
double * | log_beta, | ||
int | verbose | ||
) |
Prepares the hyperparamters.
beta | hyper_num length array. |
log_beta | hyper_num length array. |
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.
ofs | offset. This is ignored for level ≤ 2 calculation. |
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.
xlar | |
xrar |
void BNRC_reinit | ( | void * | buff, |
ytData * | data | ||
) |
Re-initializes the score function.
This is only applicable if only the values in data are changed.
buff | pointer to the buffere returned by BNRC_init(). |
data | Only ytData::X and ytData::Y are used. |
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.
buff | score buffer returned by BNRC_init(). |
j | target node. |
parents | parent indices. |
q | length of parents. |
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.
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.
work | whether this allocates BNRC_Work::logDetLambdaWork and BNRC_Work::LambdaInvBtWork. |