0

I want to save an object ('clustering') of the following type in order to use it later. The object has the type

<class 'pyemma.coordinates.clustering.kmeans.KmeansClustering'>

I tried using pickle, but the loaded object leads to an error.

n_clusters = 3
clustering = coor.cluster_kmeans(Y, k=n_clusters, max_iter=100, tolerance=1e-10, fixed_seed=True) 
with open("clustering.file", "wb") as f:
 pickle.dump(clustering, f, pickle.HIGHEST_PROTOCOL)
with open("clustering.file", "rb") as f:
 clustering=pickle.load(f)
clustering.save_traj()
dtrajs = clustering.dtrajs # get discrete trajectories

This is the error:

 File "pyemma_dG.py", line 102, in <module>
 dtrajs = clustering.dtrajs # get discrete trajectories
 File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/clustering/interface.py", line 101, in dtrajs
 self._dtrajs = self.assign(stride=1)
 File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/clustering/interface.py", line 217, in assign
 mapped = self.get_output(stride=stride, chunk=self.chunksize, skip=skip)
 File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/data/_base/transformer.py", line 182, in chunksize
 return self.default_chunksize
 File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/data/_base/iterable.py", line 74, in default_chunksize
 if self._default_chunksize is None:
AttributeError: 'KmeansClustering' object has no attribute '_default_chunksize'
asked Sep 1, 2018 at 11:03

1 Answer 1

1

Unfortunately this old version of PyEMMA did not support pickling complex objects in the coordinates subpackage. Versions higher than 2.5 support it correctly. I would recommend using the builtin save and load functionality as it also provides very fast and io efficient array serialization with HDF5.

answered Aug 13, 2019 at 6:38
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.