Ticket #3726: sage-3726-part7.patch

File sage-3726-part7.patch, 1.8 KB (added by was, 11 years ago)
  • sage/stats/hmm/chmm.pyx

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1217813371 25200
    # Node ID d1058cb7f1393ba458f1eedc44d9833b1939afa4
    # Parent  80bce2448195e008b6510a04f879d54a06238f76
    trac #3726 -- finished first HMM code.
    
    diff -r 80bce2448195 -r d1058cb7f139 sage/stats/hmm/chmm.pyx
    a b cdef class GaussianHiddenMarkovModel(Con 
    596596            exception on error
    597597
    598598        EXAMPLES:
     599        We train a very simple model:
     600            sage: m = hmm.GaussianHiddenMarkovModel([[1]], [(0,1)], [1])
     601            sage: m.baum_welch([1,1,1,1])
    599602
    600         NOTE: Training for models including silent states is not yet supported.
    601 
    602         REFERENCES:
    603             Rabiner, L.R.: "`A Tutorial on Hidden Markov Models and Selected
    604             Applications in Speech Recognition"', Proceedings of the IEEE,
    605             77, no 2, 1989, pp 257--285.
     603        Notice that after training the mean in the emission parameters changes
     604        form 0 to 1.
     605            sage: m
     606            Gaussian Hidden Markov Model with 1 States
     607            Transition matrix:
     608            [1.0]
     609            Emission parameters:
     610            [(1.0, 0.0001)]
     611            Initial probabilities: [1.0]
    606612        """
    607613        cdef ghmm_cmodel_baum_welch_context cs
    608614
    609615        cs.smo      = self.m
    610616        cs.sqd      = to_cseq(training_seqs)
     617        cs.logp     = <double*> safe_malloc(sizeof(double))
    611618        cs.eps      = log_likelihood_cutoff
    612619        cs.max_iter = max_iter
    613620       
    614621        if ghmm_cmodel_baum_welch(&cs):
    615622            raise RuntimeError, "error running Baum-Welch algorithm"
    616         #ghmm_cseq_free(&cs.sqd)
     623        ghmm_cseq_free(&cs.sqd)
     624       
    617625       
    618626cdef ghmm_cseq* to_cseq(seq) except NULL:
    619627    """