I'm trying to transform a time series with a recursive filter to model a feedback.

I was able to do a simple filter like :

Y[t] = x +αY[t-1]

a[0]*y[n] = b[0]*x[n] + b[1]*x[n-1]

with scipy.signal.lfilter


but i don't know how i can model this kind of transformation with a filter:

Y = α (1 - e^(1 - β x)) + Y[T-1]

the desired effect is:

x = time_series data
feedback = .35
alfa = .40
beta = 10
transformed = np.empty(len(x.values))

for k in range(0, len(transformed )):
if k == 0:
    transformed[k] = x[0]
    transformed[k] = (alfa* (1-np.exp(-beta*x[k])) ) + feedback*transformed[k-1]

can someone tell me what kind of filter is it? and how i can define it with scipy.signal enter image description here

  • $\begingroup$ Well, what you propose doesn't look like a linear filter.. which can't be modeled with lfilter (linear filter). I don't have a solution for you, but maybe we can make a step if you answer these 2 questions. Why do you want to process it with scipy if you have a working solution (increase processing speed, maybe)?. Where does this algorithm comes from and what is its purpose? $\endgroup$ May 21 '19 at 0:51
  • $\begingroup$ Thanks for your time. 1)I want to process with a filter because i need to define a transformation function in order to use it in an optimizer. 2) that lead to the why... it's a time-series explaining the spend in ads,the transformation is the ad stock (with a feedback of the preceding interval )and with saturation (similar to diminishing return). $\endgroup$ May 21 '19 at 8:37
  • $\begingroup$ Ok, and this equation is known in your field of expertise or have you come up with it? Does it yoeld exact result or an approximation? Also, what does "running through an optimizer" means exactly? Do you mean you want to process a time series faster? $\endgroup$ May 21 '19 at 10:59
  • $\begingroup$ i think is going out the thread... this transformation model a signal in the marketing mix model. When i say optimizer i mean using a simplex algo to find the parameter of the transformation( in this case alpha,beta, and feedback) that better explain my marketing kpi. $\endgroup$ May 21 '19 at 14:39
  • $\begingroup$ I don't think this is going out of thread. In order to get a good answer, you need to ask a good question. If you limit yourself to "Can I use a function designed for linear filter to compute a non-linear filter", the answer will be simply "no". If you give some context, what is your final goal, how you arrived where you're at, then someone can get the bigger picture and bring you somewhere you may not have thinked of. So if I understand well, you have 2 timeseries, input and output and you want to compute efficiently the parameter of a predefined function that will bring you from A to B? $\endgroup$ May 21 '19 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.