Скачиваний:
5
Добавлен:
08.04.2022
Размер:
1.23 Кб
Скачать
%% Clear all
clc
clear
close all

%% Data processing, splitting
num = xlsread('ts1.xlsx','Лист1');
n=600;
i = randperm(n);
x = num(i,:);
y = num(i,:);

trainX = x(1:fix(1*n),:);
trainY = y(1:fix(1*n),:);
testX = x(fix(0.8*n)+1:end,:);
testY = y(fix(0.8*n)+1:end,:);

X = tonndata(trainX,false,false);
Y = tonndata(trainY,false,false);
testX = tonndata(testX,false,false);
testY = tonndata(testY,false,false);
inputSeries = X;
targetSeries = Y;

% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:3;
feedbackDelays = 1:3;
hiddenLayerSize = 2;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);

%% Prepare the Data for Training and Simulation
[inputs,inputStates,layerStates,targets] = ...
preparets(net,inputSeries,{},targetSeries);

%% Set up Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 10/100;
net.divideParam.testRatio =10/100;

%% Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates);

%% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);
Соседние файлы в папке Лаба 5