• Matlab神经网络工具箱学习之一


    1、神经网络设计的流程

    2、神经网络设计四个层次

    3、神经网络模型

    4、神经网络结构

    5、创建神经网络对象

    6、配置神经网络的输入输出

    7、理解神经网络工具箱的数据结构

    8、神经网络训练

    1、神经网络设计的流程

      神经网络设计可以分为七个步骤:

        a. 采集数据

        b. 创建网络

        c. 配置网络参数

        d. 初始化权重和偏置

        e. 训练神经网络

        f. 验证网络

        g. 使用网络

    2、神经网络设计四个层次

      这里的层次主要只Matlab的神经网络工具箱和相关命令

        a. 第一层是“Getting Started with Neural Network Toolbox”里面提到的GUI,可以方便、快速的解决拟合、模式识      别、聚类、时序分析等问题。

        b. 第二层是使用命令行输入。

        c. 第三层是工具箱的个性化配置,根据需求选择参数。

        d. 第四层是自己修改.M文件,以适应需要解决的问题。

    3、神经网络模型

      基本神经元

        神经网络的最基本结构是神经元。下图是单个神经元的图示。一个神经元包含了输入p,此输入的权重w,外加偏置b,这  三项元素组成了转移方程f的输入,经过f的计算,得到输出a。网络的权重方程通常是取w和p的乘积,有时也使用|w-p|(参  见help nnweight)。网络的输入方程n一般是各项wp的累加和,有时也用乘积(参见help nnnetinput)。

        神经网络的训练目的就是迭代计算,每次调整w和b的值,使得网络的输出结果和目标结果的误差最小。

        

      转移方程

        常用的转移方程有两种,线性转移方程和Log-sigmoid转移方程。前一种多用于网络最后一层(输出层),而后者多用  于网络的中间层(参见help nntransfer)。

        

      神经元的向量输入

        通常每个节点的输入p会是一个多维(N维)的向量,所以每个节点的权重也是N维的向量w,偏置b还是一个常数。转移  方程的输入就可以写为n = w*p + b,n仍旧是一个标量。

         

    4、神经网络结构

      神经网络按照结构可以分为单层网络和多层网络,每一层网络又可以包含多个节点(神经元),最后构成一个完整的模型。

      一层网络

        下图是一层网络的模型图,输入有R个元素,每个元素Pr是一个向量。中间层有S个节点(神经元),Wsr表示第S个节  点对第r个输入的权重。bs表示第s个节点的偏置。权重W就变成了一个SxR的矩阵。P是RxN的矩阵,b是一个S维的向量。

      

      多层网络

        多层网络类似于是多级运算放大电路,把多个一层网络串联。每一层都有一个权重矩阵W和偏置向量b。上一层的输出作为下一层的输入。

      

      

    5、创建神经网络对象

      创建一个简单的网络模型可以用feedforwardnet( )函数

      net = feedforwardnet

      这时会显示很多的模型参数。dimensions表示整个网络的结构。connections保存网络各节点之间的连接状态,0表示没有连接,1表示有连接。layerConnect矩阵是各个网络层之间的连接,行表示目标层,列表示源层。

      关键的几个参数是inputs, layers, outputs, biases, inputWeights and layerWeights.

    6、配置神经网络的输入输出

      网络的输入输出配置可以用configure()函数。

      net1 = configure(net, input, target_output);

    %% an example of BP network

    load data input output

    % shuffle index
    k = rand(1,2000);
    [m,n] = sort(k);

    % prepare for training data 1900 out of 2000
    input_train=input(n(1:1900),:)';
    output_train=output(n(1:1900));
    % prepare for test data 100 out of 2000
    input_test=input(n(1901:2000),:)';
    output_test=output(n(1901:2000));

    % normalize training and test data to [-1, 1]
    [inputn,inputps]=mapminmax(input_train);
    [outputn,outputps]=mapminmax(output_train);

    % initial NN model and set parameters
    net=newff(inputn,outputn,5);
    net.trainParam.epochs=100; % iteration times
    net.trainParam.lr=0.1; % learning rate
    net.trainParam.goal=0.00004;
    net=train(net,inputn,outputn);

    % normalize test data
    inputn_test=mapminmax('apply',input_test,inputps);
    % predict output
    an=sim(net,inputn_test);
    % de-normalize test data
    BPoutput=mapminmax('reverse',an,outputps);


    % plot predict output
    figure(1)
    plot(BPoutput,':og')
    hold on
    plot(output_test,'-*');
    legend('test output','expected output')
    title('BP neural network test output','fontsize',12)
    ylabel('output','fontsize',12)
    xlabel('sample','fontsize',12)

    % plot errors
    error=BPoutput-output_test;
    figure(2)
    plot(error,'-*')
    title('BP neural network error','fontsize',12)
    ylabel('error','fontsize',12)
    xlabel('samole','fontsize',12)

  • 相关阅读:
    virtualBox下面安装linux系统如何共享目录
    PHP中spl_autoload_register()函数
    PHP 5.5 新特性
    useradd密码无效
    Linux audit安全审计工具
    Javascript class获取回调函数数据
    RPi 3B 无线连接配置
    Refused to execute inline event handler because it violates the following Content Security Policy directive: "xxx". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...')
    options.html:1 Refused to load the script 'xxxx' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".
    jQuery.Deferred exception: $.get is not a function TypeError: $.get is not a function
  • 原文地址:https://www.cnblogs.com/naive/p/3570571.html
Copyright © 2020-2023  润新知