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

Support vector machine model 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  SVM_model
 Support vector machine model. More...
struct  SVM_model_node
 SVM model tree node. More...

Typedefs

typedef struct SVM_model_node SVM_model_node
 SVM model tree node.
typedef SVM_model_node SVM_model_tree
 SVM model tree.

Functions

void train_svm_model (SVM_model **model_out, const Vector_u32 *labels, const Matrix_i32 *markers, double cost, double gamma)
 Trains a SVM model.
Errorpredict_label_with_svm_model (uint32_t *label_out, double **confidence_out, const struct svm_node *markers, const SVM_model *model)
 Predicts the label for a marker sample using a SVM model.
Errorpredict_labels_with_svm_model (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const SVM_model *model)
 Predicts the labels for a set of marker samples using a SVM model.
Errorread_svm_model (SVM_model **model_out, const char *fname)
 Reads a SVM model.
Errorwrite_svm_model (SVM_model *model, const char *fname)
 Writes a SVM model.
Errorwrite_svm_model_training_data (const Vector_u32 *labels, const Matrix_i32 *markers, const char *fname)
 Writes the training data for an SVM model to a file.
void free_svm_model (SVM_model *model)
 Frees a SVM model.
Errortrain_svm_model_tree (SVM_model_tree **tree_out, const Vector_u32 *labels, const Matrix_i32 *markers, const char *tree_xml_fname, const char *tree_dtd_fname)
 Trains a SVM model tree .
Errorpredict_labels_with_svm_model_tree (Vector_u32 **labels_out, Vector_d **confidence_out, const Matrix_i32 *markers, const SVM_model_tree *tree)
 Predicts the labels for a set of marker samples using a SVM model tree.
Errorread_svm_model_tree (SVM_model_tree **tree_out, const char *tree_xml_fname, const char *tree_dtd_fname, const char *model_dirname)
 Reads a SVM model tree from.
Errorwrite_svm_model_tree (const SVM_model_tree *tree, const char *model_dirname)
 Writes a SVM model tree.
Errorwrite_svm_model_tree_training_data (const Vector_u32 *labels, const Matrix_i32 *markers, const char *tree_xml_fname, const char *tree_dtd_fname, const char *data_dirname)
 Writes the training data for an SVM model tree to a file.
void free_svm_model_tree (SVM_model_tree *tree)
 Frees a SVM model tree.

Detailed Description

Support vector machine model classifier.

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

Definition in file svm_tree.h.


Typedef Documentation

SVM model tree node.

SVM model tree.

Definition at line 184 of file svm_tree.h.


Function Documentation

void train_svm_model ( SVM_model **  model_out,
const Vector_u32 labels,
const Matrix_i32 markers,
double  cost,
double  gamma 
)

Trains a SVM 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.
costCost parameter for the SVM model.
gammaGamma parameter for the SVM model.

Definition at line 98 of file svm_tree.c.

Error* predict_label_with_svm_model ( uint32_t *  label_out,
double **  confidence_out,
const struct svm_node *  markers,
const SVM_model model 
)

Predicts the label for a marker sample using a SVM model.

Parameters:
label_outResult parameter.
confidence_outResult parameter. Must be an array of doubles of length svm_get_nr_class(model).
markersMarker data to predict.
modelTrained model to use for predicting.
Returns:
On success, NULL is returned; otherwise an error is returned.

Definition at line 172 of file svm_tree.c.

Error* predict_labels_with_svm_model ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const SVM_model model 
)

Predicts the labels for a set of marker samples using a SVM 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 241 of file svm_tree.c.

Error* read_svm_model ( SVM_model **  model_out,
const char *  fname 
)

Reads a SVM 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 299 of file svm_tree.c.

Error* write_svm_model ( SVM_model model,
const char *  fname 
)

Writes a SVM model.

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

Definition at line 328 of file svm_tree.c.

Error* write_svm_model_training_data ( const Vector_u32 labels,
const Matrix_i32 markers,
const char *  fname 
)

Writes the training data for an SVM model to a file.

The format is txt-based and consistent with input to libsvm.

  label-index  1:marker-val 2:marker-val 3:marker-val ...
Parameters:
labelsModel training labels to write.
markersModel training markers to write.
fnameFile to write to.
Returns:
On success, NULL is returned; otherwise an error is returned.

Definition at line 357 of file svm_tree.c.

void free_svm_model ( SVM_model model)

Frees a SVM model.

Parameters:
modelModel to free.

Definition at line 399 of file svm_tree.c.

Error* train_svm_model_tree ( SVM_model_tree **  tree_out,
const Vector_u32 labels,
const Matrix_i32 markers,
const char *  tree_xml_fname,
const char *  tree_dtd_fname 
)

Trains a SVM 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 829 of file svm_tree.c.

Error* predict_labels_with_svm_model_tree ( Vector_u32 **  labels_out,
Vector_d **  confidence_out,
const Matrix_i32 markers,
const SVM_model_tree tree 
)

Predicts the labels for a set of marker samples using a SVM 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.
Returns:
On success, NULL is returned; otherwise an error is returned, but the result parameters are not freed.

Definition at line 1170 of file svm_tree.c.

Error* read_svm_model_tree ( SVM_model_tree **  tree_out,
const char *  tree_xml_fname,
const char *  tree_dtd_fname,
const char *  model_dirname 
)

Reads a SVM 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 1264 of file svm_tree.c.

Error* write_svm_model_tree ( const SVM_model_tree tree,
const char *  model_dirname 
)

Writes a SVM model tree.

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

Definition at line 1321 of file svm_tree.c.

Error* write_svm_model_tree_training_data ( const Vector_u32 labels,
const Matrix_i32 markers,
const char *  tree_xml_fname,
const char *  tree_dtd_fname,
const char *  data_dirname 
)

Writes the training data for an SVM model tree to a file.

Writes the data files using the name of the model to the data_dir directory.

Parameters:
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.
data_dirnameDirectory to write the training data files.

Definition at line 1436 of file svm_tree.c.

void free_svm_model_tree ( SVM_model_tree tree)

Frees a SVM model tree.

Parameters:
treeModel tree to free.

Definition at line 1493 of file svm_tree.c.