convexengineering / gpfit

Fit posynomials to data
http://gpfit.readthedocs.io/en/latest/
MIT License
10 stars 7 forks source link

fit should fail gracefully when given infinite or nan inputs #35

Open 1ozturkbe opened 8 years ago

1ozturkbe commented 8 years ago

I have been trying to fit a SMA function with two terms to the data attached, but been getting the index error above. Don't exactly know what I am doing wrong. The data, code, and specific error are attached.

issue.zip

1ozturkbe commented 8 years ago

Never mind, figured it out. Made the mistake of leaving a 1/log(1) in the data, giving inf... Problem resolved.

It is odd that this gives an indexError though.

whoburg commented 8 years ago

Thanks @1ozturkbe. Agreed that this should fail more gracefully. I reduced your code and data to a MWE:

import numpy as np
from gpfit.fit import fit

logL = np.array([
    float("-inf"),
    -2.083896,
    -1.390749,
    -1.021651,
    -0.762140,
    -0.579818,
    -0.432494,
    -0.316234])

logh = np.array([
    float("-inf"),
    8.095855,
    8.789002,
    9.194467,
    9.482149,
    9.705293,
    9.887614,
    10.041765])

cstrt, rms_error = fit(logh,logL, 2, "SMA")

This gives an IndexError; it should fail more gracefully, probably by raising a ValueError for the -inf.

Let's leave this open to make sure we fix it.