zoukankan      html  css  js  c++  java
  • BP实现函数拟合

    %%
    clc;
    clear all;
    close all;
    
    %% 生成正弦曲线
    x = linspace(-2*pi, 2*pi, 100);
    y = sin(x);
    % 对目标值加入噪声
    n = 0.1 * rand(1, length(x));
    y = y + n;
    
    % figure();
    % plot(x, y, 'b-');
    
    %% 数据归一化,创建测试数据集
    [x_, ps] = mapminmax(x);
    data_input = x_;
    data_target = y;
    
    % figure();
    % plot(data_input, data_target, 'b-');
    
    data_test = linspace(-5, 5, 50);
    data_true = sin(data_test);
    data_t = mapminmax('apply', data_test, ps);
    
    % figure();
    % plot(data_t, data_true, 'b-');
    
    %% 创建神经网络(也可打开nntool,在matlab中使用gui创建神经网络)
    hidden_layer_size = 10;
    net = feedforwardnet(hidden_layer_size);
    [net, tr] = train(net, data_input, data_target);
    
    %% 拟合结果
    data_y = sim(net, data_t);
    % data_y = net(data_t);
    figure();
    e = 0.5 * (data_true - data_y) .^ 2;
    plot(e);
    xlabel('x axis');
    ylabel('y axis');
    legend('error');
    
    figure();
    hold on;
    plot(data_test, data_y, '*');
    plot(x, y, 'b');
    xlabel('x axis');
    ylabel('y axis');
    legend('prediction', 'real value');
    
    这篇文章,是又一个故事的结束...
    lazy's story is continuing.
  • 相关阅读:
    Python 函数 之 目录
    python---------匿名函数
    python-------递归函数
    python-----内置函数
    hibernate.cfg.xml
    struts2 工作原理
    拦截器
    js制作 子菜单
    struts---最简单实例步骤
    常用标签---地址----
  • 原文地址:https://www.cnblogs.com/Hello-world-hello-lazy/p/15216926.html
Copyright © 2011-2022 走看看