-
Is there a way to define a source term "u" within the ConstrainedSR3 optimizer? I have a 2nd order ODE with excitation (Duffing osc). This 2nd order ODE is built of a system of 2 first order ode: def duffing_oscillator(t, Y, args): Using the ps.STLSQ() the output is matching perfectly "including the source term": If I switch to ConstrainedSR3() and define the parameter of x1 in the first equaiton to be 1:
This produces an error: cannot reshape array of size 12 into shape (1,10) If I use the fit method without u: model.fit(x_train, t = dt) , then I get: x0' = 0.995 1 + 0.998 x1 + -0.369 x0^2 + -0.273 x1^2 Any suggestions or ideas? Thx and cheers |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I believe your constraint is not what you intend. It is prescribing that the coefficient of the constant term in the x0' equation should be equal to 1, which is why you get x0' ~ 1 + ..., which is not the duffing oscillator. Try constraint_lhs[0, 2] = 1 to make x0' = 1 * x1 + ... and you can additionally add constraints to zero out all the other terms (since x0' = x1 exactly here actually). I think the control u should be compatible with ConstrainedSR3 since u is just appended to the existing state variables so x = [x0, x1, u] and the constraints should work (albeit may need to be adjusted in the indices). What is the variable f above that you use during model.simulate? |
Beta Was this translation helpful? Give feedback.
-
Wait, just to clear out some doubts on my side: You mentioned that "and you can additionally add constraints to zero out all the other terms (since x0' = x1 exactly here actually)." |
Beta Was this translation helpful? Give feedback.
-
For your two questions:
This library is not the one you were using for computing n_features because you used library.fit( x_train ) without the u variable! x_train becomes [x_train, u] when you call model.fit.
|
Beta Was this translation helpful? Give feedback.
I believe your constraint is not what you intend. It is prescribing that the coefficient of the constant term in the x0' equation should be equal to 1, which is why you get x0' ~ 1 + ..., which is not the duffing oscillator. Try constraint_lhs[0, 2] = 1 to make x0' = 1 * x1 + ... and you can additionally add constraints to zero out all the other terms (since x0' = x1 exactly here actually).
I think the control u should be compatible with ConstrainedSR3 since u is just appended to the existing state variables so x = [x0, x1, u] and the constraints should work (albeit may need to be adjusted in the indices). What is the variable f above that you use during model.simulate?