Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71296

Re: Question on Debugging a code line

Newsgroups comp.lang.python
Date 2014-05-10 23:20 -0700
References <283e285b-4ab3-4ec7-a8be-4f1e047d9645@googlegroups.com>
Message-ID <e50d8baa-5fd0-4ca7-af59-2f9f66568596@googlegroups.com> (permalink)
Subject Re: Question on Debugging a code line
From subhabangalore@gmail.com

Show all headers | View raw


On Sunday, May 11, 2014 12:57:34 AM UTC+5:30, subhaba...@gmail.com wrote:
> Dear Room,
> 
> 
> 
> I was trying to go through a code given in http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm[ Forward Backward is an algorithm of Machine Learning-I am not talking on that
> 
> I am just trying to figure out a query on its Python coding.]
> 
> 
> 
> I came across the following codes.
> 
> 
> 
> >>> states = ('Healthy', 'Fever')
> 
> >>> end_state = 'E'
> 
> >>> observations = ('normal', 'cold', 'dizzy')
> 
> >>> start_probability = {'Healthy': 0.6, 'Fever': 0.4}
> 
> >>> transition_probability = {
> 
>    'Healthy' : {'Healthy': 0.69, 'Fever': 0.3, 'E': 0.01},
> 
>    'Fever' : {'Healthy': 0.4, 'Fever': 0.59, 'E': 0.01},
> 
>    }
> 
> >>> emission_probability = {
> 
>    'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
> 
>    'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6},
> 
>    }
> 
> 
> 
> def fwd_bkw(x, states, a_0, a, e, end_st):
> 
>     L = len(x)
> 
>     fwd = []
> 
>     f_prev = {} #THE PROBLEM 
> 
>     # forward part of the algorithm
> 
>     for i, x_i in enumerate(x):
> 
>         f_curr = {}
> 
>         for st in states:
> 
>             if i == 0:
> 
>                 # base case for the forward part
> 
>                 prev_f_sum = a_0[st]
> 
>             else:
> 
>                 prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) ##
> 
>  
> 
>             f_curr[st] = e[st][x_i] * prev_f_sum
> 
>  
> 
>         fwd.append(f_curr)
> 
>         f_prev = f_curr
> 
>  
> 
>     p_fwd = sum(f_curr[k]*a[k][end_st] for k in states)
> 
> 
> 
> As this value was being called in prev_f_sum = sum(f_prev[k]*a[k][st] for k in states marked ## 
> 
> I wanted to know what values it is generating.
> 
> So, I had made the following experiment, after 
> 
> for i, x_i in enumerate(x): 
> 
> I had put print f_prev 
> 
> but I am not getting how f_prev is getting the values.
> 
> 
> 
> Here, 
> 
> x=observations,
> 
> states= states,
> 
> a_0=start_probability,
> 
> a= transition_probability,
> 
> e=emission_probability,
> 
> end_st= end_state
> 
> 
> 
> Am I missing any minor aspect?
> 
> Code is running fine. 
> 
> 
> 
> If any one of the esteemed members may kindly guide me.
> 
> 
> 
> Regards,
> 
> Subhabrata Banerjee.

Dear Sir,
Thank you for your kind reply. I will check. 
Regards,
Subhabrata Banerjee. 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question on Debugging a code line subhabangalore@gmail.com - 2014-05-10 12:27 -0700
  Re: Question on Debugging a code line MRAB <python@mrabarnett.plus.com> - 2014-05-10 21:44 +0100
  Re: Question on Debugging a code line subhabangalore@gmail.com - 2014-05-10 23:20 -0700
    Re: Question on Debugging a code line subhabangalore@gmail.com - 2014-05-11 00:45 -0700
      Re: Question on Debugging a code line Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-05-11 13:03 +0100

csiph-web