我试图找到这个函数的最小值。但是当我运行脚本时收到以下错误。我究竟做错了什么:
% pre allocating
x=zeros(10,4);
mu=zeros(10,1);% process parameter
T=zeros(10,1);% spike times
y=zeros(10,1);%number of spikes
eta=zeros(10,1);% linear predictor
for i=1:10 % on trials
for j=1:4 % on pixels
x(i,j)=randi(2,1)-1;
end
mu(i)=randi(20,1)/100;
[T,y(i)]=ppsample(mu(i),20);
eta(i)=log(mu(i));
syms b0;syms b1;syms b2;syms b3;syms b4;syms objfun;
o(i)=((b0+b1*x(i,1)+b2*x(i,2)+b3*x(i,3)+b4*x(i,4))*y(i))-exp(b0+b1*x(i,1)+b2*x(i,2)+b3*x(i,3)+b4*x(i,4));
end
%%finding optimum weights
objfun=sum(o);
ofun= matlabFunction(objfun);
x0 = ones(1,5);
[x,fval] = fminunc(ofun,x0);
这给出了以下内容:
Error using makeFhandle/@(b0,b1,b2,b3,b4)b0.*1.9e1+b1.*9.0+b2.*1.2e1+b3.*7.0+b4.*7.0-exp(b0+b1+b2+b3)-exp(b0+b2+b3+b4)-exp(b0+b1).*2.0-exp(b0+b2)-exp(b0)-exp(b0+b1+b2)-exp(b0+b1+b3)-exp(b0+b2+b4)-exp(b0+b3+b4)
Not enough input arguments.
Error in fminunc (line 254)
f = feval(funfcn{3},x,varargin{:});
Error in GLM (line 30)
[x,fval] = fminunc(ofun,x0);
Caused by:
Failure in initial user-supplied objective function evaluation.
FMINUNC cannot continue.