Haplo Prediction
predict haplogroups
Functions
mv_gmm.c File Reference

Multivariate Gaussian mixture model classifier. More...

#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/valid.h>
#include <jwsc/base/error.h>
#include <jwsc/base/limits.h>
#include <jwsc/base/file_io.h>
#include <jwsc/vector/vector.h>
#include <jwsc/vector/vector_io.h>
#include <jwsc/vector/vector_math.h>
#include <jwsc/matrix/matrix.h>
#include <jwsc/matrix/matrix_io.h>
#include <jwsc/matblock/matblock.h>
#include <jwsc/matblock/matblock_io.h>
#include <jwsc/stat/gmm.h>
#include "xml.h"
#include "haplo_groups.h"
#include "input.h"
#include "mv_gmm.h"

Go to the source code of this file.

Functions

void train_mv_gmm_model (MV_gmm_model **model_out, const Vector_u32 *labels, const Matrix_i32 *markers, const Vector_d *label_priors, uint32_t num_components)
 Trains a multivariate Gaussian mixture model.
Errorpredict_label_with_mv_gmm_model (uint32_t *label_out, double *confidence_out, const Vector_i32 *markers, const MV_gmm_model *model, uint32_t order)
 Predicts the label for a marker sample using a multivariate Gaussian mixture model.
Errorpredict_labels_with_mv_gmm_model (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const MV_gmm_model *model)
 Predicts the labels for a set of marker samples using a multivariate Gaussian mixture model.
Errorread_mv_gmm_model (MV_gmm_model **model_out, const char *fname)
 Reads a multivariate Gaussian mixture model.
Errorwrite_mv_gmm_model (MV_gmm_model *model, const char *fname)
 Writes a multivariate Gaussian mixture model.
void free_mv_gmm_model (MV_gmm_model *model)
 Frees a multivariate Gaussian mixture model.
static Errorread_mv_gmm_xml_doc (xmlDoc **xml_doc_out, const char *xml_fname, const char *dtd_fname)
 Reads and and optionally validates an XML document.
static Errorcreate_mv_gmm_model_tree_from_xml_node (MV_gmm_model_tree **tree_out, const MV_gmm_model_tree *parent, uint32_t parent_label, xmlNode *xml_node)
 Allocates and initializes a model tree from an xml node.
static Errorcreate_model_training_data (Vector_u32 **train_labels_out, Matrix_i32 **train_markers_out, const Vector_u32 *data_labels, const Matrix_i32 *data_markers, const Vector_u32 *model_labels, Vector_u32 *const *model_altlabels)
 Creates a set of training data as a model-specific labeled subset of a larger data set.
static Errortrain_mv_gmm_model_node (MV_gmm_model_node *node, const Vector_u32 *labels, const Matrix_i32 *markers)
 Trains a model in the tree using node-specific data.
Errortrain_mv_gmm_model_tree (MV_gmm_model_tree **tree_out, const Vector_u32 *labels, const Matrix_i32 *markers, const char *tree_xml_fname, const char *tree_dtd_fname)
 Trains a multivariate Gaussian mixture model tree .
static Errorrecursively_predict_label_in_model_tree (uint32_t *label_out, double *confidence_out, const MV_gmm_model_tree *tree, const Vector_i32 *markers_v, uint32_t order)
 Recursively predicts a label from a model tree.
Errorpredict_labels_with_mv_gmm_model_tree (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const MV_gmm_model_tree *tree, uint32_t order)
 Predicts the labels for a set of marker samples using a multivariate Gaussian mixture model tree.
static Errorread_mv_gmm_model_node (MV_gmm_model_node *node, const char *model_dirname)
 Recursively reads the model in a node from its file name.
Errorread_mv_gmm_model_tree (MV_gmm_model_tree **tree_out, const char *tree_xml_fname, const char *tree_dtd_fname, const char *model_dirname)
 Reads a multivariate Gaussian mixture model tree from.
Errorwrite_mv_gmm_model_tree (const MV_gmm_model_tree *tree, const char *model_dirname)
 Writes a multivariate Gaussian mixture model tree.
void free_mv_gmm_model_tree (MV_gmm_model_tree *tree)
 Frees a multivariate Gaussian mixture model tree.

Detailed Description

Multivariate Gaussian mixture model classifier.

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

Definition in file mv_gmm.c.


Function Documentation

void train_mv_gmm_model ( MV_gmm_model **  model_out,
const Vector_u32 labels,
const Matrix_i32 markers,
const Vector_d label_priors,
uint32_t  num_components 
)

Trains a multivariate Gaussian mixture 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.
num_componentsNumber of mixture components.

Definition at line 93 of file mv_gmm.c.

Error* predict_label_with_mv_gmm_model ( uint32_t *  label_out,
double *  confidence_out,
const Vector_i32 markers,
const MV_gmm_model model,
uint32_t  order 
)

Predicts the label for a marker sample using a multivariate Gaussian mixture 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 208 of file mv_gmm.c.

Error* predict_labels_with_mv_gmm_model ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const MV_gmm_model model 
)

Predicts the labels for a set of marker samples using a multivariate Gaussian mixture 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 339 of file mv_gmm.c.

Error* read_mv_gmm_model ( MV_gmm_model **  model_out,
const char *  fname 
)

Reads a multivariate Gaussian mixture 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 396 of file mv_gmm.c.

Error* write_mv_gmm_model ( MV_gmm_model model,
const char *  fname 
)

Writes a multivariate Gaussian mixture model.

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

Definition at line 477 of file mv_gmm.c.

void free_mv_gmm_model ( MV_gmm_model model)

Frees a multivariate Gaussian mixture model.

Parameters:
modelModel to free.

Definition at line 525 of file mv_gmm.c.

static Error* read_mv_gmm_xml_doc ( xmlDoc **  xml_doc_out,
const char *  xml_fname,
const char *  dtd_fname 
) [static]

Reads and and optionally validates an XML document.

Definition at line 551 of file mv_gmm.c.

static Error* create_mv_gmm_model_tree_from_xml_node ( MV_gmm_model_tree **  tree_out,
const MV_gmm_model_tree parent,
uint32_t  parent_label,
xmlNode *  xml_node 
) [static]

Allocates and initializes a model tree from an xml node.

Does not train or read the model; leaves the model field as NULL in each tree node.

Definition at line 604 of file mv_gmm.c.

static Error* create_model_training_data ( Vector_u32 **  train_labels_out,
Matrix_i32 **  train_markers_out,
const Vector_u32 data_labels,
const Matrix_i32 data_markers,
const Vector_u32 model_labels,
Vector_u32 *const *  model_altlabels 
) [static]

Creates a set of training data as a model-specific labeled subset of a larger data set.

Definition at line 757 of file mv_gmm.c.

static Error* train_mv_gmm_model_node ( MV_gmm_model_node node,
const Vector_u32 labels,
const Matrix_i32 markers 
) [static]

Trains a model in the tree using node-specific data.

Definition at line 828 of file mv_gmm.c.

Error* train_mv_gmm_model_tree ( MV_gmm_model_tree **  tree_out,
const Vector_u32 labels,
const Matrix_i32 markers,
const char *  tree_xml_fname,
const char *  tree_dtd_fname 
)

Trains a multivariate Gaussian mixture 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 878 of file mv_gmm.c.

static Error* recursively_predict_label_in_model_tree ( uint32_t *  label_out,
double *  confidence_out,
const MV_gmm_model_tree tree,
const Vector_i32 markers_v,
uint32_t  order 
) [static]

Recursively predicts a label from a model tree.

Definition at line 928 of file mv_gmm.c.

Error* predict_labels_with_mv_gmm_model_tree ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const MV_gmm_model_tree tree,
uint32_t  order 
)

Predicts the labels for a set of marker samples using a multivariate Gaussian mixture 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 986 of file mv_gmm.c.

static Error* read_mv_gmm_model_node ( MV_gmm_model_node node,
const char *  model_dirname 
) [static]

Recursively reads the model in a node from its file name.

Definition at line 1038 of file mv_gmm.c.

Error* read_mv_gmm_model_tree ( MV_gmm_model_tree **  tree_out,
const char *  tree_xml_fname,
const char *  tree_dtd_fname,
const char *  model_dirname 
)

Reads a multivariate Gaussian mixture 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 1076 of file mv_gmm.c.

Error* write_mv_gmm_model_tree ( const MV_gmm_model_tree tree,
const char *  model_dirname 
)

Writes a multivariate Gaussian mixture model tree.

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

Definition at line 1128 of file mv_gmm.c.

void free_mv_gmm_model_tree ( MV_gmm_model_tree tree)

Frees a multivariate Gaussian mixture model tree.

Parameters:
treeModel tree to free.

Definition at line 1163 of file mv_gmm.c.