2017-01-06 47 views
0

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

但我需要直接为输出图层传递第一个隐藏层的输出。我正在考虑改变第二个隐藏层的输出,以便它变得等于第一个隐藏层的输出。为此,我需要访问隐藏层输出的值。 我已经打开了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 

我发现那里的偏见和突触被更新,但我没能找到的地方神经元输出值被设置。有人能帮助我吗?

回答

0

您可以创建两个没有隐藏层的自定义网络,然后您可以使用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/

+0

谢谢!真的,我没有那样做过。但你的答案是有用的。在这篇文档中,关于如何选择哪些图层相互连接以及哪些图层与输入和输出连接起来进行了扩展。 –

相关问题