You are on page 1of 11

I.

Bước 1: chuẩn bị dữ liệu:

Với y2/y1:
I.1. 1 lớp ẩn:
I.1.1. Dùng tool trong Matlab:
nftool hoặc nnstart
Nhưng mà chỉ có mạng 1 lớp ẩn, ko thể thêm số lớp ẩn được. Vậy nên dùng code để tùy chỉnh
nhiều hơn.
I.1.2. Code:
input =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','1:4'); % tùy đường dẫn
y2y1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','5:5');
Ljy1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','6:6');

x = input;
t = y2y1sm;
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 1;
netA = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
netA.divideParam.trainRatio = 70/100;
netA.divideParam.valRatio = 15/100;
netA.divideParam.testRatio = 15/100;
% Train the Network
[netB,tr] = train(netA,x,t);
% Test the Network
y = netB(x); %Outputs of the neural network
e = gsubtract(t,y); %Generalized subtraction
performance = perform(netA,t,y); %Calculate network performance
% View the Network
view(netB);
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)
I.1.3. Diễn giải:

Mạng sử dụng là mạng Feed Forward Network (mạng truyền thẳng)

Hàm kích hoạt trong lớp ẩn: hàm sigmoid lưỡng cực
Hàm kích hoạt trong lớp ouput: hàm tuyến tính

146 bộ số liệu dùng làm Training data (75% trên tổng 210 bộ) (gồm 4 input và 1 output)
32 bộ số liệu dùng làm Validation data (gồm 4 input và 1 output dùng để kiểm trong trong
quá trình training)
32 bộ số liệu dùng làm Test data (gồm 4 input dùng để kiểm trong trong quá trình training)

Các trọng số và bias được máy khởi tạo ngẫu nhiên và tự động.

Thuật toán sử dụng: Levenberg-Marquardt (thường nhanh nhất khi so với Bayesian
regularization hay Scaled Conjugate Gradient)

Quá trình training sẽ dừng lại khi 1 trong 6 thông số bên dưới gặp target value.
- Epoch: lần lặp thứ mấy
- Performance: Sai số bình phương trung bình (mean squared error hay MSE hay loss
function)
- Gradient: độ dốc, độ dốc nhỏ là đang tiến đến local minima
- Mu: (chưa rõ)
- Validation checks: (chưa rõ)

I.1.4. Kết quả:


Bên trên là mạng 1 lớp ẩn có 1 nơ ron

Kết quả hồi quy nhận được rất tốt.


Tiếp theo thử với 1 lớp ẩn 5 nơ ron cũng ổn.

Tiếp theo thử với 1 lớp ẩn 10 nơ ron cũng ổn.


I.2. 2 lớp ẩn:
I.2.1. Code:
input =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','1:4');
y2y1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','5:5');
Ljy1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','6:6');
x = input;
t = y2y1sm;
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = [1 1];
netA = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
netA.divideParam.trainRatio = 70/100;
netA.divideParam.valRatio = 15/100;
netA.divideParam.testRatio = 15/100;
% Train the Network
[netB,tr] = train(netA,x,t);
% Test the Network
y = netB(x); %Outputs of the neural network
e = gsubtract(t,y); %Generalized subtraction
performance = perform(netA,t,y) %Calculate network performance
% View the Network
view(netB);
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)

(Code y hệt 1 lớp ẩn, chỉ khác dòng màu đỏ)


I.2.2. Kết quả:

Kết quả cho 2 lớp ẩn, số nơ ron lần lượt là 1 và 1.


Kết quả cho 2 lớp ẩn, số nơ ron lần lượt là 5 và 3.

II. Với Lj/y1:


II.1. 1 lớp ẩn:
II.1.1. Code:
input =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','1:4');
y2y1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','5:5');
Ljy1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','6:6');

x = input;
t = Ljy1sm;
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 1;
netA = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
netA.divideParam.trainRatio = 70/100;
netA.divideParam.valRatio = 15/100;
netA.divideParam.testRatio = 15/100;
% Train the Network
[netB,tr] = train(netA,x,t);
% Test the Network
y = netB(x); %Outputs of the neural network
e = gsubtract(t,y); %Generalized subtraction
performance = perform(netA,t,y) %Calculate network performance
% View the Network
view(netB);
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)

(Code y hệt y2/y1 1 lớp ẩn, chỉ khác dòng màu đỏ)
II.1.2. Kết quả:

1 lớp ẩn, 1 nơ ron.

1 lớp ẩn, 5 nơ ron, chưa được tốt lắm.


Vẫn là 1 lớp ẩn, 5 nơ ron, sau khi train lại thì đạt kết quả ổn hơn.

1 lớp ẩn, 10 nơ ron, kết quả lại ko ổn lắm.


II.2. 2 lớp ẩn:
input =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','1:4');
y2y1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','5:5');
Ljy1sm =xlsread('D:\C. Study\6.NCKH\AI\Data AI','Data','6:6');

x = input;
t = Ljy1sm;
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = [1 1];
netA = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
netA.divideParam.trainRatio = 70/100;
netA.divideParam.valRatio = 15/100;
netA.divideParam.testRatio = 15/100;
% Train the Network
[netB,tr] = train(netA,x,t);
% Test the Network
y = netB(x); %Outputs of the neural network
e = gsubtract(t,y); %Generalized subtraction
performance = perform(netA,t,y) %Calculate network performance
% View the Network
view(netB);
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)

(Code y hệt Lj/y1 2 lớp ẩn, chỉ khác dòng màu đỏ)
II.2.1. Kết quả:

2 lớp ẩn, số nơ ron lần lượt là: 1 và 1, kết quả tạm được
2 lớp ẩn, số nơ ron lần lượt là: 1 và 1, trong 1 lần training nào đó thì kết quả khá tệ

2 lớp ẩn, số nơ ron lần lượt là: 5 và 3, kết quả khá ổn


2 lớp ẩn, số nơ ron lần lượt là: 10 và 10, không tốt bằng 1-1 hay 5-3.

You might also like