Sum of square error

34 views (last 30 days)
Mike
Mike on 13 Apr 2011
Hello,
I'm very new to Matlab. We are attempting to curve fit a biologic response to a sinusoidal input. I'm able to fit the curve using the system identification tool without problems. For this study we need a measured of error. I have been able to get confidence intervals but what I would like to get is the sum of squares error. I have a few questions:
  1. Is there a way to display the sum of square error in Matlab?
  2. What is the number displayed on the model output as a measure of best fit?
  3. When the data is presented following the estimation, it displays the loss function and the FPE. What is the FPE?
Thank you. Michael

Accepted Answer

Rajiv Singh
Rajiv Singh on 18 Apr 2011
What type of model is model1 (what does class(model1) return)? PE is a System Identification Toolbox function that would work only on models recognized by it. You can create either IDPROC or IDPOLY structure for your model.
model = idproc('p1d'); model.Kp = K; model.Td = Td; model.Tp1 = Tp1;
model = idpoly(1,K/Tp1,1,1,[1 1/Tp1],'Ts',0,'noise',0);
  5 Comments
Rajiv Singh
Rajiv Singh on 18 Apr 2011
SID files are GUI session files. You must load them into GUI to view their contents. Suppose you have a file called foo.sid, then type ident(foo) in MATLAB command window. This will launch the GUI with the session contents loaded from foo.sid. If you see any models in the modal board of the GUI, you may export them by dragging their icons onto the "To workspace" box. HTH.
Mike
Mike on 19 Apr 2011
Hi Rajiv. That really helped. Thank you. After exported the data i am able to define the iddata and use E=pe(model,data) and the e=E,y. When I try the line you posted for MSE i get "undefined function or method norm for input arguements of type iddata". Thanks.

Sign in to comment.

More Answers (2)

Jarrod Rivituso
Jarrod Rivituso on 13 Apr 2011
Are you trying to determine coefficients of a dynamic model, something with derivatives in it such as
dx/dt = A*x + B*u y = C*x + D*u
Or are you trying to determine coefficients of a more basic equation, such as
y = A*sin(u)+B*cos(u)
If the latter is the case, you don't need to use system identification toolbox. You could instead do a linear regression analysis in MATLAB, or there's even a curve fitting toolbox
>> cftool
Generally, it is easy in MATLAB to find the sum of square errors between two vectors. For example:
>> x1 = randn(10,1);
>> x2 = randn(10,1);
>> residuals = x2-x1;
>> sum(residuals.^2)
  1 Comment
Mike
Mike on 14 Apr 2011
Thank you for your answer. It is the former. We are testing a 1st order system and trying to determine the time constant by fitting to a sinusoidal chirp function. I'm using the system identification tool to fit the sinusoidal output and determine the time constant. What I need to get is the sum of square error. Is there a way to do that? Thanks.

Sign in to comment.


Rajiv Singh
Rajiv Singh on 14 Apr 2011
FPE represents a norm of the prediction error; it stands for Final Prediction Error (more details in the product documentation). The fit shown on "model output" plot is the one returned by the COMPARE command. It is:
FIT = 100(1-norm(Ymeas-Ysim)/norm(Ymeas-mean(Ymeas))) (in %)
where YMeas is the measured response and Ysim is the output of the model. Type "help compare" for more information on COMPARE.
For obtaining other error measures, you could obtain the prediction or simulation error explicitly and use it to compute your measure of fit. For prediction error use the PE command. For simulation error, you could do e = ymeas - sim(model, u) where ymeas is the measured output signal for input signal u and SIM is the command that can be used on identified models to compute the simulation response.
  5 Comments
Rajiv Singh
Rajiv Singh on 16 Apr 2011
If you are using the process model, idproc, PE can be used. For example:
E = pe(model, data)
e = E.y;
MSE = norm(e)^2/length(e)
Mike
Mike on 18 Apr 2011
Thanks again for the answer. I am trying to use PE. My problem is that the model I create in the system identification tool is not recognized by PE. Do I need to use idmodel? The model transfer function is (Kexp(-Tds))/(1+Tp1s). The model name is model1. Thanks Rajiv. Mike.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!