Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.

4 views (last 30 days)
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 );

Accepted Answer

Alan Weiss
Alan Weiss on 22 Dec 2017
  • '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.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
heba silem
heba silem on 23 Dec 2017
Thanks for kind answer , for optimoptions can it work for Hessian Quasi-newton .
For square terms :No the objective includes only one square terms and the rest are normal shown in attached pictures .Is there any way to keep

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!