Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:41:14+00:00 2026-06-17T00:41:14+00:00

I want to use HMM with Viterbi Algorithm to correct typographical errors, I calculated

  • 0

I want to use HMM with Viterbi Algorithm to correct typographical errors, I calculated the required probability but when I apply Viterbi algorithm I got very bad results, I checked the code line by line and I couldn’t find the error

public ForwardViterbi(string[] states, string[] observations, double[] startProbability, double[,] transitionProbability, double[,] emissionProbability, double scaleFactor)
        {

            this.states = states;
            this.observations = observations;
            this.startProbability = startProbability;
            this.transitionProbability = transitionProbability;
            this.emissionProbability = emissionProbability;
            this.scaleFactor = scaleFactor;

        }

        //----------------------------------------------------------------------
        //The Methods

        public void Process(int[] problem)
        {

            double[,] T = new double[states.Length, 3];  //We will store the probability sequence for the Viterbi Path
            vPath = new int[problem.Length];
            vProbs = new double[problem.Length];

            //initialize T
            //------------------------------------------------------------------    
            for (int state = 0; state < states.Length; state++)
            {
                T[state, 0] = startProbability[state];
                T[state, 1] = state;
                T[state, 2] = startProbability[state];
            }

            for (int output = 0; output < problem.Length; output++)
            {

                double[,] U = new double[states.Length, 3];  //We will use this array to calculate the future probabilities

                Console.WriteLine("\nTesting hypothesis {0} ({1})", output, observations[problem[output]]);
                double highest = 0;

                for (int nextState = 0; nextState < states.Length; nextState++)
                {
                    double total = 0;
                    double argMax = 0;
                    double valMax = 0;

                    Console.WriteLine("  Estimating probability for future state {0} ({1})", nextState, states[nextState]);
                    for (int state = 0; state < states.Length; state++)
                    {
                        Console.WriteLine("    The testing state is {0} ({1})", states[state], state);
                        double prob = T[state, 0];
                        double v_path = T[state, 1];
                        double v_prob = T[state, 2];
                        double p = emissionProbability[state, problem[output]] * transitionProbability[state, nextState] * scaleFactor;
                        prob *= p;
                        v_prob *= p;
                        total += prob;

                        if (v_prob > valMax)
                        {
                            valMax = v_prob;
                            argMax = nextState;
                        }

                        Console.WriteLine("    VProbability of {0} is {1} with scale {2}^{3}", states[nextState], v_prob, scaleFactor, output + 1);

                        if (v_prob > highest)
                        {
                            highest = v_prob;
                            vPath[output] = nextState;
                            vProbs[output] = v_prob;
                        }
                    }

                    U[nextState, 0] = total;
                    U[nextState, 1] = argMax;
                    U[nextState, 2] = valMax;
                }
                T = U;
                Console.WriteLine("The highest probability was {0} in state {1} (scale factor of {2}^{3})", highest, states[vPath[output]], scaleFactor, output + 1);
            }


            //Apply SumMax
            double Total = 0;
            double ValMax = 0;

            for (int state = 0; state < states.Length; state++)
            {
                double prob = T[state, 0];
                double v_path = T[state, 1];
                double v_prob = T[state, 2];

                Total += prob;
                if (v_prob > ValMax)
                {
                    ValMax = v_prob;
                }
            }

            Console.WriteLine("\nAnalysis: Total probability (sum of all paths) for the given state is :: {0}\nThe Viterbi Path Probability is :: {1}", Total, ValMax);
            Console.WriteLine("The above results are presented with a scale factor of {0}^{1}", scaleFactor, problem.Length);

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:41:15+00:00Added an answer on June 17, 2026 at 12:41 am

    I’ve just checked this implementation and the one published on wikipedia.
    This one doesn’t seem to work. The one on wikipedia does work.
    If you want – you can compare them, but I’m lazy to do this.

    (I’ve implemented solution for exactly your problem as described here)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use JQuery mobile for the front-end of my mobile application, but I
Sorry I dont know the correct terminology to use but I have a 3x3
I want use Kendo ui window, but I can't see what the problem is.
I'm correctly use JQuery FullCalendar in a project but I want to translate some
I want use writeToFile to store a pic image to the documents, but find
I want use fiddler check the https request send by Azure Powershell, but when
I want use the VennDiagram package to correlate three different variables. But in R
I want use glassfish as the solr search server, but I don't know how
I want use Twisted in Python, but when I installing ,in comes this error,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.