函数逼近的深信念网络

时间:2018-01-03 05:54:18

标签: matlab machine-learning dbn function-approximation

我使用Masayuki Tanaka开发的深度神经网络工具箱,链接https://www.mathworks.com/matlabcentral/fileexchange/42853-deep-neural-network

现在我尝试使用深度置信网络来进行函数逼近。但结果并不是很好。以下是我的脚本代码。有没有人能够找出哪些部分可以修改以改善拟合结果?

%% Environment Settings
clear all;
close all;
clc;

rng(42);

addpath DBNLib

%% Define function to be learned and generate test and training data
num_points = 1000;

lower_bound = -2*pi;
upper_bound = 2*pi;
X_all = (upper_bound-lower_bound).*rand(num_points, 1) + lower_bound;
Y_all = cos(X_all) + 0.1*randn(num_points, 1);
Y_all = Y_all;

train_split = 0.8;
train_size  = train_split*num_points;
X_train = X_all(1:train_size);
Y_train = Y_all(1:train_size);
X_test  = X_all(train_size+1:end);
Y_test  = Y_all(train_size+1:end);

% Plot train and test data
scatter(X_train, Y_train, 'g', 'filled'),hold on
scatter(X_test, Y_test, 'r', 'filled'), grid minor
drawnow;

%% Construct deep belif network model
nodes = [1 64 64 1];
dnn = randDBN( nodes , 'GBDBN' );
nrbm = numel(dnn.rbm);

opts.MaxIter = 200;
opts.BatchSize = train_size/8;
opts.Verbose = true;
opts.StepRatio = 0.01;
opts.DropOutRate = 0.5;
opts.Object = 'Squares';

% opts.Layer = nrbm-1;
dnn = pretrainDBN(dnn, X_train, opts);
dnn= SetLinearMapping(dnn, X_train, Y_train);

opts.Layer = 0;
dnn = trainDBN(dnn, X_train, Y_train, opts);
rmse = CalcRmse(dnn, X_train, Y_train);
rmse

estimate = v2h( dnn, X_all);
scatter(X_all, estimate, 'b', 'filled')
legend('train', 'test', 'DBN Fit')

DBN学习结果:

The DBN learning result

1 个答案:

答案 0 :(得分:0)

您是否有可能扩展您的输入和目标以培训您的网络,并且您在输出时忘记了预测的缩放?