2 // Copyright © 2009 The University of Chicago
8 #include "generaldefinitions.h"
11 class LinguisticaMainWindow
;
13 class hmmForSortingItem
;
14 class CPhoneCollection
;
15 class CWordCollection
;
18 template<class V
> class Q3SortedList
;
20 typedef Q3SortedList
<hmmForSortingItem
> hmmSortedList
;
21 typedef QMap
<int, hmmSortedList
*> IntTohmmSortedList
;
22 typedef QMap
<int, CParse
*> IntToParse
;
23 typedef QMap
<int, void*> IntToVoid
;
24 typedef QMap
<int, int*> IntToIntArray
;
25 typedef QMap
<int, int> IntToInt
;
26 typedef QMap
<QString
, int> QStringToInt
;
34 class LinguisticaMainWindow
* m_parent
;
35 class CLexicon
* m_Lexicon
;
37 // Construction Parameters
40 int m_lengthOfObservation
;
41 int m_maxLengthOfObservation
;
42 int m_NumberOfIterations
;
43 int m_countOfDataItems
;
45 QString m_HMMLogDirectory
;
46 eHmmDataType m_dataType
;
52 IntToString m_symbolList
;
53 StringToInt m_symbolIndex
;
57 IntToParse m_trainingData
;
58 IntToIntArray m_encodedTrainingData
;
59 IntToVoid m_trainingDataSource
;
60 QStringToInt m_trainingDataIndices
;
61 IntToInt m_trainingDataFrequency
;
62 IntToInt m_trainingDataSizes
;
64 void* m_trainingDatumSource
; // a pointer to the Object that provided the data
75 double* m_PI_SoftCounts
; // state i softcounts
76 double** m_A_SoftCounts
; // state i --> state j softcounts
77 double** m_B_SoftCounts
; // state i --> symbol j softcounts
78 double* m_Entropy
; // Entropy of each state's emissions
80 // probability of data
81 double* m_WordProbabilities
; // could be total Forward probl, or Viterbi; one for each data item
83 // For next use, output
84 IntTohmmSortedList m_symbolStateList
;
87 double m_LogProbabilityOfData
;
90 StateEmitHMM(LinguisticaMainWindow
*);
91 StateEmitHMM(CLexicon
*);
93 virtual ~StateEmitHMM();
96 bool preprocessData(eHmmDataType
, void*); // type =1 : take PhoneTier1; type =2 take PhoneTier2, type=3 take CParse
97 void init(int, int loops
= 1000 );
101 void forward(int, double&);
103 // backward procedure
104 void backward(int, double&);
106 // Expectation procedure
107 void Expectation(int);
109 // Total Maximization procedure
113 double trainParameters();
118 // compute a symbol's state list
119 void getStateListForASymbol();
122 void logInfo(double totalLogProbability
);
123 void OutputTransitions(int IterationNumber
, QString FileName
);
124 void OutputTransitionsToLogFile(int IterationNumber
, QString FileName
);
125 void OutputEmissions(int IterationNumber
, QString LogFileName
);
126 void OutputInitials(int IterationNumber
, QString LogFileName
);
129 double GetLogProbability() { return m_LogProbabilityOfData
; }
131 // Output to VideoFrame
132 void InsertValues ( VideoFrame
* );
137 class hmmForSortingItem
144 hmmForSortingItem(){};
145 ~hmmForSortingItem(){};
147 hmmForSortingItem(int stateNumber
, double probRatio
)
149 m_stateNumber
= stateNumber
;
150 m_probRatio
= probRatio
;
155 bool operator<(const hmmForSortingItem
& another
)
157 return (m_probRatio
> another
.m_probRatio
);
161 bool operator==(const hmmForSortingItem
& another
)
163 return (m_probRatio
== another
.m_probRatio
);
169 #endif // STATEEMITHMM_H