parameter estimation using lsqcurvefit

5 Ansichten (letzte 30 Tage)
Anuj Anand
Anuj Anand am 27 Jan. 2014
Beantwortet: Anuj Anand am 28 Jan. 2014
I have a strange problem. I wrote a function named "post_2" which uses lsqcurvefit command which interns calls a model function named "function_one" in which I pass few arguments as below. This works perfectly fine.
However, now I am not given the value of dVec (time lag for the signal eVec) so I cannot pass dVec as input. Therefore, I want to make 'd' (i.e. input to "function_one") as a variable i.e. k(3) so that the optimizer also estimates the value of k(3) from the model fitting. The condition on k(3) is that it can only take positive real integers values from 0-to-length(aVec). I have attached a matlab file 'testVar.mat'.
Kindly suggest how to do this. Many Thanks in advance.
if true
% Start script for calling the Function "post_2"
testVec = load('testVar.mat') ;
aVec = testVec(:,1);
bVec = testVec(:,2);
cVec = testVec(:,3);
dVec = testVec(1,4);
[X,Y] = post_2( aVec, [0 ; 0 ; bVec(1:end-2)] , cVec, 3 )
disp('The output should be X=0.0032 and Y=0.1984')
% End script for calling the Function "post_2"
% FUNCTION code
function [ X, Y ] = post_2( aVec , bVec , cVec , dVec )
eVec = [ zeros(dVec,1) ; cVec ];
lb = [0 0]; ub = [1 1]; initalCondition = [0.50 0.50];
ahat = lsqcurvefit( @(x,aVec) function_one(x,aVec,eVec,dVec),initalCondition,aVec,bVec,lb,ub);
X = ahat(1); Y = ahat(2);
function F = function_one(k,a,e,d)
conv_res = k(1) * conv( e , exp(-k(1)*a/k(2)) );
F = conv_res( 1:(length(e)-d) );
end
end
% -- -Function End---%
end

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 28 Jan. 2014
Unfortunately, Optimization Toolbox solvers do not accept integer-valued variables. So lsqcurvefit will not be able to optimizae over dvec.
You have two choices that I see. One is to optimize over dvec in an outside loop (I mean, do an exhaustive search over various dvec values, or use patternsearch to optimize over dvec where you take the initial point for patternsearch to be an integer vector, have the stopping criterion be when the mesh coes below size 1, and turn off mesh scaling). Or you could use integer ga to try to search the dvec values, realizing that ga is not all that reliable.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Weitere Antworten (1)

Anuj Anand
Anuj Anand am 28 Jan. 2014
Hello Alan Weiss, Many Thanks for your reply. I will read up on your suggestion. However, the exhaustive search of dVec values will depend on the final error from the optimization routine. I think what you mean here is (correct me if I am wrong), I can run an outer loop with all the possible dVec values and save the error from each, and then select the dVec value that gives the minimum error. I will read up on this anyways. But thanks a million. With Regards.

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by