convexengineering / gpfit

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

ValueError('Not enough data points') #72

Closed iclucho closed 7 years ago

iclucho commented 7 years ago

Hi,

I'm trying to run a SMA fit on my data but I can't seem to enter it correctly. My x-data is a 1062x4 matrix and correspondingly my y-data is a 1062x1 vector.

x array([[ -0.69314718, -1.2039728 , -13.81551056, -13.81551056], [ -0.65392647, -1.2039728 , -13.81551056, -13.81551056], [ -0.61618614, -1.2039728 , -13.81551056, -13.81551056], ..., [ 0.37843644, 0.18232156, -11.51292546, -9.21034037], [ 0.39204209, 0.18232156, -11.51292546, -9.21034037], [ 0.40546511, 0.18232156, -11.51292546, -9.21034037]])

x.shape (1062, 4)

y array([-10.09725113, -10.0955659 , -10.09396532, ..., -5.87544124, -5.87526203, -5.87509244])

y.shape (1062,)

When I try to run the fit, I get the following error:

cSMA, errorSMA = fit(x,y,K,"SMA") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/gpfit/fit.py", line 72, in fit params = get_params(ftype, K, xdata, ydata) File "/usr/local/lib/python2.7/dist-packages/gpfit/fit.py", line 26, in get_params ba = ba_init(xdata, ydata.reshape(ydata.size, 1), K).flatten('F') File "/usr/local/lib/python2.7/dist-packages/gpfit/ba_init.py", line 36, in ba_init raise ValueError('Not enough data points') ValueError: Not enough data points

I know that this is probably not a tool error but a user-keyboard bug, but I just don't get what could be the problem here. Any pointers are much appreciated.

Regards,

Lucho.

bqpd commented 7 years ago

You probably need to transpose x, as in this example:

from gpfit.fit import fit
from numpy import logspace, log, log10, random

# fixed initial guess for fitting
random.seed(33404)

u = 100*random.random((1062, 4)) + 1
# note: should be (4, 1062), we'll fix this on the next line
u = u.T
w = (u**2).sum(axis=1)
x = log(u)
y = log(w)
K = 4

cSMA, errorSMA = fit(x, y, K, "SMA")

print "SMA RMS Error: %.5g" % errorSMA
bqpd commented 7 years ago

(also, welcome to gpfit / gpkit! Always curious to hear what uses it's finding, how you heard about it, and how we can make it more useful to you: give the feedback here or via email to gpkit@mit.edu)

iclucho commented 7 years ago

Thanks bqpd!

I actually tried to transpose y-data but not the x-data :p

bqpd commented 7 years ago

(the first thing I'm noticing here is that that required shape is...odd. I understand why it was done in the original code, but I'm going to add it to the list of things to change now that I'm the maintainer)

bqpd commented 7 years ago

(also note that the docstring has this info! Since I don't know your level of Python experience, I'll note that you can see this and much additional documentationby typing help(fit) into an interactive session)

iclucho commented 7 years ago

I'm pretty much an absolute beginner. I'm used to work with MATLAB. My intention is to use gpfit/kit in IC design. I read the paper "Fitting geometric programming models to data" and I'm curious to see how can this extended GP approach help me in analog design automation. Thanks for your quick reply and for sure I'll be dropping questions here.

bqpd commented 7 years ago

Awesome! We don't do much IC stuff in the lab; we've talked about abstractions/syntax for making it easy to connect components, but without much chance to apply them they've gone stale, so let me know if you end up with something monolithic and complex that could use some more modularity. :)