Error while using newpnn for classification and then fminunc for optimization.

I am using newpnn for classification, where i have input vector X, target vector Tc and output vector Yc. I need to optimize the newpnn function by varying the spread value in it to get the maximum correct classifications.(newpnn is an inbuilt function and has spread in its code for output estimation). Here is the code i wrote for the same:
T=ind2vec(Tc);
net=newpnn(X,T,spread);
Y= net(X);
Yc=vec2ind(Y);
Penalty=@(spread, Tc)((Tc-Yc).^2);
out= Penalty(spread, Tc);
spread0= 1;
[spread, fval,exitflag,output]=fminunc(out,1);
On running the script, I am getting this error:
Error using optimfcnchk (line 288)
FUN must be a function, a valid string expression, or an inline function object.
Error in fminunc (line 240)
funfcn = optimfcnchk(FUN,'fminunc',length(varargin),funValCheck,gradflag,hessflag);
Error in join (line 20)
[spread, fval,exitflag,output]=fminunc(out,1);
Any help/guidance/suggestion would be appreciated.

2 Comments

by varying the spread value in it to get the maximum correct classifications.
You cannot use fminunc to optimize an integer-valued function. fminunc is designed for functions f(x) that vary continuously (and differentiably) as a function of a continuously varying vector x.
You are right, unless i use quasi-newton method with it(which does not need gradient value). I ended up using fminsearch for this problem. But the output was just a local minima and not global minima. I am looking into differential evolution now, any suggestions?

Answers (0)

This question is closed.

Asked:

on 18 Feb 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!