Hello,
I am trying to fit a signal with a combination of signatures following something like this:
y(x) = a * A(x) + b * B(x) + c * C(x) with the specific constraints of having b to 0 if c is not, and similarly having c to 0 if b is not, meaning that if contribution of B is 'used' then C is not and vice versa.
My very first question is: is such a problem actually have solution (from a mathematical point of view) or it it not possible ?
My code is the following and (obviously) it doesn't work, where I was trying to used literal constraints capabilities through 'expr':
A = np.array(whatever)
B = np.array(whatever)
B = np.array(whatever)
def fnc(x, a, b, c, K):
vector = np.vectorize(np.int_)
y = a * A[vector(x)] + b * B[vector(x)] + c * B[vector(x)] + K
return y
model = Model(fnc, prefix='model_')
params = Parameters()
params.add('coeff_a', value=0.0, min=0.0)
params.add('coeff_b', value=0.0, min=0.0, expr='vary = False if c > 0.0 ')
params.add('coeff_c', value=0.0, min=0.0, expr='vary = False if b > 0.0 ')
params.add('B', value=0.0, min=0.0, max=1.0)
out = model.fit(data_to_fit[x1:x2], params, x=np.arange(x1, x2, 1))
What should I change to solve such a question? Is the approach using the 'expr' parameter correct and I simply didn't wrote it correctly, or should a different approach be used ?
I am rather new to this kind of problematic so apologies if my question is poorely formulated or if it is a trivial question, thanks in advance from France.
Best regards,
Raphael