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 NB_GAUSS_H 00047 #define NB_GAUSS_H 00048 00049 00050 #include <config.h> 00051 00052 #include <stdlib.h> 00053 #include <inttypes.h> 00054 00055 #include <jwsc/base/error.h> 00056 #include <jwsc/vector/vector.h> 00057 #include <jwsc/matrix/matrix.h> 00058 00059 00061 typedef struct 00062 { 00064 uint32_t num_markers; 00065 00067 Matrix_d* mu; 00068 00070 Matrix_d* sigma; 00071 00078 Vector_d* priors; 00079 } 00080 NB_gauss_model; 00081 00082 00084 void train_nb_gauss_model 00085 ( 00086 NB_gauss_model** model_out, 00087 const Vector_u32* labels, 00088 const Matrix_i32* markers, 00089 const Vector_d* priors 00090 ); 00091 00092 00097 Error* predict_label_with_nb_gauss_model 00098 ( 00099 uint32_t* label_out, 00100 double* confidence_out, 00101 const Vector_i32* markers, 00102 const NB_gauss_model* model, 00103 uint32_t order 00104 ); 00105 00106 00111 Error* predict_labels_with_nb_gauss_model 00112 ( 00113 Vector_u32** labels_out, 00114 Vector_d** confidence_out, 00115 const Matrix_i32* markers, 00116 const NB_gauss_model* model 00117 ); 00118 00119 00121 Error* read_nb_gauss_model(NB_gauss_model** model_out, const char* fname); 00122 00123 00125 Error* write_nb_gauss_model(NB_gauss_model* model, const char* fname); 00126 00127 00129 void free_nb_gauss_model(NB_gauss_model* model); 00130 00131 00133 typedef struct NB_gauss_model_node 00134 { 00140 const struct NB_gauss_model_node* parent; 00141 00147 uint32_t parent_label; 00148 00150 uint32_t num_groups; 00151 00157 struct NB_gauss_model_node** subtrees; 00158 00160 Vector_u32* labels; 00161 00163 Vector_u32** altlabels; 00164 00170 Vector_d* priors; 00171 00173 NB_gauss_model* model; 00174 00176 char* model_fname; 00177 } 00178 NB_gauss_model_node; 00179 00180 00182 typedef NB_gauss_model_node NB_gauss_model_tree; 00183 00184 00186 Error* train_nb_gauss_model_tree 00187 ( 00188 NB_gauss_model_tree** tree_out, 00189 const Vector_u32* labels, 00190 const Matrix_i32* markers, 00191 const char* tree_xml_fname, 00192 const char* tree_dtd_fname 00193 ); 00194 00195 00200 Error* predict_labels_with_nb_gauss_model_tree 00201 ( 00202 Vector_u32** labels_out, 00203 Vector_d** confidence_out, 00204 const Matrix_i32* markers, 00205 const NB_gauss_model_tree* tree, 00206 uint32_t order 00207 ); 00208 00209 00211 Error* read_nb_gauss_model_tree 00212 ( 00213 NB_gauss_model_tree** tree_out, 00214 const char* tree_xml_fname, 00215 const char* tree_dtd_fname, 00216 const char* model_dirname 00217 ); 00218 00219 00221 Error* write_nb_gauss_model_tree 00222 ( 00223 const NB_gauss_model_tree* tree, 00224 const char* model_dirname 00225 ); 00226 00227 00229 void free_nb_gauss_model_tree(NB_gauss_model_tree* tree); 00230 00231 00232 #endif