Haplo Prediction
predict haplogroups
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #ifndef HAPLO_SVM_H 00047 #define HAPLO_SVM_H 00048 00049 00050 #include <config.h> 00051 00052 00053 #include <stdlib.h> 00054 #include <inttypes.h> 00055 00056 #if defined HAPLO_HAVE_LIBSVM_H 00057 #include <libsvm.h> 00058 #elif defined HAPLO_HAVE_SVM_H 00059 #include <svm.h> 00060 #endif 00061 00062 #include <jwsc/base/error.h> 00063 #include <jwsc/vector/vector.h> 00064 #include <jwsc/matrix/matrix.h> 00065 00066 00068 typedef struct 00069 { 00071 struct svm_model* svm; 00072 00078 struct svm_problem* prob; 00079 } 00080 SVM_model; 00081 00082 00084 void train_svm_model 00085 ( 00086 SVM_model** model_out, 00087 const Vector_u32* labels, 00088 const Matrix_i32* markers, 00089 double cost, 00090 double gamma 00091 ); 00092 00093 00095 Error* predict_label_with_svm_model 00096 ( 00097 uint32_t* label_out, 00098 double** confidence_out, 00099 const struct svm_node* markers, 00100 const SVM_model* model 00101 ); 00102 00103 00105 Error* predict_labels_with_svm_model 00106 ( 00107 Vector_u32** labels_out, 00108 Vector_d** confidence_out, 00109 const Matrix_i32* markers, 00110 const SVM_model* model 00111 ); 00112 00113 00115 Error* read_svm_model(SVM_model** model_out, const char* fname); 00116 00117 00119 Error* write_svm_model(SVM_model* model, const char* fname); 00120 00121 00123 Error* write_svm_model_training_data 00124 ( 00125 const Vector_u32* labels, 00126 const Matrix_i32* markers, 00127 const char* fname 00128 ); 00129 00130 00132 void free_svm_model(SVM_model* model); 00133 00134 00136 typedef struct SVM_model_node 00137 { 00143 const struct SVM_model_node* parent; 00144 00150 uint32_t parent_label; 00151 00157 struct SVM_model_node** subtrees[2]; 00158 00160 Vector_u32* labels[2]; 00161 00163 Vector_u32** altlabels[2]; 00164 00166 Vector_d* cost; 00167 00169 Vector_d* gamma; 00170 00172 uint32_t num_models; 00173 00175 SVM_model** models; 00176 00178 char** model_fnames; 00179 } 00180 SVM_model_node; 00181 00182 00184 typedef SVM_model_node SVM_model_tree; 00185 00186 00188 Error* train_svm_model_tree 00189 ( 00190 SVM_model_tree** tree_out, 00191 const Vector_u32* labels, 00192 const Matrix_i32* markers, 00193 const char* tree_xml_fname, 00194 const char* tree_dtd_fname 00195 ); 00196 00197 00202 Error* predict_labels_with_svm_model_tree 00203 ( 00204 Vector_u32** labels_out, 00205 Vector_d** confidence_out, 00206 const Matrix_i32* markers, 00207 const SVM_model_tree* tree 00208 ); 00209 00210 00212 Error* read_svm_model_tree 00213 ( 00214 SVM_model_tree** tree_out, 00215 const char* tree_xml_fname, 00216 const char* tree_dtd_fname, 00217 const char* model_dirname 00218 ); 00219 00220 00222 Error* write_svm_model_tree 00223 ( 00224 const SVM_model_tree* tree, 00225 const char* model_dirname 00226 ); 00227 00228 00230 Error* write_svm_model_tree_training_data 00231 ( 00232 const Vector_u32* labels, 00233 const Matrix_i32* markers, 00234 const char* tree_xml_fname, 00235 const char* tree_dtd_fname, 00236 const char* data_dirname 00237 ); 00238 00239 00241 void free_svm_model_tree(SVM_model_tree* tree); 00242 00243 00244 #endif