partofthething / ace

Python package for performing the Alternating Conditional Expectation (ACE) regression
MIT License
68 stars 20 forks source link

divide by zero encountered in double scalar #10

Closed mycarta closed 5 years ago

mycarta commented 7 years ago

Hi there. I am able to run the Wang example without problems. However, when I try to adapt to use with my own data I get an error message, attached below: divide

Do you know what might be causing this? I am including my data to allow you to try and replicate the issue. I realize it is not a lot of data points but I suspect this has not to do with the issue.

data_final.txt

partofthething commented 6 years ago

Hi. Those kinds of warnings usually show up when there's a NaN or something in one of the underlying numpy modules. I ran your problem and got the same result. I tried again changing the x variable to a list of numpy arrays and re-ran and it seemed to work. That's pretty fragile behavior so I'll look to fix it.

Here's what the transforms of your data look like:

image

partofthething commented 6 years ago

Here's a complete example using your data of how I got that plot:

import numpy as np

hunt = np.loadtxt('data_final.txt', skiprows=1)
hunt = list(zip(*hunt))
x = [np.array(xi) for xi in hunt[:4]]
y = np.array(hunt[4])

from ace import model
myace = model.Model()
myace.build_model_from_xy(x, y)

from ace import ace 
ace.plot_transforms(myace.ace)
mycarta commented 6 years ago

great, thank you!

partofthething commented 5 years ago

Aha, I got to the bottom of the issue here. Sometimes the denominator in ace.smoother.BasicFixedSpanSmoother._compute_cross_validated_residual_here is zero, which causes this. If I just avoid the NaN and pass to next iteration, it behaves much better. I'll push a more robust fix soon.

partofthething commented 5 years ago

I updated the code in 1593a49f3c2e84551 and it's more robust. Your initial code works with this now. Transforms are a bit nicer as well: ace_transforms

mycarta commented 5 years ago

Hi there. I re-installed ACE (tried both using pip and directly from source), but I am still getting the problem, ad result looks as before. IS there anything I am missing? image

partofthething commented 5 years ago

I neglected to do a full release so pip wouldn't have the code. But your "from source" install should have worked. Your transforms look like they did originally still. I'll re-verify with the new code and try to push it up to pip. Sorry about that.

partofthething commented 5 years ago

Ok I confirmed again that the code you posted above "works for me" on 0.3.2 which I just pushed to PyPI: https://pypi.org/project/ace/0.3.2/ Can you try it and let me know? If not, can you send me your pip freeze list? There may be a version issue in one of the underlying libraries that I don't have correct in the requirements.txt.

mycarta commented 5 years ago

Thanks Nick

I am now indeed getting the expected result (same as yours), this is great!

image

Minor thing, still getting the error:

C:\ProgramData\Anaconda\envs\py36\lib\site-packages\ace\smoother.py:310: RuntimeWarning: invalid value encountered in double_scalars self._variance_in_window)

partofthething commented 5 years ago

Excellent.

I'll try to clean up that RuntimeWarning as a separate issue.