msultan / SML_CV

Using supervised machine learning to build collective variables for accelerated sampling
MIT License
27 stars 5 forks source link

Problem doing tICA using features.pkl #5

Closed sbhakat closed 5 years ago

sbhakat commented 5 years ago

I was trying to perform tICA using the features.pkl which was described in this notebook

https://github.com/msultan/SML_CV/blob/master/alanine_example/01-svm_example.ipynb

My steps looks like:

plot_feat = load("raw_features.pkl")
train_feat = load("features.pkl")
df = load("./train_data/feature_descriptor.pkl")
from msmbuilder.io import load_trajs, save_trajs, save_generic
from msmbuilder.io.sampling import sample_dimension
from msmbuilder.io import load_trajs, save_generic, preload_top, backup
%matplotlib inline

ncomp = 4

#define our tica model
tica_mdl = tICA(lag_time=100,n_components=ncomp, kinetic_mapping=False)
tica_features = train_feat.fit_transform(tica_mdl, out_ds = 'reg_ticas_10lt_5tics//')

#load the features
tica_features = dataset("./reg_ticas_10lt_5tics/")

#for each feature from our contact we now have 4 tICs
#for each feature from our contact we now have 4 tICs
verbosedump(tica_mdl,"tica_mdl.pkl")

It gives an error TypeError: 'list' object is not callable

Am i doing something wrong?

msultan commented 5 years ago

I am not using the MSMBuilder dataset object here. you will need to first generate that dataset for the tica_features before the code will work as you have it written. Alternatively, the following modification should work.

tica_mdl = tICA(lag_time=100,n_components=ncomp, kinetic_mapping=False)
tica_features = tICA.fit_transform(train_feat)
verbosedump(tica_mdl,"tica_mdl.pkl")
verbosedump(tica_features,"tica_features.pkl")
sbhakat commented 5 years ago

getting an error like

TypeError: fit_transform() missing 1 required positional argument: 'sequences'

msultan commented 5 years ago

This should work, i am guessing I make train_feat a dictionary instead of a list of lists.

tica_features = tICA.fit_transform(list(train_feat.values())
sbhakat commented 5 years ago

Well it can't be tICA

tica_mdl = tICA(lag_time=100,n_components=4, kinetic_mapping=False)
tica_features = tICA.fit_transform(list(train_feat.values())

#verbosedump(tica_mdl,"tica_mdl.pkl")
verbosedump(tica_features,"tica_features.pkl")

We defined tica_mdl but not using it during fit_transform that seems wired or am I misunderstanding the process?

After that I am getting an error like:


 File "<ipython-input-51-01cfb022b000>", line 11
    verbosedump(tica_features,"tica_features.pkl")
              ^
SyntaxError: invalid syntax

Attaching my notebook for more reference. bhakat_method.pdf

msultan commented 5 years ago

whoops, my bad, that should have been:

tica_features = tica_mdl.fit_transform(list(train_feat.values())
sbhakat commented 5 years ago

The verbose dump syntax problem still persists

from msmbuilder.io import load_trajs, save_trajs, save_generic
from msmbuilder.io.sampling import sample_dimension
from msmbuilder.io import load_trajs, save_generic, preload_top, backup
from msmbuilder.utils import dump
%matplotlib inline

tica_mdl = tICA(lag_time=100,n_components=2, kinetic_mapping=False)
tica_features = tica_mdl.fit_transform(list(train_feat.values())

#verbosedump(tica_mdl,"tica_mdl.pkl")
verbosedump(tica_mdl,"tica_mdl_rawpos.pkl")

It still gives an error like

  File "<ipython-input-63-e51343b3e9e5>", line 11
    verbosedump(tica_mdl,"tica_mdl_rawpos.pkl")
              ^
SyntaxError: invalid syntax

Not sure why is this?

msultan commented 5 years ago

tica_features = tica_mdl.fit_transform(list(train_feat.values()) that line is missing a ) at the end. thats a python syntax error.

sbhakat commented 5 years ago

AttributeError Traceback (most recent call last)

in () 6 7 tica_mdl = tICA(lag_time=100,n_components=4, kinetic_mapping=False) ----> 8 tica_features = tica_mdl.fit_transform(list(train_feat.values())) 9 10 #verbosedump(tica_mdl,"tica_mdl.pkl") AttributeError: 'list' object has no attribute 'values' Any help? Seems like something wring with the train_feat thingy.
msultan commented 5 years ago

wait, is train_feat already a list? try printing out its type in an ipython shell. my guess is that you need to remove ".values()"

sbhakat commented 5 years ago

Got it. Thanks