mominbuet / jahmm

Automatically exported from code.google.com/p/jahmm
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

HmmReader class cannot the exponential formed values. #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
HMMReader class cannot read the observation symbol probability formatted with 
exponential 
form from the HMM file. 

I show the HMM file.
--------------------------------------------
Hmm v1.0

NbStates 4

State
Pi 0.25
A 0.25 0.25 0.25 0.25 
IntegerOPDF [0.5775083500334324 0.42158984635940894 9.018036072144319E-4 0.0 ]

State
Pi 0.25
A 0.25 0.25 0.25 0.25 
IntegerOPDF [0.5775083500334324 0.42158984635940894 9.018036072144319E-4 0.0 ]

State
Pi 0.25
A 0.25 0.25 0.25 0.25 
IntegerOPDF [0.5775083500334324 0.42158984635940894 9.018036072144319E-4 0.0 ]

State
Pi 0.25
A 0.25 0.25 0.25 0.25 
IntegerOPDF [0.5775083500334324 0.42158984635940894 9.018036072144319E-4 0.0 ]
--------------------------------------------

What is the expected output? What do you see instead?
I would like you to support HMMReader can read the values formatted with 
exponetial form.

What version of the product are you using? On what operating system?
jahmm-0.6.2.jar MacOS X 10.5.8

Please provide any additional information below.
I implement the function of reading the values with formatted with exponential 
form. But, I think 
there are some bugs in my implementation. I fix read(StreamTokenizer st, int 
length) method in 
OpdfReader class. I'm looking forwad to supporting the exponential form in the 
official 
implementation.

    /**
     * Reads a sequence of numbers.  The sequence is between brackets
     * and numbers are separated by spaces.  Empty array are not allowed.
     * 
     * @param st The tokenizer to read the sequence from.
     * @param length The expected length of the sequence or a strictly negative
     *        number if it must not be checked.
     * @return The array read.
     */
    static protected double[] read(StreamTokenizer st, int length)
    throws IOException, FileFormatException
    {
        LinkedList<String> l = new LinkedList<String>();

        HmmReader.readWords(st, "[");

                while ((st.nextToken() == StreamTokenizer.TT_NUMBER)
                        || (st.ttype == StreamTokenizer.TT_WORD)) {
                    String token = null;

                    if(st.ttype == StreamTokenizer.TT_NUMBER) {
                        token = Double.toString(st.nval);
                    }

                    if(st.ttype == StreamTokenizer.TT_WORD) {
                        String word = st.sval;
                        String nval = l.removeLast();

                        token = nval + word;
                    }

                    l.addLast(token);
                }

        st.pushBack();
        HmmReader.readWords(st, "]");

        if (length >= 0 && l.size() != length)
            throw new FileFormatException(st.lineno(),
                    "Wrong length of number sequence");

        if (l.size() == 0)
            throw new FileFormatException(st.lineno(),
                    "Invalid empty sequence");

        double[] a = new double[l.size()];
        for (int i = 0; i < a.length; i++) {
                    try {
            a[i] = Double.parseDouble(l.get(i));
                    } catch(NumberFormatException e) {
                        e.printStackTrace();
                    }
                }

        return a;
    }

Original issue reported on code.google.com by crossan...@gmail.com on 17 Aug 2009 at 2:04

Attachments:

GoogleCodeExporter commented 9 years ago
see also file attached in Issue #9.

Original comment by jean.phi...@gmail.com on 12 Jul 2011 at 8:29