parameter estimation using lsqcurvefit

5 次查看(过去 30 天)
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

采纳的回答

Alan Weiss
Alan Weiss 2014-1-28
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

更多回答(1 个)

Anuj Anand
Anuj Anand 2014-1-28
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by