FMINUNC : Failure in initial objective function evaluation.

11 views (last 30 days)
Hi,
I'm using FMINUNC for a school project, I'm trying to find the original signal of a filtered signal with noise. Here's my code :
Main code
x1=x_triang_signal();
h=h_gauss_function(15,15,[0:1:30]);
y_nb=conv(x1,h,'same');
y=adgnoise(y_nb,30);
x0=zeros(length(x1),1);
fxo=criteria(x0,h,y,0.01)
xsol=optimize(x0,h,y,0.01);
This creates a triangle signal, a gaussian filter, gives the filtered signal then adds gaussian noise (i'm sure about all these functions). Then optimize :
Optimize (that uses FMINUNC)
function [xsol] = optimize(x0,h,y,alpha)
options = optimoptions("fminunc");
options = optimoptions(options,'Display','iter','MaxFunctionEvaluations',1000,'StepTolerance',1e-10,'SpecifyObjectiveGradient',true,'CheckGradients',true);
% Run optimization solver
xsol = fminunc(@(x)criteria(x,h,y,alpha),x0,options);
end
Criteria (the function i want to optimize, only considering x)
function [result] = criteria(x,h,y,alpha)
result = norm(y-conv(h,x,'same'));
for index=1:(length(x)-1)
result = result + alpha * phi(x,index);
end
end
Phi (a non-linear function that can change)
function [result] = phi(signal,index)
result=abs(signal(index+1)-signal(index));
end
in the main code fx0 is 21.6754, however when running the main code i get :
Error using criteria
Too many output arguments.
Error in optimize>@(x)criteria(x,h,y,alpha) (line 9)
xsol = fminunc(@(x)criteria(x,h,y,alpha),x0,options);
Error in fminunc (line 313)
[f,GRAD] = feval(funfcn{3},x,varargin{:});
Error in optimize (line 9)
xsol = fminunc(@(x)criteria(x,h,y,alpha),x0,options);
Error in mainTP3 (line 11)
xsol=optimize(x0,h,y,0.01);
Caused by:
Failure in initial objective function evaluation. FMINUNC cannot continue.
Any help would be very appreciated !

Answers (0)

Community Treasure Hunt

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

Start Hunting!