Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during plotting #1

Open
sbhakat opened this issue Feb 25, 2018 · 19 comments
Open

Error during plotting #1

sbhakat opened this issue Feb 25, 2018 · 19 comments

Comments

@sbhakat
Copy link

sbhakat commented Feb 25, 2018

Hi,

During executing the following command

scatter(plot_feat[:,0],plot_feat[:,1],c=new_y.data.tolist(),cmap='jet')
xlim([-np.pi,np.pi])
ylim([-np.pi,np.pi])
cb = plt.colorbar()
xlabel(r'$\phi$')
ylabel(r'$\psi$')
cb.set_label("Neural Network Projection")

I got an error like


TypeError Traceback (most recent call last)
~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
131 try:
--> 132 rgba = _colors_full_map.cache[c, alpha]
133 except (KeyError, TypeError): # Not in cache, or unhashable.

TypeError: unhashable type: 'list'

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
3985 # must be acceptable as PathCollection facecolors
-> 3986 colors = mcolors.to_rgba_array(c)
3987 except ValueError:

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/colors.py in to_rgba_array(c, alpha)
232 for i, cc in enumerate(c):
--> 233 result[i] = to_rgba(cc, alpha)
234 return result

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
133 except (KeyError, TypeError): # Not in cache, or unhashable.
--> 134 rgba = _to_rgba_no_colorcycle(c, alpha)
135 try:

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
188 if len(c) not in [3, 4]:
--> 189 raise ValueError("RGBA sequence should have length 3 or 4")
190 if len(c) == 3 and alpha is None:

ValueError: RGBA sequence should have length 3 or 4

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
in ()
----> 1 scatter(plot_feat[:,0],plot_feat[:,1],c=new_y.data.tolist(),cmap='jet')
2 xlim([-np.pi,np.pi])
3 ylim([-np.pi,np.pi])
4 cb = plt.colorbar()
5 xlabel(r'$\phi$')

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
3376 vmin=vmin, vmax=vmax, alpha=alpha,
3377 linewidths=linewidths, verts=verts,
-> 3378 edgecolors=edgecolors, data=data, **kwargs)
3379 finally:
3380 ax._hold = washold

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/init.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.name),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.doc
1719 if pre_doc is None:

~/miniconda2/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
3989 msg = ("c of shape {0} not acceptable as a color sequence "
3990 "for x with size {1}, y with size {2}")
-> 3991 raise ValueError(msg.format(c.shape, x.size, y.size))
3992 else:
3993 colors = None # use cmap, norm after collection is created

AttributeError: 'list' object has no attribute 'shape'

Any idea how to solve it?

@msultan
Copy link
Owner

msultan commented Feb 25, 2018

weird, i have it working on my machine. try the following for the color instead?

c=np.array(new_y.data.tolist())[:,0]

@sbhakat
Copy link
Author

sbhakat commented Feb 25, 2018

Cool It is working. Is this a numpy array type of error?

@sbhakat
Copy link
Author

sbhakat commented Feb 26, 2018

One more possibly small error. When using the following command

from helper_func.helper import *

Got an error like

ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 from helper_func.helper import *

ModuleNotFoundError: No module named 'helper_func'

@msultan
Copy link
Owner

msultan commented Feb 26, 2018

you have to be in the same folder to be able to call that. It wont work for arbitrary scripts.

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

What you mean by same folder? Same folder of in my computer path or according to the Github file structure? I am in the same folder of my computer.

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

Sorry okay got it

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

Okay now I put all the files in the correct path but when I was trying to execute the following command I got an error like

if os.path.isfile("./autoencoder.net"): model = torch.load("./autoencoder.net") else: model = AutoEncoder()


ModuleNotFoundError Traceback (most recent call last)
in ()
1 if os.path.isfile("./autoencoder.net"):
----> 2 model = torch.load("./autoencoder.net")
3 else:
4 model = AutoEncoder()

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module)
265 f = open(f, 'rb')
266 try:
--> 267 return _load(f, map_location, pickle_module)
268 finally:
269 if new_fd:

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/serialization.py in _load(f, map_location, pickle_module)
418 unpickler = pickle_module.Unpickler(f)
419 unpickler.persistent_load = persistent_load
--> 420 result = unpickler.load()
421
422 deserialized_storage_keys = pickle_module.load(f)

ModuleNotFoundError: No module named 'pandas.indexes'

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

Sorry again. I have trouble understanding the following things

# Hyper Parameters
input_size = 4
hidden_size = 8
# The output class becomes our Plumed collective variable(CV)
num_classes = 1

What is the Hyper parameter? How can one set the values in each case.

What is the following part doing?

`class Encoder(nn.Module):
def init(self):
super(Encoder, self).init()
self.df = df
self.hidden_size = hidden_size
self.input_size = input_size
self.num_classes = num_classes

    self.l1 = nn.Linear(input_size, hidden_size) 
    self.l2 = nn.Sigmoid()
    self.l3 = nn.Linear(hidden_size, num_classes)     

def forward(self, x):
    out = self.l1(x)
    out = self.l2(out)
    out = self.l3(out)
    return out

class Decoder(nn.Module):
def init(self):
super(Decoder, self).init()
self.l1 = nn.Linear(num_classes, hidden_size)
self.l2 = nn.Sigmoid()
self.l3 = nn.Linear(hidden_size, input_size)

def forward(self, x):
    out = self.l1(x)
    out = self.l2(out)
    out = self.l3(out)
    return out

class AutoEncoder(nn.Module):
def init(self):
super(AutoEncoder, self).init()
self.fc1 = Encoder()
self.fc2 = Decoder()

def forward(self, x):
    return self.fc2(self.fc1(x))`

I tried to train the autoencoder with the following script

`optimizer = optim.Adam(model.parameters(), lr=0.5)
loss_list=[]
for epoch in range(5):
for i in rnd_sampler:
optimizer.zero_grad()

    x = Variable(torch.from_numpy(np.vstack(i)))
    y=model(x)
    output = loss(y,x) 
    output.backward()
    loss_list.extend(output.data.tolist())
    optimizer.step()`

But it gives an error like

`---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
in ()
6
7 x = Variable(torch.from_numpy(np.vstack(i)))
----> 8 y=model(x)
9 output = loss(y,x)
10 output.backward()

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
355 result = self._slow_forward(*input, **kwargs)
356 else:
--> 357 result = self.forward(*input, **kwargs)
358 for hook in self._forward_hooks.values():
359 hook_result = hook(self, input, result)

in forward(self, x)
38
39 def forward(self, x):
---> 40 return self.fc2(self.fc1(x))

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
355 result = self._slow_forward(*input, **kwargs)
356 else:
--> 357 result = self.forward(*input, **kwargs)
358 for hook in self._forward_hooks.values():
359 hook_result = hook(self, input, result)

in forward(self, x)
12
13 def forward(self, x):
---> 14 out = self.l1(x)
15 out = self.l2(out)
16 out = self.l3(out)

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
355 result = self._slow_forward(*input, **kwargs)
356 else:
--> 357 result = self.forward(*input, **kwargs)
358 for hook in self._forward_hooks.values():
359 hook_result = hook(self, input, result)

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/linear.py in forward(self, input)
53
54 def forward(self, input):
---> 55 return F.linear(input, self.weight, self.bias)
56
57 def repr(self):

~/miniconda2/envs/py36/lib/python3.6/site-packages/torch/nn/functional.py in linear(input, weight, bias)
833 if input.dim() == 2 and bias is not None:
834 # fused op is marginally faster
--> 835 return torch.addmm(bias, input, weight.t())
836
837 output = input.matmul(weight.t())

RuntimeError: size mismatch, m1: [500 x 2], m2: [4 x 8] at /opt/conda/conda-bld/pytorch-cpu_1518282373170/work/torch/lib/TH/generic/THTensorMath.c:1434`

What is the reason of this error?

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

ModuleNotFoundError: No module named 'pandas.indexes'

That is a pandas issue, look into updating pandas to 0.19 i believe. google might be able to do it as well.

What is the Hyper parameter? How can one set the values in each case.

They specify the network size, shape and how its trained. For example input_size is the number of input features. hidden size is the number of hidden nodes per layer. The pytorch website will likely have more data.

RuntimeError: size mismatch, m1: [500 x 2], m2: [4 x 8] at /opt/conda/conda-bld/pytorch-cpu_1518282373170/work/torch/lib/TH/generic/THTensorMath.c:1434`

What is your input number of features.For example, alanine is 4 features which are sin cosine transform of the backbone dihedrals \phi and \psi. In your case there is a mismatch between the vectors here so pytorch is complaining about that.

ps: I ended up writing a paper on how to use auto encoder and its variants for enhanced sampling. The following github is a bit more complete since we wrote a lot more code for it: https://github.com/msultan/vde_metadynamics

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

Okay got it I had two features hence it was a mismatch.

However I didn't understand the exact meaning of #
# The output class becomes our Plumed collective variable(CV)
num_classes = 1

When I am trying to render the plumed file I got an error like


ValueError Traceback (most recent call last)
in ()
----> 1 print(render_network(model.fc1))

~/Reweighting_test/2D_COM_distance/TF-MetaD/helper_func/helper.py in render_network(net)
73 output =[]
74 # Start by evaluating the actual dihedrals + sin-cosine transform aka the input features
---> 75 output.append(write_df(net.df))
76 index = 0
77 # Go over every layer of the netowrk

~/Reweighting_test/2D_COM_distance/TF-MetaD/helper_func/helper.py in write_df(df)
30 label = "l0%d"%feature_index
31
---> 32 output.append(create_feature(argument, df.otherinfo[feature_index], label))
33 output.append("\n")
34

~/Reweighting_test/2D_COM_distance/TF-MetaD/helper_func/helper.py in create_feature(argument, func, feature_label)
111 label = feature_label
112 else:
--> 113 raise ValueError("Can't find function")
114
115 return plumed_matheval_template.render(arg=arg, func=f,\

ValueError: Can't find function

Any help?

I was going through the manuscript of VDE metadynamics will try it for sure.

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

Yea, so I didn't write the code to transform all possible featurizers from MSMBuilder to Plumed. I think it currently does Dihedrals, alpha carbon dihedrals, and contact distances. I think it might also do angles but definitely not center of mass. One reason being that I am fairly sure, though could be wrong, that the COM calculation in Plumed is different than in Mdtraj/MSMbuilder so I need to write a new featurizer for MSMbuilder first to make everything compatible. Unfortunately, all the packages use slightly different definitions of everything which makes writing these transforms rather cumbersome.

Distances or dihedrals are pretty alright, and I implemented the closest heavy atom distance in mdtraj to be the same as Plumed for that reason. If you want to work on it yourself, please feel free to file a pull request !

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

My case it is just two features both are simple CA distances. So how should I render?

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

Ohh, try using the VDE_Metadynamics module. I think that has the ca distances.

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

Sorry about the code fragmentation on this, this repo was more of a weekend project to try to see if I could teach Plumed basic neural networks.

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

print(df) gives the following

       atominds featuregroup featurizer otherinfo      resids    resnames  \

0 [[534], [1203]] ca Contact 20 [35, 79] [ASP, VAL]
1 [[3336], [4558]] ca Contact 20 [215, 293] [ASH, LEU]

  resseqs  

0 [36, 80]
1 [216, 294]

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

Ha ha I am laughing on myself. This is the NOOBEST question. So I installed VDE Metadynamics and all the render files are in this path

~/miniconda2/envs/py36/lib/python3.6/site-packages/vde_metadynamics-0.1-py3.6.egg/vde_metadynamics

How can I define the path inside notebook to import the .py scripts.

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

Try walking through the following notebook

https://github.com/msultan/vde_metadynamics/blob/master/examples/alanine/ala_res.ipynb

@sbhakat
Copy link
Author

sbhakat commented Feb 27, 2018

But that is not the problem seems like my installation paath is not catching up


ModuleNotFoundError Traceback (most recent call last)
in ()
6 from msmbuilder.msm import ContinuousTimeMSM
7 from msmbuilder.utils import verbosedump,verboseload
----> 8 from vde_metadynamics import *
9 get_ipython().run_line_magic('pylab', 'inline')
10 from matplotlib import pyplot as plt

ModuleNotFoundError: No module named 'vde_metadynamics'

@msultan
Copy link
Owner

msultan commented Feb 27, 2018

weird, can you try

python setup.py develop

in your folder, and let me know if that works? Also you might have to restart the ipython notebook kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants