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

NaiveBayesDecoder: example_data_hc statsmodel ValueError during predict #9

Open
Blinky0815 opened this issue Nov 6, 2019 · 5 comments

Comments

@Blinky0815
Copy link

Hi,
I am getting this error when trying to run the reconstruction using the NaiveBayesDecoder for example_data_hc.pickle
There is no error when trying to run it on the example data sets.
I am using Ubuntu 19.04 and python3.7


R2s: [0.53720666 0.79702171]
time_elapsed: 38.46179175376892
R2s: [0.65030058 0.77625489]
time_elapsed: 76.14730286598206
R2s: [0.68462371 0.53993597]
time_elapsed: 116.00050210952759
R2s: [0.76831659 0.75020602]
time_elapsed: 153.70069885253906
R2s: [0.53691629 0.64449254]
time_elapsed: 192.6614019870758
/home/blinky/.local/lib/python3.7/site-packages/statsmodels/genmod/families/links.py:521: RuntimeWarning: overflow encountered in exp
return np.exp(z)
/home/blinky/.local/lib/python3.7/site-packages/statsmodels/genmod/families/family.py:430: RuntimeWarning: overflow encountered in multiply
return 2 * resid_dev
/home/blinky/.local/lib/python3.7/site-packages/statsmodels/genmod/families/family.py:134: RuntimeWarning: invalid value encountered in multiply
return 1. / (self.link.deriv(mu)**2 * self.variance(mu))
/home/blinky/.local/lib/python3.7/site-packages/statsmodels/genmod/families/family.py:134: RuntimeWarning: divide by zero encountered in true_divide
return 1. / (self.link.deriv(mu)**2 * self.variance(mu))
/home/blinky/.local/lib/python3.7/site-packages/statsmodels/genmod/generalized_linear_model.py:1163: RuntimeWarning: invalid value encountered in multiply

  • self._offset_exposure)

ValueError Traceback (most recent call last)
in
106 #Fit model
107 print('fit')
--> 108 model_nb.fit(X_b_train,y_train)
109
110 #Get predictions

~/.local/lib/python3.7/site-packages/Neural_Decoding-0.1.2.dev0-py3.7.egg/Neural_Decoding/decoders.py in fit(self, X_b_train, y_train)
914 tuning=glm_run(y_train,X_b_train[:,j:j+1],input_xy)
915 if self.encoding_model=='quadratic':
--> 916 tuning=glm_run(y_train_modified,X_b_train[:,j:j+1],input_xy_modified)
917 #Enter tuning curves into matrix
918 tuning_all[j,:]=np.squeeze(tuning)

~/.local/lib/python3.7/site-packages/Neural_Decoding-0.1.2.dev0-py3.7.egg/Neural_Decoding/decoders.py in glm_run(Xr, Yr, X_range)
829 poiss_model = sm.GLM(Yr, X2, family=sm.families.Poisson())
830 try:
--> 831 glm_results = poiss_model.fit()
832 Y_range=glm_results.predict(sm.add_constant(X_range))
833 except np.linalg.LinAlgError:

~/.local/lib/python3.7/site-packages/statsmodels/genmod/generalized_linear_model.py in fit(self, start_params, maxiter, method, tol, scale, cov_type, cov_kwds, use_t, full_output, disp, max_start_irls, **kwargs)
1026 return self._fit_irls(start_params=start_params, maxiter=maxiter,
1027 tol=tol, scale=scale, cov_type=cov_type,
-> 1028 cov_kwds=cov_kwds, use_t=use_t, **kwargs)
1029 else:
1030 self._optim_hessian = kwargs.get('optim_hessian')

~/.local/lib/python3.7/site-packages/statsmodels/genmod/generalized_linear_model.py in _fit_irls(self, start_params, maxiter, tol, scale, cov_type, cov_kwds, use_t, **kwargs)
1164 wls_mod = reg_tools._MinimalWLS(wlsendog, wlsexog,
1165 self.weights, check_endog=True,
-> 1166 check_weights=True)
1167 wls_results = wls_mod.fit(method=wls_method)
1168 lin_pred = np.dot(self.exog, wls_results.params)

~/.local/lib/python3.7/site-packages/statsmodels/regression/_tools.py in init(self, endog, exog, weights, check_endog, check_weights)
46 if check_weights:
47 if not np.all(np.isfinite(w_half)):
---> 48 raise ValueError(self.msg.format('weights'))
49
50 if check_endog:

ValueError: NaN, inf or invalid value detected in weights, estimation infeasible.

@jglaser2
Copy link
Collaborator

jglaser2 commented Nov 6, 2019

Use the notebook "Examples_naivebayes_decoder_hc.ipynb" inside the "Examples_hippocampus" folder if you're using the hippocampus dataset. There is some additional preprocessing for that dataset.

@Blinky0815
Copy link
Author

Thanks!
The example doesn't crash.

@Blinky0815 Blinky0815 reopened this Nov 7, 2019
@Blinky0815
Copy link
Author

Blinky0815 commented Nov 7, 2019

Hi,
I am sorry I have to reopen this, but the issue only goes away if I comment

** In HC dataset, there is a long period without movement starting at ~80%, so we only use the first 80% of the data**
if dataset=='hc':
X=X[:int(.8X.shape[0]),:]
y=y[:int(.8
y.shape[0]),:]

and instead, work on the entire dataset.

Also in order to make the code work I needed to add the Neural_Decoding. prefix in the import section.

#Import function to get the covariate matrix that includes spike history from previous bins
from Neural_Decoding.preprocessing_funcs import get_spikes_with_history

#Import metrics
from Neural_Decoding.metrics import get_R2
from Neural_Decoding.metrics import get_rho

#Import decoder functions
from Neural_Decoding.decoders import NaiveBayesDecoder

#Import Bayesian Optimization package
from bayes_opt import BayesianOptimization

@jglaser2
Copy link
Collaborator

jglaser2 commented Nov 8, 2019

Thanks for mentioning the prefix - we did not update any of the examples in the Examples_hippocampus folder when we updated the code a few months ago. We will do that.

When I have time, I'll look into the issue with only using 80% of the data.

@Blinky0815
Copy link
Author

Nice! Thanks!

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