Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.
Afficher commentaires plus anciens
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 );
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!