Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Iohmm`2"/> class with a given list of initial hidden state probabilities and
        /// a generator function for transition distributions.
        /// </summary>
        /// <param name="pi">The given list of initial hidden state probabilities.</param>
        /// <param name="transitionDistributionGenerator">A generator function, that generates the transition functions, it has one parameter: the original state.</param>
        /// <exception cref="ArgumentException">If the length of <paramref name="pi"/> is smaller than or equal to zero.</exception>
        /// <exception cref="ArgumentException">If one of the given initial probabilities is less than zero.</exception>
        /// <exception cref="ArgumentException">If the list of initial probabilities do not sum up to one.</exception>
        protected Iohmm(IEnumerable <double> pi, Func <int, ITransitionDistribution <TInput, int> > transitionDistributionGenerator)
        {
            double[] pia = pi.ToArray();
            int      numberOfHiddenStates = pia.Length;

            if (numberOfHiddenStates <= 0x00)
            {
                throw new ArgumentException("The number of hidden states must be greater than zero.");
            }
            double sum = 0.0d, p;

            for (int i = 0x00; i < numberOfHiddenStates; i++)
            {
                p = pia [i];
                if (p < 0.0d)
                {
                    throw new ArgumentException("All initial state probabilities must be larger or equal to zero.");
                }
                sum += pia [i];
            }
            if (Math.Abs(1.0d - sum) > ProgramConstants.Epsilon)
            {
                throw new ArgumentException("The given intial state probabilities must sum up to one.");
            }
            this.Pi = pia;
            ITransitionDistribution <TInput, int>[] tr = new ITransitionDistribution <TInput, int> [numberOfHiddenStates];
            for (int i = 0x00; i < numberOfHiddenStates; i++)
            {
                tr [i] = transitionDistributionGenerator(i);
            }
            this.Transitions = tr;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:iohmma.MealyIohmm`2"/> class, an Input-output Hidden Markov model with Mealy flavor.
 /// </summary>
 /// <param name="numberOfHiddenStates">Number of hidden states.</param>
 /// <param name="transitionDistributionGenerator">A generator that constructs input-dependent transition probabilities. The generator has no parameters.</param>
 /// <param name="emissionDistributionGenerator">A generator that constructs emmission probabilities. The generator takes one parameter: the state that will emit.</param>
 /// <exception cref="ArgumentException">If the number of hidden states is smaller than or equal to zero.</exception>
 public MealyIohmm(int numberOfHiddenStates, Func <ITransitionDistribution <TInput, int> > transitionDistributionGenerator, Func <int, ITransitionDistribution <TInput, TOutput> > emissionDistributionGenerator) : base(numberOfHiddenStates, transitionDistributionGenerator)
 {
     ITransitionDistribution <TInput, TOutput>[] em = new ITransitionDistribution <TInput, TOutput> [numberOfHiddenStates];
     for (int i = 0x00; i < numberOfHiddenStates; i++)
     {
         em [i] = emissionDistributionGenerator(i);
     }
     this.emissions = em;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:iohmma.MealyIohmm`2"/> class, an Input-output Hidden Markov model with Mealy flavor.
        /// </summary>
        /// <param name="pi">The given list of initial hidden state probabilities.</param>
        /// <param name="transitionDistributions">A list of initial distributions for the hidden states transitions.</param>
        /// <param name="emissionDistributionGenerator">A generator that constructs emmission probabilities. The generator takes one parameter: the state that will emit.</param>
        /// <exception cref="ArgumentException">If the length of <paramref name="pi"/> is smaller than or equal to zero.</exception>
        /// <exception cref="ArgumentException">If one of the given initial probabilities is less than zero.</exception>
        /// <exception cref="ArgumentException">If the list of initial probabilities do not sum up to one.</exception>
        /// <exception cref="ArgumentException">The number of elements in the <paramref name="transitionDistributions"/> is less than the number of hidden states.</exception>
        /// <remarks>
        /// <para>Additional items in the <paramref name="transitionDistributions"/> are simply ignored.</para>
        /// </remarks>
        public MealyIohmm(IEnumerable <double> pi, IEnumerable <ITransitionDistribution <TInput, int> > transitionDistributions, Func <int, ITransitionDistribution <TInput, TOutput> > emissionDistributionGenerator) : base(pi, transitionDistributions)
        {
            int numberOfHiddenStates = this.NumberOfHiddenStates;

            ITransitionDistribution <TInput, TOutput>[] em = new ITransitionDistribution <TInput, TOutput> [numberOfHiddenStates];
            for (int i = 0x00; i < numberOfHiddenStates; i++)
            {
                em [i] = emissionDistributionGenerator(i);
            }
            this.emissions = em;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Iohmm`2"/> class.
 /// </summary>
 /// <param name="numberOfHiddenStates">Number of hidden states.</param>
 /// <param name="transitionDistributionGenerator">A generator function, that generates the transition functions, it has one parameter: the original state.</param>
 /// <exception cref="ArgumentException">If the number of hidden states is smaller than or equal to zero.</exception>
 protected Iohmm(int numberOfHiddenStates, Func <int, ITransitionDistribution <TInput, int> > transitionDistributionGenerator)
 {
     if (numberOfHiddenStates <= 0x00)
     {
         throw new ArgumentException("The number of hidden states must be greater than zero.");
     }
     this.Pi = new double[numberOfHiddenStates];
     this.ResetPi();
     ITransitionDistribution <TInput, int>[] tr = new ITransitionDistribution <TInput, int> [numberOfHiddenStates];
     for (int i = 0x00; i < numberOfHiddenStates; i++)
     {
         tr [i] = transitionDistributionGenerator(i);
     }
     this.Transitions = tr;
 }