%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%% 导入数据
res = xlsread('数据集.xlsx');
%% 划分训练集和测试集%
P_train = res(1: 250, 1: 12)';
T_train = res(1: 250, 13)';
M = size(P_train, 2);
P_test = res(251: end, 1: 12)';
T_test = res(251: end, 13)';
N = size(P_test, 2);
%% 数据归一化
[p_train, ps_input] = mapminmax(P_train, 0, 1);
p_test = mapminmax('apply', P_test, ps_input);
t_train = ind2vec(T_train);
t_test = ind2vec(T_test );
%% 节点个数
inputnum = size(p_train, 1); % 输入层节点数
hiddennum = 15; % 隐藏层节点数
outputnum = size(t_train, 1); % 输出层节点数
%% 构建网络
net = newff(p_train, t_train, hiddennum);
%% 设置训练参数
net.trainParam.epochs = 100; % 训练次数
net.trainParam.goal = 1e-4; % 目标误差
net.trainParam.lr = 0.01; % 学习率
net.trainParam.showWindow = 0; % 关闭窗口
%% 麻雀参数设置
fun = @getObjValue; % 目标函数
dim = inputnum * hiddennum + hiddennum * outputnum + ...
hiddennum + outputnum; % 优化参数个数
智能算法及其模型预测