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

2 Ansichten (letzte 30 Tage)
Kang Wang
Kang Wang am 23 Mär. 2011
Beantwortet: Ruslan Dautkhanov am 16 Mär. 2015
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 Kommentare
Kang Wang
Kang Wang am 24 Mär. 2011
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 am 24 Mär. 2011
Refer to my Answer: it is exactly what is going on in your situation.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Mär. 2011
The objective function cannot accept that many variables directly. Please see the documentation of how to pass extra parameters.
  1 Kommentar
Kang Wang
Kang Wang am 24 Mär. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Ruslan Dautkhanov
Ruslan Dautkhanov am 16 Mär. 2015

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by