`correctDrift` fails
After the
Function _driftFit
def _driftFit(x, shift_target, cal_mean, driftModel):
x_index = x.index - x.index[0]
x_data = x_index.total_seconds().values
x_data = x_data / x_data[-1]
y_data = x.values
origin_mean = np.mean(y_data[:cal_mean])
target_mean = np.mean(y_data[-cal_mean:])
dataFitFunc = functools.partial(driftModel, origin=origin_mean, target=target_mean)
# if drift model has free parameters:
try:
# try fitting free parameters
fit_paras, *_ = curve_fit(dataFitFunc, x_data, y_data)
data_fit = dataFitFunc(x_data, *fit_paras)
data_shift = driftModel(
x_data, *fit_paras, origin=origin_mean, target=shift_target
)
except RuntimeError:
# if fit fails -> make no correction
data_fit = np.array([0] * len(x_data))
data_shift = np.array([0] * len(x_data))
# when there are no free parameters in the model:
except ValueError:
data_fit = dataFitFunc(x_data)
data_shift = driftModel(x_data, origin=origin_mean, target=shift_target)
return data_fit, data_shift
Depending on the input (I always triggered the failure with x
of length 1) the call to curve_fit(dataFitFunc, x_data, y_data)
fails with a ValueError
and execution jumps to dataFitFunc(x_data)
. In my use case the argument to dataFitFunc
is the function lib.ts_operators.expDriftModel
shown below:
def expDriftModel(x, c, origin, target):
c = abs(c)
b = (target - origin) / (np.exp(c) - 1)
return expModelFunc(x, origin, b, c)
This function however takes 4 arguments but only gets passed a single one, which finally raises a TypeError
.
So I guess the main problem are not input series of length 1 but rather the faulty call to dataFitFunc
. Could you please have a look into this @luenensc ?
Edited by David Schäfer