matlab神经网络训练批量大小

时间:2012-02-24 18:26:10

标签: matlab neural-network

我正在尝试使用不同的批量大小训练神经网络,但我不确定如何将所得到的网络合并在一起。

这是我编写的用于训练网络的代码,批量大小作为参数。

%% Train the Network using batches
batch_size = 50;

total_size = size(inputs,2);
batch_num = ceil(total_size / batch_size);

for i = 1:batch_num
    start_index = i + batch_size * (i - 1);
    end_index = batch_size + batch_size * (i - 1);

    if i == batch_num
        end_index = total_size;
    end

    [net,tr] = train(net,inputs(:,start_index:end_index), targets(:,start_index:end_index));
end

这是net和tr的结构

tr =

    trainFcn: 'traingdm'
  trainParam: [1x1 nnetParam]
  performFcn: 'mse'
performParam: [1x1 nnetParam]
    derivFcn: 'defaultderiv'
   divideFcn: 'dividerand'
  divideMode: 'sample'
 divideParam: [1x1 nnetParam]
    trainInd: [1x538 double]
      valInd: [1x115 double]
        ...

net =

Neural Network

          name: 'Pattern Recognition Neural Network'
    efficiency: .cacheDelayedInputs, .flattenTime,
                .memoryReduction
      userdata: (your custom info)

dimensions:

     numInputs: 1
     numLayers: 4
    numOutputs: 1
numInputDelays: 0
numLayerDelays: 0
 numFeedbackDelays: 0
 numWeightElements: 845
    sampleTime: 1

connections:

   biasConnect: [1; 1; 1; 1]
  inputConnect: [1; 0; 0; 0]
  layerConnect: [4x4 boolean]
 outputConnect: [0 0 0 1]

subobjects:

        inputs: {1x1 cell array of 1 input}
        layers: {4x1 cell array of 4 layers}
       outputs: {1x4 cell array of 1 output}
        biases: {4x1 cell array of 4 biases}
  inputWeights: {4x1 cell array of 1 weight}
  layerWeights: {4x4 cell array of 3 weights}
    ...

在所有批次完成后,如何获得生成的net变量来保存结果神经网络?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您将覆盖变量nettr。只需使用一个单元格数组:

使用以下内容在开头声明:

 net = {};
 tr = {};

并将相关行更改为:

 [net{end+1},tr{end+1}] = ...