示例#1
0
文件: Main.cs 项目: ArxCaeli/hmm_lab1
        private static void ShowStatistics(ForwardBackward FB, string[] MaxProbPath, double Limit)
        {
            int TruePos = 0;
            int TrueNeg = 0;
            int FalsePos = 0;
            int FalseNeg = 0;
            string TrueRes = "St1";
            //string FalseRes = "St2";
            int Unresolved = 0;
            foreach (InputLine Seq in InputManager.Sequence)
            {
                double SeqPossibility =
                    FB.GetBackwardValue (Seq.SequenceNo + 1, Seq.StateName) *
                    FB.GetForwardValue (Seq.SequenceNo + 1, Seq.StateName) /
                    FB.GetForwardValue (InputManager.Sequence.Count + 1, 0);

                if (SeqPossibility > Limit)
                {
                    if (MaxProbPath[Seq.SequenceNo + 1] == TrueRes)
                    {
                        if (Seq.StateName == TrueRes)
                            TruePos++;
                        else
                            FalsePos++;
                    }
                    else
                    {
                        if (Seq.StateName == TrueRes)
                            FalseNeg++;
                        else
                            TrueNeg++;
                    }
                }
                else
                    Unresolved++;
            }

            Console.WriteLine("======================================");
            Console.WriteLine("Limit: " + Limit.ToString());
            Console.WriteLine("TP: " + TruePos.ToString());
            Console.WriteLine("TN: " + TrueNeg.ToString());
            Console.WriteLine("FP: " + FalsePos.ToString());
            Console.WriteLine("FN: " + FalseNeg.ToString());
            Console.WriteLine("Unresolved: " + Unresolved.ToString());
        }
        public static void Export(ForwardBackward FB, string FileName)
        {
            using(StreamWriter SW = new StreamWriter(FileName))
            {
                SW.WriteLine (FB.GetBackwardValue (0, 0) + "\t" + FB.GetBackwardValue (0, 1));
                SW.WriteLine (FB.GetForwardValue (InputManager.Sequence.Count + 1, 0) + "\t"
                    + FB.GetForwardValue (InputManager.Sequence.Count + 1, 1));

                double[] SeqPossibility = new double[InputManager.Sequence.Count];
                double[,] MaxMinPossibility = new double[InputManager.Sequence.Count,2];

                foreach (InputLine Seq in InputManager.Sequence)
                {
                    SeqPossibility[Seq.SequenceNo] =
                        FB.GetBackwardValue (Seq.SequenceNo + 1, Seq.StateName) *
                        FB.GetForwardValue (Seq.SequenceNo + 1, Seq.StateName) /
                        FB.GetForwardValue (InputManager.Sequence.Count + 1, 0);

                    MaxMinPossibility[Seq.SequenceNo,0] =
                        FB.GetBackwardValue (Seq.SequenceNo + 1, 0) *
                        FB.GetForwardValue (Seq.SequenceNo + 1, 0) /
                        FB.GetForwardValue (InputManager.Sequence.Count + 1, 0);

                    MaxMinPossibility[Seq.SequenceNo,1] =
                        FB.GetBackwardValue (Seq.SequenceNo + 1, 1) *
                        FB.GetForwardValue (Seq.SequenceNo + 1, 1) /
                        FB.GetForwardValue (InputManager.Sequence.Count + 1, 0);

                    if (MaxMinPossibility[Seq.SequenceNo,1] > MaxMinPossibility[Seq.SequenceNo,0])
                    {
                        double Tmp = MaxMinPossibility[Seq.SequenceNo,1];
                        MaxMinPossibility[Seq.SequenceNo,1] = MaxMinPossibility[Seq.SequenceNo,0];
                        MaxMinPossibility[Seq.SequenceNo,0] = Tmp;
                    }
                }

                for(int I = 0; I < InputManager.Sequence.Count; I++)
                    SW.WriteLine(MaxMinPossibility[I,1].ToString() + "\t" +
                                 SeqPossibility[I] + "\t" +
                                 MaxMinPossibility[I,0] + "\t" +
                                 InputManager.Sequence[I].Sequence + "\t" +
                                 InputManager.Sequence[I].StateName);

            }
        }