Error,, too many input arguments!!

function [x,fval] = yasmin
%% Fitness function (objective function) and number of variables
fitnessFcn = @(x) ga_test(x);
numberOfVariables = 1310;
A=[]; %% (2596x1310)
b=[]; %% (1310x1)
Aeq=[]; %% (20x220)
beq=[]; %% (220x1)
%% Decision variables are bounded (either zero or one)
LB = zeros(1,1310);
UB = ones(1,1310);
Bound = [LB;UB];
% Create an options structure to be passed to GA % Three options namely 'CreationFcn', 'MutationFcn', and % 'PopInitRange' are required part of the problem. %% Population size to be at least the value of Number of variables, so that %% the individuals in each population span the space being searched.
options = gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation, ... 'PopInitRange',Bound,'Display','iter','StallGenL',100,'Generations',150, ... 'PopulationSize',1310,'PlotFcns',{@gaplotbestf,@gaplotbestindiv});
[x,fval] = ga(fitnessFcn,numberOfVariables,A,b,Aeq,beq,LB,UB,[],options);
x
%%************************************************************************* %%*************************************************************************
% Mutation function to generate childrens satisfying the range and integer % constraints on decision variables.
function mutationChildren = int_mutation(parents,options,GenomeLength, ... FitnessFcn,state,thisScore,thisPopulation)
shrink = .01;
scale = 1;
scale = scale - shrink * scale * state.Generation/options.Generations;
range = options.PopInitRange;
lower = range(1,:);
upper = range(2,:);
scale = scale * (upper - lower);
mutationPop = length(parents);
% The use of ROUND function will make sure that childrens are integers.
mutationChildren = repmat(lower,mutationPop,1) + ... round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));
% End of mutation function
%%************************************************************************* %%*************************************************************************
function Population = int_pop(GenomeLength,FitnessFcn,options)
totalpopulation = sum(options.PopulationSize);
range = options.PopInitRange;
lower= range(1,:);
span = range(2,:) - lower;
% The use of ROUND function will make sure that individuals are integers.
Population = repmat(lower,totalpopulation,1) + ... round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
When I run my m-file from the command line I write: x=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options) OR [x,fval]=ga(@ga_test,1310,A,b,Aeq,beq,LB,UB,[],options)
and I get error using ga,, Too many input arguments
So I also tried : x=ga(yasmin) but I keep getting the same error.
Any help in this regard will be highly appreciated
Thanx in advance.

2 Kommentare

Atakan
Atakan am 28 Mär. 2011
just try yasmin on command window,it will work...
Yasmin Tamimi
Yasmin Tamimi am 28 Mär. 2011
Actually this is what I've done, but unfortunately it didn't work!!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Mär. 2011

1 Stimme

Which version are you using?
Please check
which -all ga
If you see anything other than an entry under the gads toolbox, you might have a conflicting function.

13 Kommentare

Yasmin Tamimi
Yasmin Tamimi am 28 Mär. 2011
I'm using R2007 and I've checked the ga function it consists of three input arguments only [ga(fittnessFunction, nVariables, options)]. I don't have R2010b so I tried to download a student version but I couldn't. At the university campus we have R2009b but without global optimization toolbox.
Any suggestions..
Walter Roberson
Walter Roberson am 28 Mär. 2011
Even R2007a accepted all of the arguments you provided, according to the documentation, http://www.mathworks.com/help/releases/R2007a/toolbox/gads/ga.html
Yasmin Tamimi
Yasmin Tamimi am 28 Mär. 2011
But when I opened doc ga in the "Reference page in Help browser" I got:
Syntax
x = ga(fitnessfun, nvars)
x = ga(fitnessfun, nvars, options)
x = ga(problem)
[x, fval] = ga(...)
[x, fval, reason] = ga(...)
[x, fval, reason, output] = ga(...)
[x, fval, reason, output, population] = ga(...)
[x, fval, reason, output, population, scores] = ga(...)
So the max # arguments that I can input is 3.
[I don't have a license so I can't open the link u have posted.]
What did u mean by "If you see anything other than an entry under the gads toolbox, you might have a conflicting function." ? Did u mean when I open the toolboxes tab at the start menu??
Thanx in advance.
Walter Roberson
Walter Roberson am 28 Mär. 2011
At the command line,
which -all ga
Does it report one ga.m file in a subdirectory toolbox/gads or does it report multiple files?
Please clarify as to whether you are using 2007a or 2007b ?
I don't think you need a license to open the link I specified, but you might need to have a user community account. And maybe a license too, I'm not sure. The 2007a reference page that is online at Mathworks says,
ga
Find minimum of function using genetic algorithm
Syntax
x = ga(fitnessfcn,nvars)
x = ga(fitnessfcn,nvars,A,b)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options)
x = ga(problem)
[x, fval] = ga(...)
[x, fval, exitflag] = ga(...)
It is not impossible that the wrong documentation is being presented online.
Yasmin Tamimi
Yasmin Tamimi am 29 Mär. 2011
I really don't know, the version that I have is (matlab 7) it's without a or b. I removed it bcz I plan to download matlab R2010a, I found one of my friends using it so I tried my example and I had no errors with the input arguments but I had an error with GenomeLength. I read doc ga where GenomeLength is defined as the number of independent variables in the fitness function so I wrote it as 30 but I still have the error which states that matlab expected something else!!
Walter Roberson
Walter Roberson am 29 Mär. 2011
A copy of the error would help us.
I am not familiar with the workings of ga(), but it appears likely to me that your GenomeLength would be 1310 rather than 30.
You have used far too many "magic numbers" in your ga_test() function. Why 220 instead of 221 or 234 or 262 ? and so on. No-one is going to understand the reason those numbers were picked when they examine your code.
Yasmin Tamimi
Yasmin Tamimi am 29 Mär. 2011
When I read the manual of matlab R2010a GenomeLength is defined as the number of independent variables in the fitness function (I use 30 variables in my fitness function), but in the following link it is defined as number of variables which is 1310 (I've tried both 1310 & 30 but I still get the error). http://www.mathworks.com/support/solutions/en/data/1-1C90Z/index.html?product=GD&solution=1-1C90Z
In ga_test() function I have only 30 variables from x(1) till x(30)others are zeros. As for the inequalities and equalities they depend on the number of variables I'm using in my problem (from x(1) till x(1310)); (this is the updated version of my matrices dimensions):
A(2596X1310)*X(1310X1) <= b(2596X1); (A*X <= b)
A(20X1310)*X(1310X1) <= b(20X1); (A*X = b) (i.e I have 20 equality contraints which consists of 1310 variables)
My errors appear in this part of the code:
% Mutation function to generate childrens satisfying the range and integer % constraints on decision variables.
function mutationChildren = int_mutation(parents,options,GenomeLength, ... FitnessFcn,state,thisScore,thisPopulation)
shrink = .01;
scale = 1;
scale = scale - shrink * scale * state.Generation/options.Generations;
range = options.PopInitRange;
lower = range(1,:);
upper = range(2,:);
scale = scale * (upper - lower);
mutationPop = length(parents);
% The use of ROUND function will make sure that childrens are integers.
mutationChildren = repmat(lower,mutationPop,1) + ... round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));
% End of mutation function
%%************************************************************************* %%*************************************************************************
function Population = int_pop(GenomeLength,FitnessFcn,options)
totalpopulation = sum(options.PopulationSize);
range = options.PopInitRange;
lower= range(1,:);
span = range(2,:) - lower;
% The use of ROUND function will make sure that individuals are integers.
Population = repmat(lower,totalpopulation,1) + ... round(repmat(span,totalpopulation,1) .* rand(totalpopulation,GenomeLength));
% End of creation function
Walter Roberson
Walter Roberson am 29 Mär. 2011
I do not have that toolbox so I cannot run the code. A copy of the exact error message would help.
Yasmin Tamimi
Yasmin Tamimi am 29 Mär. 2011
??? Error: File: yasmin.m Line: 2959 Column: 58
Unexpected MATLAB expression.
Yasmin Tamimi
Yasmin Tamimi am 29 Mär. 2011
At it occurs where I write 1310 or 30 for the GenomeLength..
Walter Roberson
Walter Roberson am 29 Mär. 2011
I cannot tell from here what your code is at that line. This is, though, an error that would show up in mlint, so if you use the matlab editor to look at that file, look for the red marks on the right-hand side of the editor and click on them to be positioned to the line that has the syntax error.
Walter Roberson
Walter Roberson am 29 Mär. 2011
Are you trying to put in a numeric value for GenomeLength in a 'function' line? That isn't allowed. If you must, for some reason, override the value you are passing in (something that is more often a mistake than not) then use an assignment after the 'function' line, such as
GenomeLength = 1310;
Yasmin Tamimi
Yasmin Tamimi am 29 Mär. 2011
Yes, that was my error. I've been using numeric values in a function line!! I run my example for both GenomeLength = 1310 which was wrong and the correct was for GenomeLength = 30 (#variables in the fitness function only)as defined in the reference manual.
Thank u very much for ur help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by