From: Stefan Mandl
Subject: Library for Hidden Markov Models?
Date: 
Message-ID: <4chq91F168e5qU1@news.dfncis.de>
Hi c.l.l,

I'm looking for implementations of Hidden Markov Models in Common Lisp.
As a lot of Natural Language Processing has been done in CL, there 
should be such a thing out there.
I actually found this one:

http://www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp

but it does not seem to work in SBCL because of type issues.

Does anybody know other alternatives?

Thanks,

Stefan

From: Pascal Bourguignon
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <87y7x85dgp.fsf@thalassa.informatimago.com>
Stefan Mandl <············@informatik.uni-erlangen.de> writes:

> Hi c.l.l,
>
> I'm looking for implementations of Hidden Markov Models in Common Lisp.
> As a lot of Natural Language Processing has been done in CL, there
> should be such a thing out there.
> I actually found this one:
>
> http://www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp
>
> but it does not seem to work in SBCL because of type issues.
>
> Does anybody know other alternatives?

Yes, you can use it on clisp, where it works perfectly well:

[89]> (load"/local/users/pjb/src/lisp/nlp/www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp")
;; Loading file /local/users/pjb/src/lisp/nlp/www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp ...
;; Loaded file /local/users/pjb/src/lisp/nlp/www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp
T
[90]> (edit "/local/users/pjb/src/lisp/nlp/www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp")
Waiting for Emacs...
0
[91]> (viterbi test-hmm (vector 0 1 0 1 0 1))
(1 2 1 2 1 2) ;
2.4414063E-4
[92]> (viterbi-log test-hmm (vector 0 1 0 1 0 1))
(1 2 1 2 1 2) ;
-8.317767
[93]> (baum-welch test-hmm (vector 0 1 0 1 0 1))
#S(HMM :NO-OF-STATES 3 :NO-OF-OUTPUTS 2
   :TRANS
   #2A((0.0010008148 0.0010004593 0.9999988)
       (0.0010005977 0.0010003344 0.9999991)
       (0.021066384 0.9799336 0.0010000031))
   :PROB-INIT #(0.012722388 0.9882776 0.0010000011)
   :E
   #2A((0.99996537 0.0010346494) (0.9999997 0.0010003409) (0.0010000014 1.0)))
[94]> (viterbi-log test-hmm (vector 0 1 0 1 0 1))
(1 2 1 2 1 2) ;
-0.0523361
[95]> 

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
From: ··········@gmail.com
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <1147410629.242819.4380@j33g2000cwa.googlegroups.com>
Furthermore, it appears that the type errors on SBCL stem from the fact
that it assumes arrays created by (make-array (n m)) and (vector 1 2 3
4 5) are of type (simple-array fixnum (* *)) and (simple-array fixnum
(*)) respectively.  However, it appears that SBCL arrrays are
(simple-array t (* *)) which is the reasonable thing to expect when
:element-type is not provided to make-array.

Thus, you can make the code work by tracking down make-array and
setting :element-type fixnum on those that should have it.  That and
creating fixnum vectors.  Or, you can simply remove the fixnum type
declarations, presumably at the cost of efficiency.
From: Stefan Mandl
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <4cinakF15e2l9U1@news.dfncis.de>
 > Yes, you can use it on clisp, where it works perfectly well:

oh, I really like clisp but unfortunately can't use it in my project.

··········@gmail.com wrote:
> Furthermore, it appears that the type errors on SBCL stem from the fact
> that it assumes arrays created by (make-array (n m)) and (vector 1 2 3
> 4 5) are of type (simple-array fixnum (* *)) and (simple-array fixnum
> (*)) respectively.  However, it appears that SBCL arrrays are
> (simple-array t (* *)) which is the reasonable thing to expect when
> :element-type is not provided to make-array.
> 
> Thus, you can make the code work by tracking down make-array and
> setting :element-type fixnum on those that should have it.  That and
> creating fixnum vectors.  Or, you can simply remove the fixnum type
> declarations, presumably at the cost of efficiency.
> 

Hey Alex, that really did it, thanks a lot!

What's quite funny is that asking the question here was about the last 
thing I did before going to bed and finding the answer about the first 
thing I did when getting up.
Seems like my little problem has been worked on over night ;-)

Stefan
From: Christophe Rhodes
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <sqvesbg45x.fsf@cam.ac.uk>
Madhu <·······@meer.net> writes:

> Helu
>
> * Stefan Mandl in <···············@news.dfncis.de> :
> | http://www.cs.berkeley.edu/~wilensky/lispcraft/sources/hmm.lisp
> |
> | but it does not seem to work in SBCL because of type issues.
>
>
> If you are looking for something likely to work only on SBCL, I
> believe the following URL was posted to cll:
>
> 	http://www-jcsu.jesus.cam.ac.uk/~csr21/hmm.lisp 

That should work on any lisp which understands Unicode, but potential
users should be aware that I wrote that more as a test-case for using
Unicode in CL source rather than a production-quality HMM
implementation; that code does no rescaling, does not use logarithms
of probabilities, doesn't do any clever training (just Baum-Welch),
and has essentially no user interface.  So you might find fixing
Wilensky's HMM code more useful.

Christophe
From: Stefan Mandl
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <4ciogiF162t22U2@news.dfncis.de>
Christophe Rhodes wrote:

> That should work on any lisp which understands Unicode, but potential
> users should be aware that I wrote that more as a test-case for using
> Unicode in CL source rather than a production-quality HMM
> implementation; that code does no rescaling, does not use logarithms
> of probabilities, doesn't do any clever training (just Baum-Welch),
> and has essentially no user interface.  So you might find fixing
> Wilensky's HMM code more useful.
> 

Hi Christophe, still it's enlightening to look at and to find the 
corresponding
parts from the tutorial.

Thanks a lot.
From: Stefan Mandl
Subject: Re: Library for Hidden Markov Models?
Date: 
Message-ID: <4cioa5F162t22U1@news.dfncis.de>
> If you are looking for something likely to work only on SBCL, I
> believe the following URL was posted to cll:
> 
> 	http://www-jcsu.jesus.cam.ac.uk/~csr21/hmm.lisp 
> 

Thanks for the hint!

It actually uses some unicode characters to display greek letters, quite
nice once you have an editor that can actually display those.

I'm going to look at the two implementations closer this day.

Stefan