2016-09-17 73 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函数相同的结果。我希望这可以帮助别人......

相关问题