Opened 8 years ago

Closed 5 years ago

#15711 closed defect (fixed)

DiscreteHiddenMarkovModel instances do not unpickle correctly

Reported by: ppurka Owned by:
Priority: major Milestone: sage-6.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:

Status badges

Description (last modified by saraedum)

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)
<ipython-input-24-2ee08778d25e> in <module>()
----> 1 M2.emission_matrix()

/opt/sage-5.12-linux-64bit-fedora_release_16_verne-x86_64-Linux/local/lib/python2.7/site-packages/sage/stats/hmm/hmm.so in sage.stats.hmm.hmm.DiscreteHiddenMarkovModel.emission_matrix (sage/stats/hmm/hmm.c:2760)()

/opt/sage-5.12-linux-64bit-fedora_release_16_verne-x86_64-Linux/local/lib/python2.7/site-packages/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)
<ipython-input-20-13669956a766> in <module>()
... (long trace deleted)

Change History (13)

comment:1 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:2 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:4 Changed 5 years ago by msaaltink

  • Branch set to u/msaaltink/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly

comment:5 Changed 5 years ago by msaaltink

  • Commit set to aff5bba2bf8fa23788a48cdf84eb4c79f9d47505
  • Status changed from new to needs_review

New commits:

aff5bbaFixed ticket 15711, unpicking of DiscreteHiddenMarkovModel instances

comment:6 Changed 5 years ago by saraedum

  • Authors set to Mark Saaltink

comment:7 Changed 5 years ago by saraedum

Btw. I could not find your name on https://trac.sagemath.org/wiki, you might want to add it there.

comment:8 Changed 5 years ago by saraedum

  • Description modified (diff)

comment:9 Changed 5 years ago by saraedum

  • Branch changed from u/msaaltink/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly to u/saraedum/discretehiddenmarkovmodel_instances_do_not_unpickle_correctly

comment:10 Changed 5 years ago by saraedum

  • 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:

ddbc327Set indirect test in the correct lines

comment:11 Changed 5 years ago by saraedum

  • Reviewers set to Julian Rüth

comment:12 Changed 5 years ago by msaaltink

  • Status changed from needs_review to positive_review

comment:13 Changed 5 years ago by vbraun

  • 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.