Opened 9 years ago
Closed 6 years ago
#15711 closed defect (fixed)
DiscreteHiddenMarkovModel instances do not unpickle correctly
Reported by:  ppurka  Owned by:  

Priority:  major  Milestone:  sage6.4 
Component:  statistics  Keywords:  
Cc:  Merged in:  
Authors:  Mark Saaltink  Reviewers:  Julian Rüth 
Report Upstream:  N/A  Work issues:  
Branch:  ddbc327 (Commits, GitHub, GitLab)  Commit:  ddbc327568db291cd50c539bd74fece2599474a5 
Dependencies:  Stopgaps: 
Description (last modified by )
From the google notebook bug reports
As you can see in the following script, even though an unpickled instance claims to be equal to the original, it behaves differently. Worse, several of the functions (e.g., M2.transition_matrix()) throw exceptions, and an exception is thrown if you just try to print the object's value.
sage: from sage.stats.hmm.hmm import DiscreteHiddenMarkovModel sage: M = DiscreteHiddenMarkovModel([[1.0]], [[0.1, 0.9]], [1.0]) sage: import pickle sage: M2 = pickle.loads(pickle.dumps(M)) sage: M2 == M True sage: M.log_likelihood([1]*4) 0.4214420626313051 sage: M2.log_likelihood([1]*4) inf sage: M2.emission_matrix()  ValueError Traceback (most recent call last) <ipythoninput242ee08778d25e> in <module>() > 1 M2.emission_matrix() /opt/sage5.12linux64bitfedora_release_16_vernex86_64Linux/local/lib/python2.7/sitepackages/sage/stats/hmm/hmm.so in sage.stats.hmm.hmm.DiscreteHiddenMarkovModel.emission_matrix (sage/stats/hmm/hmm.c:2760)() /opt/sage5.12linux64bitfedora_release_16_vernex86_64Linux/local/lib/python2.7/sitepackages/sage/matrix/constructor.pyc in _matrix_constructor(*args, **kwds) 641 raise ValueError, "entries has the wrong length" 642 elif len(args[0]) > 0: > 643 raise ValueError, "entries has the wrong length" 644 645 entries = args[0] ValueError: entries has the wrong length sage: M2  ValueError Traceback (most recent call last) <ipythoninput2013669956a766> in <module>() ... (long trace deleted)
Change History (13)
comment:1 Changed 9 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:2 Changed 8 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:3 Changed 8 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:4 Changed 6 years ago by
 Branch set to u/msaaltink/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly
comment:5 Changed 6 years ago by
 Commit set to aff5bba2bf8fa23788a48cdf84eb4c79f9d47505
 Status changed from new to needs_review
comment:6 Changed 6 years ago by
comment:7 Changed 6 years ago by
Btw. I could not find your name on https://trac.sagemath.org/wiki, you might want to add it there.
comment:8 Changed 6 years ago by
 Description modified (diff)
comment:9 Changed 6 years ago by
 Branch changed from u/msaaltink/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly to u/saraedum/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly
comment:10 Changed 6 years ago by
 Commit changed from aff5bba2bf8fa23788a48cdf84eb4c79f9d47505 to ddbc327568db291cd50c539bd74fece2599474a5
I tweaked the docstring a bit. If you are fine with this, feel free to set it to positive review yourself.
New commits:
ddbc327  Set indirect test in the correct lines

comment:11 Changed 6 years ago by
 Reviewers set to Julian Rüth
comment:12 Changed 6 years ago by
 Status changed from needs_review to positive_review
comment:13 Changed 6 years ago by
 Branch changed from u/saraedum/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly to ddbc327568db291cd50c539bd74fece2599474a5
 Resolution set to fixed
 Status changed from positive_review to closed
Note: See
TracTickets for help on using
tickets.
New commits:
Fixed ticket 15711, unpicking of DiscreteHiddenMarkovModel instances