我想使用多层感知器近似一个简单的抛物线。我已经看到了用于fitnet()的代码,但它对我没有意义。
根据我的理解,我给MLP提供了有限数量的输入来描述这个功能,它应该找出其余的点。
但我如何训练和策划前后。
编辑:这就是我要找的: https://www.youtube.com/watch?v=BCo2c2NJLSk&list=WLNHDPIzWjvUezymNTss-7lw
代码:
clc, clear all
% Data for a continous function
%[x, t] = simplefit_dataset;
x = -10:10;
t = x.^2;
net = fitnet();
%[net, tr] = train(NETWORK, NETWORK INPUTS, NETWORK TARGETS)
% [net, tr] net: new network. tr: training record
net = train(net, x, t);
view(net)
y = net(x);
%Plots
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
perf = perform(net,y,t)
答案 0 :(得分:1)
试试这个:
clc, clear all
% Generate data and visualize via plot
x = -10:.1:10;
t = x.^2;
plot(x,t);
% Define a NN object, net, and initialize it
% net = newff(min_max_values, [size1 size2 ... sizeNlayer], {activation_func_types, ...}, training_algo );
% Using trainlm = Levenberg-Marquardt optimization (choose any)
net = newff([-10 10], [10, 1], {'tansig', 'purelin'}, 'trainlm');
% Train the network (find the best network parameters to fit the data) and store it as net1
net1 = train(net, x, t);
% Simulate the result and the error
a = sim(net1, x);
% Plot the result and the error
plot(x,a-t,x,t,x,a);
希望它有所帮助。