Haplo Prediction
predict haplogroups
nb_freq.h
Go to the documentation of this file.
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_FREQ_H
00047 #define NB_FREQ_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     uint32_t  min_marker_val;
00068 
00070     uint32_t  num_marker_vals;
00071 
00073     Matrix_d* marker_given_label;
00074 
00081     Vector_d* priors;
00082 } 
00083 NB_freq_model;
00084 
00085 
00087 void train_nb_freq_model
00088 (
00089     NB_freq_model**   model_out,
00090     const Vector_u32* labels, 
00091     const Matrix_i32* markers,
00092     const Vector_d*   priors
00093 );
00094 
00095 
00100 Error* predict_label_with_nb_freq_model
00101 (
00102     uint32_t*            label_out,
00103     double*              confidence_out,
00104     const Vector_i32*    markers,
00105     const NB_freq_model* model,
00106     uint32_t             order
00107 );
00108 
00109 
00114 Error* predict_labels_with_nb_freq_model
00115 (
00116     Vector_u32**         labels_out,
00117     Vector_d**           confidence_out,
00118     const Matrix_i32*    markers,
00119     const NB_freq_model* model
00120 );
00121 
00122 
00124 Error* read_nb_freq_model(NB_freq_model** model_out, const char* fname);
00125 
00126 
00128 Error* write_nb_freq_model(NB_freq_model* model, const char* fname);
00129 
00130 
00132 void free_nb_freq_model(NB_freq_model* model);
00133 
00134 
00136 typedef struct NB_freq_model_node
00137 {
00143     const struct NB_freq_model_node* parent;
00144 
00150     uint32_t parent_label;
00151 
00153     uint32_t num_groups;
00154 
00160     struct NB_freq_model_node** subtrees;
00161 
00163     Vector_u32* labels;
00164 
00166     Vector_u32** altlabels;
00167 
00173     Vector_d* priors;
00174 
00176     NB_freq_model* model;
00177 
00179     char* model_fname;
00180 } 
00181 NB_freq_model_node;
00182 
00183 
00185 typedef  NB_freq_model_node  NB_freq_model_tree;
00186 
00187 
00189 Error* train_nb_freq_model_tree
00190 (
00191     NB_freq_model_tree** tree_out,
00192     const Vector_u32*    labels, 
00193     const Matrix_i32*    markers,
00194     const char*          tree_xml_fname,
00195     const char*          tree_dtd_fname
00196 );
00197 
00198 
00203 Error* predict_labels_with_nb_freq_model_tree
00204 (
00205     Vector_u32**              labels_out,
00206     Vector_d**                confidence_out,
00207     const Matrix_i32*         markers,
00208     const NB_freq_model_tree* tree,
00209     uint32_t                  order
00210 );
00211 
00212 
00217 Error* read_nb_freq_model_tree
00218 (
00219     NB_freq_model_tree** tree_out,
00220     const char*          tree_xml_fname,
00221     const char*          tree_dtd_fname,
00222     const char*          model_dirname
00223 );
00224 
00225 
00227 Error* write_nb_freq_model_tree
00228 (
00229     const NB_freq_model_tree* tree,
00230     const char*               model_dirname
00231 );
00232 
00233 
00235 void free_nb_freq_model_tree(NB_freq_model_tree* tree);
00236 
00237 
00238 #endif