Haplo Prediction
predict haplogroups
|
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. | |
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. | |
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. | |
Error * | read_svm_model (SVM_model **model_out, const char *fname) |
Reads a SVM model. | |
Error * | write_svm_model (SVM_model *model, const char *fname) |
Writes a SVM model. | |
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. | |
void | free_svm_model (SVM_model *model) |
Frees a SVM model. | |
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 . | |
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. | |
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. | |
Error * | write_svm_model_tree (const SVM_model_tree *tree, const char *model_dirname) |
Writes a SVM model tree. | |
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. | |
void | free_svm_model_tree (SVM_model_tree *tree) |
Frees a SVM model tree. |
Support vector machine model classifier.
Definition in file svm_tree.h.
typedef struct SVM_model_node SVM_model_node |
SVM model tree node.
typedef SVM_model_node SVM_model_tree |
SVM model tree.
Definition at line 184 of file svm_tree.h.
void train_svm_model | ( | SVM_model ** | model_out, |
const Vector_u32 * | labels, | ||
const Matrix_i32 * | markers, | ||
double | cost, | ||
double | gamma | ||
) |
Trains a SVM model.
model_out | Result parameter. If *model_out is NULL, a model is allocated; otherwise its space is re-used. |
labels | Labels for training, with ith element as corresponding to the ith sample in markers. |
markers | Markers for training, with ith row as a sample corresponding to the ith label in labels. |
cost | Cost parameter for the SVM model. |
gamma | Gamma 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.
label_out | Result parameter. |
confidence_out | Result parameter. Must be an array of doubles of length svm_get_nr_class(model). |
markers | Marker data to predict. |
model | Trained model to use for predicting. |
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.
labels_out | Result parameter. If *labels_out is NULL, it is allocated; otherwise its space is re-used. |
confidence_out | Result parameter. If *confidence_out is NULL, it is allocated; otherwise its space is re-used. |
markers | Marker data to predict. Each row is a sample for prediction, corresponding to an element in the result parameters. |
model | Trained model to use for predicting. |
Definition at line 241 of file svm_tree.c.
Reads a SVM model.
model_out | Result parameter. If *model_out is NULL, a model is allocated; otherwise its space is re-used. |
fname | File to read the model from. |
Definition at line 299 of file svm_tree.c.
Writes a SVM model.
model | Model to write. |
fname | File to write to. |
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 ...
labels | Model training labels to write. |
markers | Model training markers to write. |
fname | File to write to. |
Definition at line 357 of file svm_tree.c.
void free_svm_model | ( | SVM_model * | model | ) |
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 .
tree_out | Result parameter. |
labels | Sample group labels. |
markers | Sample marker values. |
tree_xml_fname | XML file containing the model tree information. |
tree_dtd_fname | DTD 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.
labels_out | Result parameter. If *labels_out is NULL, it is allocated; otherwise its space is re-used. |
confidence_out | Result parameter. If *confidence_out is NULL, it is allocated; otherwise its space is re-used. |
markers | Marker data to predict. Each row is a sample for prediction, corresponding to an element in the result parameters. |
tree | Trained model tree to use for predicting. |
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.
tree_out | Result parameter. |
tree_xml_fname | XML file containing the model tree information. |
tree_dtd_fname | DTD file for validating the XML file, can be NULL. |
model_dirname | Directory 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.
tree | Model tree to write. |
model_dirname | Directory 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.
labels | Sample group labels. |
markers | Sample marker values. |
tree_xml_fname | XML file containing the model tree information. |
tree_dtd_fname | DTD file for validating the XML file, can be NULL. |
data_dirname | Directory 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.
tree | Model tree to free. |
Definition at line 1493 of file svm_tree.c.