StochHMM  v0.34
Flexible Hidden Markov Model C++ Library and Application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
userFunctions.h
Go to the documentation of this file.
1 //
2 // UserFunctions.h
3 //Copyright (c) 2007-2012 Paul C Lott
4 //University of California, Davis
5 //Genome and Biomedical Sciences Facility
6 //UC Davis Genome Center
7 //Ian Korf Lab
8 //Website: www.korflab.ucdavis.edu
9 //Email: lottpaul@gmail.com
10 //
11 //Permission is hereby granted, free of charge, to any person obtaining a copy of
12 //this software and associated documentation files (the "Software"), to deal in
13 //the Software without restriction, including without limitation the rights to
14 //use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15 //the Software, and to permit persons to whom the Software is furnished to do so,
16 //subject to the following conditions:
17 //
18 //The above copyright notice and this permission notice shall be included in all
19 //copies or substantial portions of the Software.
20 //
21 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
23 //FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
24 //COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25 //IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 //CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 
28 #ifndef StochHMM_userFunctions_cpp
29 #define StochHMM_userFunctions_cpp
30 
31 #include <iostream>
32 #include <map>
33 #include <string>
34 #include <vector>
35 #include "PDF.h"
36 namespace StochHMM{
37 
38 
39  //! \typedef Pointer to function that takes int, string ptr, string ptr
40  //typedef double (*pt2StateFunc) (const std::string*, const std::string*, size_t);
41  typedef double (*transitionFunc) (const std::string*, const size_t, const std::string*, const size_t);
42 
43  //! \typdef emissionFunc
44  //! \brief Pointer to emmission function
45  //! Passed a string and position as size_t
46  typedef double (*emissionFunc) (const std::string*, const size_t);
47 
48  //! \typedef pdfFunc
49  //! \brief Pointer to Univariate Continuous Probability Density Function
50  //! \param[in] double Given value
51  //! \param[in] std::vector<double>* Paramenters for PDF
52  typedef double (*pdfFunc)(const double, const std::vector<double>*);
53 
54  //! \typedef multiPdfFunc
55  //! Pointer to function that takes reference to array (variables) and pointer to vector
56  //! that contains multivariate function paramenters.
57  typedef double (*multiPdfFunc)(const std::vector<double>*, const std::vector<double>*);
58 
59 
60  //!\typedef Pointer to Function that takes a string and returns a vector<float>
61  typedef std::vector<double>* (*pt2TrackFunc) (const std::string*);
62 
63  //!\typedef Pointer to function that takes a string and returns a double
64  typedef double (*pt2Attrib) (const std::string*);
65 
66  //! The map stores the pointers to the different functions by const char* word.
67  //! Allows the user to create and integrate their own functions into the model
68  //! By specifying the name in the model, and assigning the ptr in the externalFuncs class.
69  //! At any State or transition their function will be called and return float
70  //! The float will then be applied in the trellis added to transition or emission.
71  //! (**Adding in log space)
72 
73  //! \class StateFuncs
74  //! Stores pointers to user functions used by the State's Emissions and Transitions
75  class StateFuncs{
76  public:
77  StateFuncs();
78 
79  void assignTransitionFunction(std::string&, transitionFunc);
80  void assignTransitionFunction(const char*, transitionFunc);
81 
82  void assignEmissionFunction(std::string&, emissionFunc);
83  void assignEmissionFunction(const char*, emissionFunc);
84 
85  void assignPDFFunction(std::string&, pdfFunc);
86  void assignPDFFunction(const char*, pdfFunc);
87 
88  void assignMultivariatePdfFunction(std::string&, multiPdfFunc);
90 
91 
93  emissionFunc* getEmissionFunction(std::string&);
94  pdfFunc* getPDFFunction(std::string&);
96 
97 
98  private:
99  std::map<std::string, transitionFunc> transitionFunctions;
100  std::map<std::string, emissionFunc> emissionFunctions;
101  std::map<std::string, pdfFunc> pdfFunctions; //For continuous emissions
102  std::map<std::string, multiPdfFunc> multiPdfFunctions;
103  void _loadUnivariatePdf();
104  void _loadMultivariatePdf();
105  };
106 
107 
108  //!Stores pointer to user functions used to create Real Number Tracks
109  class TrackFuncs{
110  public:
111  void assignFunction(std::string&, pt2TrackFunc);
112  pt2TrackFunc* getFunction(std::string&);
113  private:
114  std::map<std::string, pt2TrackFunc> functions;
115  };
116 
117 }
118 
119 #endif