[help] Error using ==> fmincon Too many input arguments

When I run a simulation of local constant cross validation for multivariables, I encountered the problem of too many input arguments.
function cv_m = lccvm(z,xc,xd,b,n) sum1 = 0 for i = 1:n dxc = (xc-xc(i,1))/(z(1)*n^(-1/5)) kc=exp(-0.5*dxc.^2); % continous kernel l=(xd==xd(i,1))+z(2)*(xd~=xd(i,1)); % discrete kernel k=kc.*l; % mixed kernel k(i,0)=0; % leave-one-out gx1=sum(b.*k)/sum(k); sum1=sum1+(b(i,1)-gx1)^2 end cv_m = 1/n*sum1;
and the bounds of z are z(1) from 0 to 20 z(2) from 0 to 1 there is no other constraint.

4 件のコメント

Sarah Wait Zaranek
Sarah Wait Zaranek 2011 年 3 月 23 日
Is lccvm your objective function for fmincon?
Kang Wang
Kang Wang 2011 年 3 月 24 日
yes it is. I also have a file for running loops.
Kang Wang
Kang Wang 2011 年 3 月 24 日
here is the fmincon file:
clear all;
close all;
n = 25;
loop = 100;
alpha = 1;
beta = 0.1;
gamma = 0.01;
for looop = 1:loop
xd = unidrnd(2,n,1)-1;
xc = randn(n,1);
u = randn(n,1);
y = alpha + beta*xd + gamma*xc + u;
z0 = [0.5;0.5];
lb = [0;0]
ub = [20;1]
[z(looop:1), cv(looop,1)]=fmincon(@lccvm,z0,lb,ub,@cons);
end
Walter Roberson
Walter Roberson 2011 年 3 月 24 日
Refer to my Answer: it is exactly what is going on in your situation.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 24 日

0 投票

The objective function cannot accept that many variables directly. Please see the documentation of how to pass extra parameters.

1 件のコメント

Kang Wang
Kang Wang 2011 年 3 月 24 日
Thanks for your help. The problem is not solved yet. I tried to minimize the objective function by choosing z=[z1;z2]. When I tried to choose a scaler z = z to minimize the function, it worked by running [z_star(looop,1), lccv(looop,1)]=fminbnd(@(z) lccvm(z,xd,xc,y,n),0.1,2). Then I went back the original problem, I wrote code like the following:
(1)The cross validation file:
clear all;
close all;
n = 25;
loop = 100;
alpha = 1;
beta = 0.1;
gamma = 0.01;
for looop = 1:loop
xd = unidrnd(2,n,1)-1;
xc = randn(n,1);
u = randn(n,1);
y = alpha + beta*xd + gamma*xc + u;
z0 = [0.5;0.5];
lb = [0;0];
ub = [20;1];
lccv = @(z)lccvm(xc,xd,z,y,n); %Anonymous Function?
[z_star(looop,1), lccv(looop,1)]=fmincon(lccv,z0,[],[],[],[],lb,ub);
end
(2) the function file
function cv_m = lccvm(c,d,e,b,N)
sum1 = 0;
for i = 1:N
dxc = (c-c(i,1))/(e(1)*N^(-1/5));
kc=exp(-0.5*dxc.^2); % continous kernel
l=(d==d(i,1))+e(2)*(d~=d(i,1)); % discrete kernel
k=kc.*l; % mixed kernel
k(i,1)=0; % leave-one-out
gx1=sum(b.*k)/sum(k);
sum1=sum1+(b(i,1)-gx1)^2;
end
cv_m = 1/N*sum1;
I hope that you can show me the details about my problem. Sincerely.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by