【问题标题】:How to access the values of the output of hidden layer neurons in MATLAB?如何在 MATLAB 中访问隐藏层神经元的输出值?
【发布时间】:2017-01-07 08:53:54
【问题描述】:

MATLAB 不允许在神经网络工具箱中使用多于一种类型的传递函数的层。所以,我想创建 2 个隐藏层,一个具有双曲正切传递函数,另一个具有 rbf 神经元。

但我需要将第一个隐藏层的输出直接传递给输出层。我正在考虑更改第二个隐藏层的输出,使其等于第一个隐藏层的输出。为此,我需要访问隐藏层的输出值。 我已经打开了traingd 函数,我想我想要的是这段代码的某些部分:

for epoch=0:param.epochs

    % Stopping Criteria
    if isMainWorker
        current_time = etime(clock,startTime);
        [userStop,userCancel] = nntraintool('check');
        if userStop, tr.stop = 'User stop.'; calcNet = best.net;
        elseif userCancel, tr.stop = 'User cancel.'; calcNet = original_net;
        elseif (perf <= param.goal), tr.stop = 'Performance goal met.'; calcNet = best.net;
        elseif (epoch == param.epochs), tr.stop = 'Maximum epoch reached.'; calcNet = best.net;
        elseif (current_time >= param.time), tr.stop = 'Maximum time elapsed.'; calcNet = best.net;
        elseif (gradient <= param.min_grad), tr.stop = 'Minimum gradient reached.'; calcNet = best.net;
        elseif (val_fail >= param.max_fail), tr.stop = 'Validation stop.'; calcNet = best.net;
        end

        % Training record & feedback
        tr = nntraining.tr_update(tr,[epoch current_time perf vperf tperf gradient val_fail]);
        statusValues = [epoch,current_time,best.perf,gradient,val_fail];
        nn_train_feedback('update',archNet,rawData,calcLib,calcNet,tr,status,statusValues);
        stop = ~isempty(tr.stop);
    end

    % Stop
    if isParallel, stop = labBroadcast(mainWorkerInd,stop); end
    if stop, return, end

    % Gradient Descent
    if isMainWorker
        dWB = param.lr * gWB;
        WB = WB + dWB;
    end

    calcNet = calcLib.setwb(calcNet,WB);
    [perf,vperf,tperf,gWB,gradient] = calcLib.perfsGrad(calcNet);

    % Validation
    if isMainWorker
        [best,tr,val_fail] = nntraining.validation(best,tr,val_fail,calcNet,perf,vperf,epoch);
    end
end

我找到了偏差和突触的更新位置,但我无法找到神经元输出值的设置位置。有人可以帮我吗?

【问题讨论】:

    标签: matlab neural-network


    【解决方案1】:

    您可以创建两个没有隐藏层的自定义网络,然后您可以使用 2 个不同的函数直接查看输出。参见文档https://www.mathworks.com/help/nnet/ug/create-and-train-custom-neural-network-architectures.html

    您也可以使用权重和偏差手动计算它们。

    input_weights = cell2mat(net.iw) // getting the input weights bias = net.b{1} //choosing the bias of the first layer hidden_layer1 = tanh(input*input_weights+repmat(bias,1,input_size)) //the dot product of the input and input_weights will give some matrix, hence why the bias must be the same size

    附带说明:我发现本教程有助于理解基本神经网络的工作原理 - https://iamtrask.github.io/2015/07/12/basic-python-network/

    【讨论】:

    • 谢谢!实际上,我还没有这样做。但是你的回答很有用。在本文档中,解释了如何选择哪些层相互连接以及哪些层与输入和输出连接。
    猜你喜欢
    • 2017-12-20
    • 2017-05-21
    • 1970-01-01
    • 2012-03-21
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2018-01-30
    相关资源
    最近更新 更多