gusucode.com > matlab编程遗传算法计算匹配电路源码程序 > code1/code/MATLAB源代码/cal_Z21_L.m

    function [Y,Xf,Af] = cal_Z21_L(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 19-Apr-2015 19:54:27.
% 
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
% 
%   X = 1xTS cell, 1 inputs over TS timsteps
%   Each X{1,ts} = 1xQ 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 = 700;
  x1_step1_gain = 0.00333333333333333;
  x1_step1_ymin = -1;
  
  % Layer 1
  b1 = [-17.678523720724392;-16.368328105808516;15.303601556733046;-11.468027124675464;10.48754202415088;10.223282352594309;8.1365649382562761;-8.5763664498349037;6.4770922300521212;3.7908267727539036;4.8694799538293259;-3.057981264105337;-3.4211504878891486;0.011511715768459394;0.42545337839662095;-0.43172595723470453;1.3068681154141877;1.5422022242357758;-1.5055534666500547;2.7743091242104811;-4.9586967749878559;6.7676297354268788;5.0528288690379153;7.6545559082277634;8.7977882505651444;3.2027871727553809;13.81414665740772;10.126732223615193;14.374873185708136;-23.073678216666451];
  IW1_1 = [17.213288383264711;16.954951850646101;-16.656183954818644;13.194362805438336;-13.011794259704027;-13.647761972557463;-11.817255898645483;13.675430465375364;-11.292256887419494;-7.6685887589589035;-12.194266368661301;9.3246004048721289;14.317613937743895;-1.4786821702336344;-12.93085703539691;-13.744071245485031;15.072639811213975;10.711102020924265;-5.8522008844550122;7.1389752325472582;-11.015650221656712;13.570157251141106;9.0203077461869405;12.008543774104572;12.646926271519401;3.8818203038368586;16.226378090152611;10.906194727365715;14.529960286782917;-22.338092759638755];
  
  % Layer 2
  b2 = [0.051043798546672917;-0.091939192411195803];
  LW2_1 = [-0.026312146816607818 -0.014284109364007765 0.0099594000561416783 -0.019764758255257479 0.015468911182284804 0.0097579766827034873 0.016249343058939238 -0.005197862661280985 0.0082355344156697721 0.020721951770197436 0.0018204527215372308 -0.0044609886120782925 -0.0010133886600223157 0.59858769499319353 0.00039941498177445411 -9.7247157793328899e-08 -0.00062382172649982166 -0.00087655114870048936 0.025930367992386748 -0.027172353731638992 0.0062858100381037287 -0.0022362886652066778 -0.023946359527468868 -0.0048925631848183342 -0.0030001801934181646 -0.26434573287726792 0.00012610012111507896 -0.015215488525780377 -0.017587432243909368 0.014474719364290444;0.01364265003525063 0.0078158317731146041 -0.0054483636243447065 0.011243446299982944 -0.0090147599157229079 -0.0058295502910175011 -0.0097637493107223614 0.0032221439049354961 -0.0049778347231697884 -0.012575756854001266 -0.00085114323479207614 0.0023478155024619497 0.0001375106196718265 -0.56797218039446018 -0.00044212195990999011 -0.00083794307847963106 0.00058099147366369463 0.0019045520107223517 -0.030574472710013397 0.030429229607428089 -0.0067519585545164785 0.0026075476501379699 0.025550103785527283 0.0049949110190154753 0.0025378706674766449 0.32862118281908637 0.00077536504700965103 0.026764576949575812 0.03014221219853503 -0.025711784938601882];
  
  % Output 1
  y1_step1_ymin = -1;
  y1_step1_gain = [25.4803751424672;0.0109757255366169];
  y1_step1_xoffset = [0.01789064;-437.9664];
  
  % ===== 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 = repmat(b2,1,Q) + LW2_1*a1;
    
    % Output 1
    Y{1,ts} = mapminmax_reverse(a2,y1_step1_gain,y1_step1_xoffset,y1_step1_ymin);
  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

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n)
  a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings_gain,settings_xoffset,settings_ymin)
  x = bsxfun(@minus,y,settings_ymin);
  x = bsxfun(@rdivide,x,settings_gain);
  x = bsxfun(@plus,x,settings_xoffset);
end