Haplo Prediction
predict haplogroups
Data Structures | Typedefs | Functions
nb_gauss.h File Reference

Naive Bayes Gaussian classifier. More...

#include <config.h>
#include <stdlib.h>
#include <inttypes.h>
#include <jwsc/base/error.h>
#include <jwsc/vector/vector.h>
#include <jwsc/matrix/matrix.h>

Go to the source code of this file.

Data Structures

struct  NB_gauss_model
 Naive Bayes Gaussian model. More...
struct  NB_gauss_model_node
 Naive Bayes Gaussian model tree node. More...

Typedefs

typedef struct NB_gauss_model_node NB_gauss_model_node
 Naive Bayes Gaussian model tree node.
typedef NB_gauss_model_node NB_gauss_model_tree
 Naive Bayes Gaussian model tree.

Functions

void train_nb_gauss_model (NB_gauss_model **model_out, const Vector_u32 *labels, const Matrix_i32 *markers, const Vector_d *priors)
 Trains a Naive Bayes Gaussian model.
Errorpredict_label_with_nb_gauss_model (uint32_t *label_out, double *confidence_out, const Vector_i32 *markers, const NB_gauss_model *model, uint32_t order)
 Predicts the label for a marker sample using a Naive Bayes Gaussian model.
Errorpredict_labels_with_nb_gauss_model (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const NB_gauss_model *model)
 Predicts the labels for a set of marker samples using a Naive Bayes Gaussian model.
Errorread_nb_gauss_model (NB_gauss_model **model_out, const char *fname)
 Reads a Naive Bayes Gaussian model.
Errorwrite_nb_gauss_model (NB_gauss_model *model, const char *fname)
 Writes a Naive Bayes Gaussian model.
void free_nb_gauss_model (NB_gauss_model *model)
 Frees a Naive Bayes Gaussian model.
Errortrain_nb_gauss_model_tree (NB_gauss_model_tree **tree_out, const Vector_u32 *labels, const Matrix_i32 *markers, const char *tree_xml_fname, const char *tree_dtd_fname)
 Trains a Naive Bayes Gaussian model tree .
Errorpredict_labels_with_nb_gauss_model_tree (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const NB_gauss_model_tree *tree, uint32_t order)
 Predicts the labels for a set of marker samples using a Naive Bayes Gaussian model tree.
Errorread_nb_gauss_model_tree (NB_gauss_model_tree **tree_out, const char *tree_xml_fname, const char *tree_dtd_fname, const char *model_dirname)
 Reads a Naive Bayes Gaussian model tree from.
Errorwrite_nb_gauss_model_tree (const NB_gauss_model_tree *tree, const char *model_dirname)
 Writes a Naive Bayes Gaussian model tree.
void free_nb_gauss_model_tree (NB_gauss_model_tree *tree)
 Frees a Naive Bayes Gaussian model tree.

Detailed Description

Naive Bayes Gaussian classifier.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

Definition in file nb_gauss.h.


Typedef Documentation

Naive Bayes Gaussian model tree node.

Naive Bayes Gaussian model tree.

Definition at line 182 of file nb_gauss.h.


Function Documentation

void train_nb_gauss_model ( NB_gauss_model **  model_out,
const Vector_u32 labels,
const Matrix_i32 markers,
const Vector_d label_priors 
)

Trains a Naive Bayes Gaussian model.

Parameters:
model_outResult parameter. If *model_out is NULL, a model is allocated; otherwise its space is re-used.
labelsLabels for training, with ith element as corresponding to the ith sample in markers.
markersMarkers for training, with ith row as a sample corresponding to the ith label in labels.
label_priorsPriors for each of the labels.

Definition at line 89 of file nb_gauss.c.

Error* predict_label_with_nb_gauss_model ( uint32_t *  label_out,
double *  confidence_out,
const Vector_i32 markers,
const NB_gauss_model model,
uint32_t  order 
)

Predicts the label for a marker sample using a Naive Bayes Gaussian model.

Parameters:
label_outResult parameter.
confidence_outResult parameter.
markersMarker data to predict.
modelTrained model to use for predicting.
orderIndicates which of the The kth best prediction values to return. Starts with 0 representing the overall best, 1 the next best and so on.
Returns:
On success, NULL is returned; otherwise an error is returned.

Definition at line 213 of file nb_gauss.c.

Error* predict_labels_with_nb_gauss_model ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const NB_gauss_model model 
)

Predicts the labels for a set of marker samples using a Naive Bayes Gaussian model.

Parameters:
labels_outResult parameter. If *labels_out is NULL, it is allocated; otherwise its space is re-used.
confidence_outResult parameter. If *confidence_out is NULL, it is allocated; otherwise its space is re-used.
markersMarker data to predict. Each row is a sample for prediction, corresponding to an element in the result parameters.
modelTrained model to use for predicting.
Returns:
On success, NULL is returned; otherwise an error is returned, but the result parameters are not freed.

Definition at line 326 of file nb_gauss.c.

Error* read_nb_gauss_model ( NB_gauss_model **  model_out,
const char *  fname 
)

Reads a Naive Bayes Gaussian model.

Parameters:
model_outResult parameter. If *model_out is NULL, a model is allocated; otherwise its space is re-used.
fnameFile to read the model from.
Returns:
On success, NULL is returned; otherwise an error is returned but does not free result parameter.

Definition at line 383 of file nb_gauss.c.

Error* write_nb_gauss_model ( NB_gauss_model model,
const char *  fname 
)

Writes a Naive Bayes Gaussian model.

Parameters:
modelModel to write.
fnameFile to write to.
Returns:
On success, NULL is returned; otherwise an error is returned.

Definition at line 446 of file nb_gauss.c.

void free_nb_gauss_model ( NB_gauss_model model)

Frees a Naive Bayes Gaussian model.

Parameters:
modelModel to free.

Definition at line 475 of file nb_gauss.c.

Error* train_nb_gauss_model_tree ( NB_gauss_model_tree **  tree_out,
const Vector_u32 labels,
const Matrix_i32 markers,
const char *  tree_xml_fname,
const char *  tree_dtd_fname 
)

Trains a Naive Bayes Gaussian model tree .

Parameters:
tree_outResult parameter.
labelsSample group labels.
markersSample marker values.
tree_xml_fnameXML file containing the model tree information.
tree_dtd_fnameDTD file for validating the XML file, can be NULL.

Definition at line 806 of file nb_gauss.c.

Error* predict_labels_with_nb_gauss_model_tree ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const NB_gauss_model_tree tree,
uint32_t  order 
)

Predicts the labels for a set of marker samples using a Naive Bayes Gaussian model tree.

Parameters:
labels_outResult parameter. If *labels_out is NULL, it is allocated; otherwise its space is re-used.
confidence_outResult parameter. If *confidence_out is NULL, it is allocated; otherwise its space is re-used.
markersMarker data to predict. Each row is a sample for prediction, corresponding to an element in the result parameters.
treeTrained model tree to use for predicting.
orderThe kth order prediction value. Zero being the best prediction.
Returns:
On success, NULL is returned; otherwise an error is returned, but the result parameters are not freed.

Definition at line 914 of file nb_gauss.c.

Error* read_nb_gauss_model_tree ( NB_gauss_model_tree **  tree_out,
const char *  tree_xml_fname,
const char *  tree_dtd_fname,
const char *  model_dirname 
)

Reads a Naive Bayes Gaussian model tree from.

Parameters:
tree_outResult parameter.
tree_xml_fnameXML file containing the model tree information.
tree_dtd_fnameDTD file for validating the XML file, can be NULL.
model_dirnameDirectory prefixing each model file in the tree.

Definition at line 1004 of file nb_gauss.c.

Error* write_nb_gauss_model_tree ( const NB_gauss_model_tree tree,
const char *  model_dirname 
)

Writes a Naive Bayes Gaussian model tree.

Parameters:
treeModel tree to write.
model_dirnameDirectory to prefix to each model file in the tree.

Definition at line 1056 of file nb_gauss.c.

void free_nb_gauss_model_tree ( NB_gauss_model_tree tree)

Frees a Naive Bayes Gaussian model tree.

Parameters:
treeModel tree to free.

Definition at line 1091 of file nb_gauss.c.