Pulling Weights from Formula

2 views (last 30 days)
Conor O' Sullivan
Conor O' Sullivan on 15 Dec 2014
Commented: Sean de Wolski on 15 Dec 2014
Hi all,
I created a relatively simple ANN using the pattern recognition wizard. 34 inputs, 2 outputs.
After creating the function, I wanted to pull the weights out to be used elsewhere (in an app), however I'm having some difficulty telling which numbers are the input weights, as well as the bias weight.
I've attached a word doc with the formula on it.
At first glance, I thought it might be the numbers next to x1_step1_xoffset or x1_step1_gain, however I'm doubtful they are them, as there's no negative numbers, and that would mean a positive result for any inputs whatsoever.
Anyway. I'd really really appreciate if anyone could shed some light on this for me.
Thank you,
Conor.

Answers (1)

Conor O' Sullivan
Conor O' Sullivan on 15 Dec 2014
It's strange - when I try to attach, nothing happens. Here it is...
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~) %MYNEURALNETWORKFUNCTION neural network simulation function. % % Generated by Neural Network Toolbox function genFunction, 12-Dec-2014 11:13:20. % % [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments: % % X = 1xTS cell, 1 inputs over TS timsteps % Each X{1,ts} = 34xQ matrix, input #1 at timestep ts. % % and returns: % Y = 1xTS cell of 1 outputs over TS timesteps. % Each Y{1,ts} = 2xQ matrix, output #1 at timestep ts. % % where Q is number of samples (or series) and TS is the number of timesteps.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1_xoffset = [17;34.3;84;40;45;8;84;0;0;0;0;0;35.1;87;37;41;9;87;0;0;0;0;0;35.1;81;35;47;9;87;0;0;0;0;0];
x1_step1_gain = [0.0298507462686567;0.307692307692308;0.0165289256198347;0.0285714285714286;0.027027027027027;0.105263157894737;0.125;2;2;2;2;2;0.408163265306123;0.0175438596491228;0.0263157894736842;0.028169014084507;0.133333333333333;0.153846153846154;2;2;2;2;2;0.425531914893617;0.0170940170940171;0.0240963855421687;0.0289855072463768;0.133333333333333;0.153846153846154;2;2;2;2;2];
x1_step1_ymin = -1;
% Layer 1
b1 = [1.6250159514304179;-0.76711617733625925;-0.087218477528884508;0.40218675522789599;1.5211715966196837];
IW1_1 = [-0.38334115088528592 0.073963977730160127 -0.21414592394085583 -0.1811023968674037 0.091457347558877411 0.26824792001744951 0.021515159445345867 0.16630488521234027 -0.31905356103014426 -0.028778051081310534 -0.2610524619567397 -0.3434506446145123 0.16255364446948642 0.46055087720622129 -0.52569637417996107 0.45356034166127779 0.41586228437989214 -0.042260852265273173 -0.09176126520559684 -0.1292117090529282 0.25370301418322144 -0.25521448463169621 0.22813842425566599 0.24812859798817519 0.33548716094810332 -0.28903101248327934 0.055823057258466077 0.20678256900006523 0.043714833424586721 0.25493727155065277 -0.2918105439897527 -0.085587139057542394 -0.026755880218446271 -0.19839458157068623;0.32344354450384089 -0.09722083870675273 -0.12141348409292725 -0.32147456751550335 0.22741347963361769 0.1866661505925552 0.11671432999224259 -0.1681892036000277 -0.079265244168909677 -0.32189673098914423 0.38782220143236523 -0.19557839247970041 0.10938064072960328 0.39493287272386546 -0.0070560903078537972 0.00061630728116105643 -0.20244959649453365 0.12395735927038111 -0.27396595888505826 0.35967072432173774 -0.40672023335160373 -0.039297405457635499 -0.24197601565354673 0.12517596889387095 0.0072890728100467317 -0.37274684201549374 0.46153169969114205 0.43040882407081466 -0.23395449789009468 0.35014673186737821 0.22531067965118223 0.2039204924730427 0.32189400477883445 0.17574148614037716;0.37476823932855202 0.11546669070368759 -0.42697958849517431 0.37463824728233669 0.18896936958088195 0.18544399738331774 -0.24707432492048281 -0.14104343087345794 0.12039635523989081 -0.26811616928246862 -0.13714994187791346 0.1999153343688525 0.066702891015596913 -0.1114256124701714 0.24349747505739053 -0.47482937127109714 -0.098103068685359104 0.2239529977248696 0.15363276001393569 -0.43615374081600777 0.27832482830345162 -0.13105214924599379 -0.087276269867450129 0.054836915925883564 -0.024874332288534421 -0.29015612700153071 0.40160084637794946 -0.21470551372720156 -0.12159309441070532 -0.22832695745345441 -0.4741872924427582 0.08010709366869595 -0.12709093111244582 0.36973518415031015;0.18370111112308748 -0.018898782741535738 -0.48518797982129946 0.38648694294404684 -0.35100960771497802 -0.13781366771574438 -0.20754819759285012 0.12883639256758114 0.5096664764071992 -0.024212741044357323 0.45052745554552653 0.20260353505680173 0.47228314972972085 -0.34187486274036016 0.65191151536123138 -0.50321162996530389 -0.47193644592037315 0.26423323011376681 -0.31612891144088717 0.37866202787421471 0.22892170749421537 0.36945359561830132 -0.11177925687789467 -0.14752554476440816 -0.50825852362040347 0.0013933572455434493 -0.59226035482801154 -0.68984679923098535 -0.4409676452727902 -0.23466028046389656 -0.00023069342390445073 0.14214091518537009 0.21732570202574586 -0.24084528223913657;0.16571676271596661 0.13496850985285166 0.5982752252872986 -0.53636450066464503 0.088728474732586174 0.067374497216185589 -0.18814899439421282 0.028559716948879071 0.19647378796700193 0.31069581039541155 -0.057785511053139595 -0.13580853602313606 -0.1574384402155081 0.12647300669219222 -0.50482015438014249 0.019589015246901886 0.29072712428189929 -0.038576615831027672 0.39003184476433883 -0.60246372479815968 0.19095848627343623 0.11064184137492346 -0.23926198257121573 0.28050298494740183 0.073503327329885154 -0.24521682276840695 0.47001328880601101 0.56538944455039464 -0.31120507963454896 -0.16173890361698254 -0.53568779513983777 -0.22691962213757588 0.017885878591252548 0.45929927005692966];
% Layer 2
b2 = [0.34791196117051243;0.032467720714978811];
LW2_1 = [0.79123446312813106 0.15350419751995401 0.11860830937971768 -0.59086739902228547 1.1296572286543383;-0.26622584110498199 -0.38821952149850331 -0.4888920545843492 1.247665944011028 -0.25135813450004862];
% ===== SIMULATION ========
% Format Input Arguments
isCellX = iscell(X);
if ~isCellX, X = {X}; end;
% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
Q = size(X{1},2); % samples/series
else
Q = 0;
end
% Allocate Outputs
Y = cell(1,TS);
% Time loop
for ts=1:TS
% Input 1
Xp1 = mapminmax_apply(X{1,ts},x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
% Layer 2
a2 = softmax_apply(repmat(b2,1,Q) + LW2_1*a1);
% Output 1
Y{1,ts} = a2;
end
% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);
% Format Output Arguments
if ~isCellX, Y = cell2mat(Y); end
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function function y = mapminmax_apply(x,settings_gain,settings_xoffset,settings_ymin) y = bsxfun(@minus,x,settings_xoffset); y = bsxfun(@times,y,settings_gain); y = bsxfun(@plus,y,settings_ymin); end
% Competitive Soft Transfer Function function a = softmax_apply(n) nmax = max(n,[],1); n = bsxfun(@minus,n,nmax); numer = exp(n); denom = sum(numer,1); denom(denom == 0) = 1; a = bsxfun(@rdivide,numer,denom); end
% Sigmoid Symmetric Transfer Function function a = tansig_apply(n) a = 2 ./ (1 + exp(-2*n)) - 1; end
  1 Comment
Sean de Wolski
Sean de Wolski on 15 Dec 2014
It's weird, you have to select the file, it will show up in the edit box and you then have to hit "attach". This happens to me all of the time.

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!