给matlab的feedforwardnet创建更多的隐藏层以及添加激活层函数。

1,你可以先查看这种网络的参数,用help,doc是不行的,我提供一种其他方法,在命令窗口键入net = feedforwardnet(1) 就可以得到下面的信息,有关net的权值以及各种参数,大多都可以通过net.调用,如net.b就是调用偏置。

net =
    Neural Network

              name: 'Feed-Forward Neural Network'
          userdata: (your custom info)

    dimensions:
         numInputs: 1
         numLayers: 2
        numOutputs: 1
    numInputDelays: 0
    numLayerDelays: 0
 numFeedbackDelays: 0
 numWeightElements: 1
        sampleTime: 1

    connections:
       biasConnect: [1; 1]
      inputConnect: [1; 0]
      layerConnect: [0 0; 1 0]
     outputConnect: [0 1]

    subobjects:
             input: Equivalent to inputs{1}
            output: Equivalent to outputs{2}

            inputs: {1x1 cell array of 1 input}
            layers: {2x1 cell array of 2 layers}
           outputs: {1x2 cell array of 1 output}
            biases: {2x1 cell array of 2 biases}
      inputWeights: {2x1 cell array of 1 weight}
      layerWeights: {2x2 cell array of 1 weight}

    functions:
          adaptFcn: 'adaptwb'
        adaptParam: (none)
          derivFcn: 'defaultderiv'
         divideFcn: 'dividerand'
       divideParam: .trainRatio, .valRatio, .testRatio
        divideMode: 'sample'
           initFcn: 'initlay'
        performFcn: 'mse'
      performParam: .regularization, .normalization
          plotFcns: {'plotperform', plottrainstate, ploterrhist,
                    plotregression}
        plotParams: {1x4 cell array of 4 params}
          trainFcn: 'trainlm'
        trainParam: .showWindow, .showCommandLine, .show, .epochs,
                    .time, .goal, .min_grad, .max_fail, .mu, .mu_dec,
                    .mu_inc, .mu_max

    weight and bias values:
                IW: {2x1 cell} containing 1 input weight matrix
                LW: {2x2 cell} containing 1 layer weight matrix
                 b: {2x1 cell} containing 2 bias vectors

    methods:
             adapt: Learn while in continuous use
         configure: Configure inputs & outputs
            gensim: Generate Simulink model
              init: Initialize weights & biases
           perform: Calculate performance
               sim: Evaluate network outputs given inputs
             train: Train network with examples
              view: View diagram
       unconfigure: Unconfigure inputs & outputs
    evaluate:       outputs = net(inputs)

2,创建更多的隐藏层以及添加激活层函数

% load data
load data.mat;
load target.mat;
x = data;
t = target;
trainFcn = 'trainbr';  % Bayesian Regularization
% Create a Feedforward Network
hiddenLayerSize = 18;
net = feedforwardnet (hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1)); % to get constant result
net.divideFcn = 'divideblock'; % Divide targets into three sets using blocks of indices
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
%TRAINING PARAMETERS
net.trainParam.show=50;  % of ephocs in display
net.trainParam.lr=0.05;  % learning rate
net.trainParam.epochs=10000;  % max epochs
net.trainParam.goal=0.05^2;  % training goal
net.performFcn='mse';  % Name of a network performance function %type help nnperformance
net.numLayers = 3;  % 创建更多的隐藏层以及添加激活层函数
net.layerConnect(3,2) = 1;
net.outputConnect = [0 0 1];
net.layers{2}.size = 8;
net.layers{2}.transferFcn = 'tansig';
net.outputs{3}.range = [1 20];
% Train the Network
[net,tr] = train(net,x,t); 
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)

你可能感兴趣的:(matlab)