- 'sqp' is not a valid algorithm for fminunc. Use optimoptions to help you set options correctly instead of optimset.
- Is your objective function a sum of squares? If so, you would get better results using lsqnonlin. If you decide to do that, change your objective to the vector of function values, not the sum of squares.
- The reason for the error is that your options indicate that you are returning the gradient and Hessian from your objective function, but your objective function does not return those things. Don't set the GradObj and Hessian options and you will not get that particular error. I am telling you this third because I believe that you should fix the other things first.
Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.
4 views (last 30 days)
Show older comments
I got this error message :
Error using MyCepMTMFun Too many output arguments. Error in fminunc (line 271)
[f,GRAD,HESS] = feval(funfcn{3},x,varargin{:});
Error in MES_call (line 20)
[X1,fval1]=fminunc(@MyCepMTMFun,Intial_Weight,options );
Caused by:
Failure in initial user-supplied objective function evaluation. FMINUNC
My function in a separate file :
function [F] = MyCepMTMFun(Alfa)
%Define different used parameter
K=3;% no of taper used
snr=-10;
N=250;% number of sample
freq=0.0100;
%Signal & its power
signal1= randn(1,N);
x=awgn(signal1,snr,'measured');
% generate Q & R_x & H_K in equation 21
q=linspace(exp(-2*pi*freq*i),exp(-2*pi*freq*(N-1)*i),(N-1));
q=[1 q];
Q=diag(q);
R_x=mean(x*x');
% generate taper window hk hL
seq_length = N;
W=0.02;
time_halfbandwidth = N*W;
num_seq = 2*(2)-1;
[dps_seq,lambda] = dpss(seq_length,time_halfbandwidth,num_seq);
hK=dps_seq(:,1:K);
Alfa1=Alfa(1,:);
hL=dps_seq(:,K:-1:1);
Alfa2=Alfa(2,:);
nfft=seq_length;% num of fourier transform point
% Compute the power of signal use different tpaer
x=x(:);
if N<=nfft
Pk=abs(fft(dps_seq(:,1:K).*x(:,ones(1,K)),nfft)).^2;
else %compute DFT on nfft evenly spaced samples around unit circle:
Pk=abs(czt(dps_seq(:,1:K).*x(:,ones(1,K)),nfft)).^2;
end
%get function MSE objective function to be optimized equation (21) (22)
%(23)
F=0;
for j=1:K
for l=1:K
Sx=sum(Pk(:,j));
Bais_Part=hK(:,j)'*ctranspose(Q)*R_x*Q*hK(:,j);
Varience_Part1=(hK(:,j)'*ctranspose(Q)*R_x*Q*hL(:,l)).^2;
Varience_part2=(hK(:,j)'*ctranspose(Q)*R_x*Q*hK(:,j)).^2;
F=F+(((Alfa1(j)*(Bais_Part)/Alfa1(j))-Sx)/(Alfa1(j)*(Bais_Part)/Alfa1(j))).^2+((Alfa1(j)*Alfa2(l)*(Varience_Part1))/Alfa1(j)*Alfa2(l))/(((Alfa1(j)).^2*(Varience_part2)/(Alfa1(j)).^2));
end
end
%%%%%%%%
and main script
%
Get the adaptive weighting from Mini MSE ;
%call Function
K=3;
% set the intial weight
seq_length = 250;
time_halfbandwidth = seq_length*0.02;
num_seq = 2*(time_halfbandwidth)-1;
[dps_seq,lambda] = dpss(seq_length,time_halfbandwidth,num_seq);
Intial_Weight1=[1/(lambda(1)),1/(lambda(2)),1/(lambda(3))];
Intial_Weight2=[1/(lambda(1)),1/(lambda(2)),1/(lambda(3))];
Intial_Weight=[Intial_Weight1;Intial_Weight2];
% set the algorithm to Quasi Newton
%options = optimset('Hessian','on'); % indicate gradient is provided
options = optimset('GradObj','on','Hessian','on','Algorithm','sqp','Display', 'off');
% Get the value of MSE after Mini see equation 21 22 23
[X1,fval1]=fminunc(@MyCepMTMFun,Intial_Weight,options );
0 Comments
Accepted Answer
Alan Weiss
on 22 Dec 2017
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!