natekupp / ffx

Fast Function Extraction
http://trent.st/ffx
Other
80 stars 93 forks source link

fail to real time series #21

Closed hfl15 closed 7 years ago

hfl15 commented 7 years ago

Hello. I have a time series 'x', I use np.gradient to calculate dx/dt, then I want to learn a function like that dx/dt=f(x). In this case here, for the FFX, target is the dx/dt, and trainx, testx is the original time series. But I face with the problem as follow. It is no problem to do the same things with the model dx/dt = 0.2x.

The problem as follow:

IndexError Traceback (most recent call last)

in () 4 test_y = dx[101::] 5 varnames = 'x' ----> 6 dxdt_fitted_result = run_ffx(train_x,train_y,test_x,test_y,varnames) in run_ffx(train_X, train_y, test_X, test_y, varnames) 3 4 def run_ffx(train_X, train_y, test_X, test_y, varnames): ----> 5 models = ffx.run(train_X, train_y, test_X, test_y, varnames) 6 base = [model.numBases() for model in models] 7 test_error = [model.test_nmse for model in models] /home/happyling/anaconda3/lib/python3.5/site-packages/ffx/api.py in run(train_X, train_y, test_X, test_y, varnames, verbose) 2 3 def run(train_X, train_y, test_X, test_y, varnames=None, verbose=False): ----> 4 return core.MultiFFXModelFactory().build(train_X, train_y, test_X, test_y, varnames, verbose) /home/happyling/anaconda3/lib/python3.5/site-packages/ffx/core.py in build(self, train_X, train_y, test_X, test_y, varnames, verbose) 557 ss = FFXBuildStrategy(approach) 558 --> 559 next_models = FFXModelFactory().build(train_X, train_y, ss, varnames, verbose) 560 561 # set test_nmse on each model /home/happyling/anaconda3/lib/python3.5/site-packages/ffx/core.py in build(self, X, y, ss, varnames, verbose) 658 #'lin' version of base 659 simple_base = SimpleBase(var_i, exponent) --> 660 lin_yhat = simple_base.simulate(X) 661 # checking exponent is a speedup 662 if exponent in [1.0, 2.0] or not yIsPoor(lin_yhat): /home/happyling/anaconda3/lib/python3.5/site-packages/ffx/core.py in simulate(self, X) 314 y -- 1d array of [sample_i] : float 315 """ --> 316 return X[:, self.var] ** self.exponent 317 318 def __str__(self): IndexError: too many indices for array
jmmcd commented 7 years ago

Can you provide a minimal piece of code that demonstrates this error, please?

hfl15 commented 7 years ago
dt = 0.1
x0=2
coef = -0.2
t = np.arange(0,30,dt)
x = odeint(lambda x,t:coef*x,x0,t)
plt.plot(t,x)
train_x = t
test_x = t
train_y = x
test_y = x
varnames = 't'
models = ffx.run(train_x,train_y,test_x,test_y,varnames)

The is a same error with the code above.

For the problem I face with before as follow. I got a time series 'x', and value as follow: array([ 0.46434198, 0.77793332, 0.88606827, 0.88066152, 0.70944786, 0.61392865, 0.38864751, -0.58096251, 0.08406741, 2.10258643, 0.96176274, -0.14662048, 0.99420322, -0.24394193, 1.29698107, 1.50604197, 0.68782087, 0.03901118, 0.14354163, 0.92031101, 0.26969907, -0.18266546, 0.89507952, 1.38709353, 0.40306551, 1.02484145, -0.29080041, 0.74729509, 1.61237467, -0.65485473, 0.14173938, 0.99240097, -0.41515559, 2.02869422, 0.64276464, 0.54724544, 1.38709353, 0.52201395, 0.38143852, 1.65202415, 0.35440478, -0.3052184 , 0.45713298, -0.10877324, -0.03668328, -0.48724556, 0.19400461, 1.18343938, -0.29080041])

I want to learn dx/dt = f(x), and the code is :

dt = 1
dx = np.gradient(x,dt)
train_x = x
test_x = x
train_y = dx
test_y = dx
varnames = 'x'
dxdt_fitted_result = run_ffx(train_x,train_y,test_x,test_y,varnames)

The IndexError is: too many indices for array. I don't know what's wrong happen so turn to your help. Very appreciate !

jmmcd commented 7 years ago

Yes, your arrays are the wrong shape. If you look at the x_square_test.py file, in /tests, you'll see that train_X and train_y have shapes (4, 1) and (4,) respectively. Yours are the other way around, i.e. (300,) and (300, 1).

jmmcd commented 7 years ago

(BTW use three backquotes to format blocks of code, and BTW run_ffx should be ffx.run.)

hfl15 commented 7 years ago

Thank you very much.