Esempio n. 1
0
        /// \fn     public void UpdateHMMFromSerializedValues()
        ///
        /// \brief  Deserialize All gestures values into  their origin format
        ///
        /// \author Khoubaeib Klai | [email protected]
        /// \date   24/04/2014
        public void UpdateHMMFromSerializedValues()
        {
            List <AKN_HiddenMarkovModel <int> > l_hmms = new List <AKN_HiddenMarkovModel <int> >();

            for (int i = 0; i < nb_states.Count; i++)
            {
                if (nb_states[i] != 0 && nb_observations[i] != 0)
                {
                    AKN_HiddenMarkovModel <int> hmm = new AKN_HiddenMarkovModel <int>(nb_states[i], nb_observations[i], m_gesturesName[i]);

                    int indexPreviousStates = 0; for (int j = 0; j < i; j++)
                    {
                        indexPreviousStates += nb_states[j];
                    }
                    int indexPreviousObservations = 0; for (int j = 0; j < i; j++)
                    {
                        indexPreviousObservations += nb_states[j];
                    }

                    hmm.MSetStates(
                        statesProbabilities.GetRange(indexPreviousStates, nb_states[i]).ToArray(),
                        statesNames.GetRange(indexPreviousStates, nb_states[i]).ToArray());

                    int indexPreviousTransitions = 0; for (int j = 0; j < i; j++)
                    {
                        indexPreviousTransitions += (nb_states[j] * nb_states[j]);
                    }
                    float[] trs = transitions.GetRange(indexPreviousTransitions, (nb_states[i] * nb_states[i])).ToArray();
                    for (int j = 0; j < nb_states[i]; j++)
                    {
                        for (int k = 0; k < nb_states[i]; k++)
                        {
                            hmm.MSetTransition(j, k, trs[(j * nb_states[i]) + k]);
                        }
                    }

                    hmm.MSetObservations(observations.GetRange(indexPreviousObservations, nb_observations[i]).ToArray());

                    int indexPreviousEmissions = 0; for (int j = 0; j < i; j++)
                    {
                        indexPreviousEmissions += (nb_states[j] * nb_observations[j]);
                    }
                    float[] ems = emissions.GetRange(indexPreviousEmissions, (nb_states[i] * nb_observations[i])).ToArray();
                    for (int j = 0; j < nb_states[i] * nb_observations[i]; j++)
                    {
                        hmm.MSetEmissionByIndex(j, ems[j]);
                    }


                    l_hmms.Add(hmm);
                }
                else
                {
                    l_hmms.Add(null);
                }
            }

            m_HMMs = l_hmms;
        }