public void ComputeNormalizerWithManyNonTrivialLoops2()
        {
            StringAutomaton automaton = StringAutomaton.Zero();

            automaton.AddStates(6);

            automaton.States[0].AddEpsilonTransition(Weight.FromValue(0.2), automaton.States[1]);
            automaton.States[0].AddEpsilonTransition(Weight.FromValue(0.5), automaton.States[3]);
            automaton.States[0].EndWeight = Weight.FromValue(0.3);
            automaton.States[1].AddEpsilonTransition(Weight.FromValue(0.8), automaton.States[0]);
            automaton.States[1].AddEpsilonTransition(Weight.FromValue(0.1), automaton.States[2]);
            automaton.States[1].EndWeight = Weight.FromValue(0.1);
            automaton.States[2].EndWeight = Weight.FromValue(1.0);
            automaton.States[3].AddEpsilonTransition(Weight.FromValue(0.2), automaton.States[4]);
            automaton.States[3].AddEpsilonTransition(Weight.FromValue(0.1), automaton.States[5]);
            automaton.States[3].EndWeight = Weight.FromValue(0.7);
            automaton.States[4].AddEpsilonTransition(Weight.FromValue(0.5), automaton.States[2]);
            automaton.States[4].AddEpsilonTransition(Weight.FromValue(0.5), automaton.States[6]);
            automaton.States[4].EndWeight = Weight.FromValue(0.0);
            automaton.States[5].AddEpsilonTransition(Weight.FromValue(0.1), automaton.States[3]);
            automaton.States[5].AddEpsilonTransition(Weight.FromValue(0.9), automaton.States[6]);
            automaton.States[5].EndWeight = Weight.Zero;
            automaton.States[6].EndWeight = Weight.One;

            AssertStochastic(automaton);
            Assert.Equal(0.0, automaton.GetLogNormalizer(), 1e-6);
            Assert.Equal(0.0, GetLogNormalizerByGetValue(automaton), 1e-6);
            Assert.Equal(0.0, GetLogNormalizerByGetValueWithTransducers(automaton), 1e-6);
        }
示例#2
0
        public void LargeTransducer()
        {
            StringAutomaton.MaxStateCount = 1200000; // Something big
            StringAutomaton bigAutomaton = StringAutomaton.Zero();

            bigAutomaton.AddStates(StringAutomaton.MaxStateCount - bigAutomaton.States.Count);
            Func <DiscreteChar, Weight, Tuple <Option <PairDistribution <char, DiscreteChar> >, Weight> > transitionConverter =
                (dist, weight) => Tuple.Create(Option.Some(PairDistribution <char, DiscreteChar> .FromFirstSecond(dist, dist)), weight);

            Assert.Throws <AutomatonTooLargeException>(() => StringTransducer.FromAutomaton(bigAutomaton, transitionConverter));

            // Shouldn't throw if the maximum number of states is increased
            int prevMaxStateCount = StringTransducer.MaxStateCount;

            try
            {
                StringTransducer.MaxStateCount = StringAutomaton.MaxStateCount;
                StringTransducer.FromAutomaton(bigAutomaton, transitionConverter);
            }
            finally
            {
                StringTransducer.MaxStateCount = prevMaxStateCount;
            }
        }