clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
N = 100;
x = linspace(0, 1, N)';
t = x.^2 + unifrnd(-0.1, 0.1, N, 1);
x = [ones(size(x, 1),1) x];
% t = [1 1 1 -1 -1 -1];
feature_number = size(x,2);
w_hidden_node_number = 10;
w_output_node_number= 1; % regression problem
w_hidden = rand(feature_number + 1, w_hidden_node_number);
w_output = rand(w_hidden_node_number + 1, w_output_node_number);
w = rand(2, 1);
n = 0.05;
E = [];
for i = 1:500
i
y_hidden = tanh([ones(size(x, 1), 1) x] * w_hidden);
y_output = logsig([ones(size(y_hidden, 1), 1) y_hidden] * w_output);
y = y_output;
e = t - y;
% Backpropagation hidden layer
delta_w_output = ((e .*(y_output.*(1-y_output))) .* [ones(size(y_hidden, 1), 1) y_hidden]);
delta_w_hidden = (delta_w_output(:, 2:end) .* ((1-y_hidden.^2)))' * [ones(size(x, 1), 1) x];
w_output = w_output + n * sum(delta_w_output)';
w_hidden = w_hidden + n * delta_w_hidden';
E(i) = mse(e);
subplot(2, 1, 1)
plot(x(:, 2), t, '.b', x(:, 2), logsig([ones(N, 1) tanh([ones(N, 1) x] * w_hidden)] * w_output), 'r');
title('Actual vs. Prediction');
xlabel('x'); ylabel('y'); legend('Actual', 'Predicted');
subplot(2,1,2);
plot(E); title('Error vs. Iteration');
xlabel('Iteration (n)'); ylabel('MSE');
drawnow;
end
fpga和matlab
- 粉丝: 18w+
- 资源: 2643
最新资源
- MATLAB【面板】的语音滤波设计.zip
- MATLAB【面板】汉字语音识别.zip
- MATLAB【面板】汉字识别.zip
- MATLAB【面板】的运动行为检测.zip
- MATLAB【面板】火焰识别系统设计.zip
- MATLAB【面板】基于DWT+SVD结合傅里叶变换的数字图像水印水印系统.zip
- MATLAB【面板】火焰烟雾检测.zip
- MATLAB【面板】交通道路标识识别.zip
- MATLAB【面板】家居防火识别系统.zip
- MATLAB【面板】教室人数统计.zip
- MATLAB【面板】考勤系统设计.zip
- MATLAB【面板】金属表面缺陷分析.zip
- MATLAB【面板】口罩识别.zip
- slm 增材制造选区激光熔化SLM的粉床数值模拟 备注:资料一直在更新,不断完善,尽可能把所有的内容讲详细 1该模拟资料包含粉床建立部分(EDEM,和Gambit软件)以及模型模拟部分Flow
- MATLAB【面板】垃圾分类系统.zip
- MATLAB【面板】口罩检测.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈