FOPDT Fit Not Converging

32 views
Skip to first unread message

JFOXX

unread,
Apr 3, 2017, 12:05:10 AM4/3/17
to apmonitor
Hi, this post is in response to your YouTube video on 'Fit Lower Order Models in Python'. I collected some temperature data from my adruino (attached) but it doesn't seem to converge using the Python FOPDT .py. You also mentioned  fmincon by I'm not familiar using Matlab for optimisation - will you be willing to also give an example on how to upload my data into Matlab and how to call the function? Also the data attached is time, input, and output, respectively. 
data.csv

John Hedengren

unread,
Apr 3, 2017, 1:53:36 AM4/3/17
to apmo...@googlegroups.com

Jamie,

 

I had a bug in the Python script that assumed all time steps were equal. I modified the script at http://apmonitor.com/pdc/index.php/Main/FirstOrderOptimization to accept any time step sequence and have also attached the new Python script to this message. As I mentioned on the YouTube video comment, the Scipy.optimize.minimize solver is not very good and it fails to find a better solution in this case. I just got it close to an optimal solution with guesses of Kp = 0.47, taup=190, and theta=15. The optimizer changed it slightly but came up with a slightly worse solution than my guess (see Sum of Squared Errors - SSE):

 

Initial SSE Objective: 17037.4813533

Final SSE Objective: 17038.3204311

“Optimized values”:

Kp: 0.470073645057

taup: 190.065271549

thetap: 14.9793341623

 

With the initial guess (Kp = 0.47, taup=190, and theta=15), the solution is close to your data.

 

You could convert over to fmincon or fminsearch if you have the energy to learn MATLAB. Here is a tutorial with fminsearch (fmincon is similar): https://youtu.be/ynm7B0N0_Yw  There are also tutorials on using more advanced estimation methods in Python and MATLAB at the dynamic optimization course web-site at http://apmonitor.com/do (see Estimation section).

 

Best regards,

 

John Hedengren

--
--
APMonitor user's group e-mail list.
- To post a message, send email to apmo...@googlegroups.com
- To unsubscribe, send email to apmonitor+...@googlegroups.com
- Visit this group at http://groups.google.com/group/apmonitor

---
You received this message because you are subscribed to the Google Groups "apmonitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apmonitor+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

first_order_fit.zip

JFOXX

unread,
Apr 4, 2017, 7:58:29 AM4/4/17
to apmonitor
Thank you so much for this!
Reply all
Reply to author
Forward
0 new messages