Example #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;
        }
 /// \fn     public void _MShowEmissionsValuesAtState(int _index)
 ///
 /// \brief  Show observations probabilities within a specific state.
 ///
 /// \author Khoubaeib Klai | [email protected]
 /// \date   24/04/2014
 ///
 /// \param  _index index of the state
 public void _MShowEmissionsValuesAtState(int _index)
 {
     GUILayout.BeginHorizontal();
     EditorGUILayout.LabelField("Etat " + (_index + 1), new GUILayoutOption[] { GUILayout.MaxWidth(50) });
     for (int j = 0; j < m_HMM.m_ObservationsCount; j++) //m_HMM.m_Emissions[i, j + 1] = EditorGUILayout.FloatField(m_HMM.m_Emissions[i, j + 1]);
     //m_HMM.MSetEmissionByIndex((i * m_HMM.m_ObservationsCount) + j, EditorGUILayout.FloatField(m_HMM.MGetEmissionByIndex((i * m_HMM.m_ObservationsCount) + j)));
     {
         m_HMM.MSetEmissionByIndex(_index, j, EditorGUILayout.FloatField(m_HMM.MGetEmissionByIndex(_index, j)));
     }
     GUILayout.EndHorizontal();
 }
        /// \fn     private AKN_HiddenMarkovModel<int> _MSetStates(AKN_HiddenMarkovModel<int> _gestureHmm)
        ///
        /// \brief  Update constructed Hmm with new states values.
        ///
        /// \author Khoubaeib Klai | [email protected]
        /// \date   24/04/2014
        ///
        /// \param  _gestureHmm HMM to update.
        ///
        /// \return new HMM with updated values.
        private AKN_HiddenMarkovModel <int> _MSetStates(AKN_HiddenMarkovModel <int> _gestureHmm)
        {
            for (int j = 0; j < _gestureHmm.m_StatesCount; j++)
            {
                _gestureHmm[j].m_name             = ("Etat " + j);
                _gestureHmm[j].m_startProbability = 0F;
                for (int k = 0; k < _gestureHmm.m_ObservationsCount; k++)
                {
                    _gestureHmm.MSetEmissionByIndex(j, k, 0);
                }
            }

            _gestureHmm[0].m_startProbability = 0.5F;
            _gestureHmm[1].m_startProbability = 0.5F;

            return(_gestureHmm);
        }