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

조회 수: 1 (최근 30일)
Kang Wang
Kang Wang 2011년 3월 23일
답변: Ruslan Dautkhanov 2015년 3월 16일
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
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일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ruslan Dautkhanov
Ruslan Dautkhanov 2015년 3월 16일

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by