遗传算法的配置存在问题-MATLAB

时间:2019-04-10 06:43:36

标签: matlab optimization genetic-algorithm

我试图通过遗传算法找到进入NN中3个隐藏层的神经元的正确数目,从而给出整数值。 我的函数接受每层中神经元数量的参数,并输出该配置的RMSE。这是我要最小化的功能。

function output_rmse = CalculateBestConfiguration(NeuronsIn_HL_1,NeuronsIn_HL_2,NeuronsIn_HL_3)
%% Create Pipeline
trainer1 = MLP_pipeline;
%% Generate Data
[X_data , Y_data, q1_set, ~, ~,~,~,~,~] = PlotWorkspace(10,7,5);
[trainInd,testInd] = dividerand(length(q1_set),80,20);
%% Feed Training Data
trainer1.input_training = [X_data(trainInd);Y_data(trainInd)];
trainer1.output_training = q1_set(trainInd);
%% Train the Perceptron Model
trainer1.fit_MLP([NeuronsIn_HL_1,NeuronsIn_HL_2,NeuronsIn_HL_3],'trainbr');
trainer1.train_MLP()
%% Feed Test Data
trainer1.input_test = [X_data(testInd);Y_data(testInd)];
trainer1.output_test = q1_set(testInd);
%% Predict Results
theta_predicted1 = trainer1.predictor();
%% Evaluate Accuracy
error_values1 = trainer1.generate_error(theta_predicted1);
output_rmse = sqrt(mean(error_values1.^2));
end

我的GA配置出现问题。我找不到它。

opt = optimoptions('ga');
% opt.InitialPopulationMatrix = ones(30,3);
opt.MaxTime = 4*60*60;
opt.MigrationFraction = 1.0000e-06;
% opt.MutationFunction= 'mutationgaussian';
opt.PopulationSize = 30;
opt.FunctionTolerance = 1e-4;
opt.MaxGenerations = 500;
fun = @CalculateBestConfiguration;
IntCon = 1:3;
lb = [1,1,1];
ub = [21,21,21];
A = [3 3 3];
b = 180;
nvars = 3;
nonlcon = [];
Solution = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,opt);

这是错误:

Not enough input arguments.

Error in CalculateBestConfiguration (line 11)
trainer1.fit_MLP([NeuronsIn_HL_1,NeuronsIn_HL_2,NeuronsIn_HL_3],'trainbr');

Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});

Error in fcnvectorizer (line 13)
            y(i,:) = feval(fun,(pop(i,:)));

Error in gaminlppenaltyfcn

Error in gapenalty

Error in makeState (line 64)
            Score = FitnessFcn(state.Population(initScoreProvided+1:end,:));

Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);

Error in gapenalty

Error in gaminlp

Error in ga (line 393)
    [x,fval,exitFlag,output,population,scores] = gaminlp(FitnessFcn,nvars, ...

Error in untitled (line 18)
Solution = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,opt);

Caused by:
    Failure in user-supplied fitness function evaluation. GA cannot continue.
    Failure in initial user-supplied fitness function evaluation. GA cannot continue.

0 个答案:

没有答案