【问题标题】:matlab Sim function giving different answermatlab Sim函数给出不同的答案
【发布时间】:2017-01-25 06:47:33
【问题描述】:
我已经使用 nprtool 训练了一个带有 XOR 门的神经网络。我想将它导出到我的 .net 应用程序中。我使用 d sim 函数来模拟网络,它产生了预期的结果。但是,sim 函数在 matlab 之外不起作用,所以我需要写出权重,以便在我的 dotnet 应用程序中使用。我写了这个函数并在matlab中测试了它。问题是该函数返回的结果与我在 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
【问题讨论】:
标签:
matlab
neural-network
【解决方案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 函数相同的结果。我希望这对某人有所帮助...