Beispiel #1
0
 /// <summary>
 /// Learns the parameters for the given system.
 /// </summary>
 /// <param name="initial">The initial.</param>
 /// <param name="transition">The transition.</param>
 /// <param name="emission">The emission.</param>
 /// <param name="trainingSet">The training set.</param>
 public void Learn([NotNull] InitialStateMatrix initial, [NotNull] TransitionMatrix transition,
                   [NotNull] EmissionMatrix emission,
                   [NotNull] IList <IList <LabeledObservation> > trainingSet)
 {
     Learn(initial, trainingSet);
     Learn(transition, trainingSet);
     Learn(emission, trainingSet);
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HiddenMarkovModel" /> class.
 /// </summary>
 /// <param name="states">The states.</param>
 /// <param name="inital">The inital state matrix.</param>
 /// <param name="transition">The transmission matrix.</param>
 /// <param name="emission">The emission matrix.</param>
 public HiddenMarkovModel(
     [NotNull] ReadOnlyCollection <IState> states,
     [NotNull] InitialStateMatrix inital,
     [NotNull] TransitionMatrix transition,
     [NotNull] EmissionMatrix emission)
 {
     _states     = states;
     _inital     = inital;
     _transition = transition;
     _emission   = emission;
 }
Beispiel #3
0
        /// <summary>
        /// Learns the initial probabilities from the specified training set.
        /// </summary>
        /// <param name="initial">The initial state matrix.</param>
        /// <param name="trainingSet">The training set.</param>
        private void Learn([NotNull] InitialStateMatrix initial, [NotNull] IList <IList <LabeledObservation> > trainingSet)
        {
            // group all traning sentences beginning with the same state
            var groups     = trainingSet.GroupBy(set => set.First().State).ToList();
            var totalCount = trainingSet.Count;

            // get the probability by dividing the count of each state's occurrence
            // by the total number of training sets
            foreach (var group in groups)
            {
                var state       = group.Key;
                var occurrences = group.Count();
                var probability = (double)occurrences / totalCount;

                initial.SetProbability(state, probability);
            }
        }