2016-09-17 71 views
-2

我已經用nprtool訓練了帶有XOR門的神經網絡。我想將它導出到我的.net應用程序中。我用d sim函數來模擬網絡,併產生了預期的結果。但是,sim函數不能在matlab之外工作,所以我需要寫出權重,以便在我的dotnet應用程序中使用。我寫了這個函數,並在MATLAB中測試它。問題是函數不會返回與我在matlab中使用sim函數時相同的結果。請我需要幫助!matlab Sim函數給出不同的答案

function [ Result ] = TrainedXOR_net(input) 
load C:\Users\Student\Desktop\my_MatlabFiles\SampleXOR_Net.mat 
y1 = tansig(net.IW{1}* input + net.b{1}); 
Resut = tansig(net.LW{2}* y1 + net.b{2}); 
end 

回答

1

我把它排序。只是想發佈我的解決方案,讓另一個有相同問題的人可以輕鬆地排序。事實證明,我需要對輸入進行一些預處理,並對輸出進行後處理。

function [ Result ] = TrainedXOR_net(inputs) 
%This is just to load the pre-trained network from the location i saved it. 
load C:\Users\Student\Desktop\my_MatlabFiles\SampleXOR_Net.mat 
for iii = 1:numel(net.inputs{1}.processFcns) 

inputs = feval(net.inputs{1}.processFcns{iii}, 'apply', inputs,    net.inputs{1}.processSettings{iii}); 
end 
y1 = tansig(net.IW{1}* inputs + net.b{1}); 
Result = tansig(net.LW{2}* y1 + net.b{2}); 
for iii = 1:numel(net.outputs{2}.processFcns) 
Result = feval(net.outputs{2}.processFcns{iii},'reverse', Result,  net.outputs{2}.processSettings{iii}); 
end 

有了這段代碼,我現在有了與sim函數相同的結果。我希望這可以幫助別人......

相關問題