Sim function giving different answer

1 次查看(过去 30 天)
I have trained a neural network with XOR gate using nprtool. I want to export it into my .net application. I used d sim function to simulate the network and it produced the expected result. However, the sim function does not work outside matlab so i need to write out the weights so i can use in my dotnet application. I wrote this function and tested it in matlab. The problem is that the function does not return same result as when i use sim function in matlab. Please i need help!!!
function [ Result ] = TrainedXOR_net(input )
load C:\Users\Student\Desktop\my_MatlabFiles\SampleXOR_Net.mat
y1 = tansig(net.IW{1}* input + net.b{1});
Result = tansig(net.LW{2}* y1 + net.b{2});
end
  1 个评论
Greg Heath
Greg Heath 2016-9-17
编辑:Greg Heath 2016-9-17
It's a common mistake responsible for many posts in both the NEWSGROUP and ANSWERS.

请先登录,再进行评论。

采纳的回答

Omotayo Asiru
Omotayo Asiru 2016-9-17
I got it sorted. Just wanna post my solution so another person with same problem can sort it easily. It turns out that i needed to do some pre-processing on my input and post-processing on the result. With this code below,I now have same result as sim function.
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by