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

    function [Y,Xf,Af] = cal_Z_matrix_C(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 19-Apr-2015 15:13:35.
% 
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
% 
%   X = 1xTS cell, 1 inputs over TS timsteps
%   Each X{1,ts} = 2xQ matrix, input #1 at timestep ts.
% 
% and returns:
%   Y = 1xTS cell of 1 outputs over TS timesteps.
%   Each Y{1,ts} = 8xQ 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 = [0.5;700];
  x1_step1_gain = [0.571428571428571;0.00333333333333333];
  x1_step1_ymin = -1;
  
  % Layer 1
  b1 = [9.4918470312480139;-10.91304589100943;-8.5753665290322125;1.7065819939402758;-8.9076162111934938;-7.912992077372019;7.0285101930308436;3.7902913298441927;6.4095788235390732;-18.053461768124336;-8.8625288716638622;-4.2070158837143667;6.3838226294239293;4.2308850503020672;3.22022501018985;2.0042029009361557;3.8617786632513837;-7.4764916118677647;-1.0693023429992383;1.9448233059278865;-0.82136107624343568;3.6431521495000698;-2.9577799236297793;0.035796436541353012;0.45073377336726833;-1.5099404214594199;1.3545951322173999;0.33747213783478186;0.99289793210628807;1.7248775710946509;-0.96294258073421224;2.9936951921586759;9.0430120751930421;-3.5692490747151391;-1.7719225484432797;-3.4210391335043302;-4.1470170423121431;1.2019353557664987;5.4472092067686155;-4.2821241889859216;-6.3145779780204778;4.5467356681361828;3.2589217989592822;7.6589610019399617;-8.433662148557783;-3.6650823880483152;5.0008793871416577;6.9992836214284369;-2.5935306160348532;3.4963048965681263];
  IW1_1 = [-8.8489968259121383 -0.0034974096703081861;3.9694530690969332 -3.2841952248287631;7.9211717203499274 -0.35153431886954406;-2.1584375349449574 -0.027239401307152307;9.9780086318876346 -0.046983188186377409;5.101774701915291 6.2923182697962288;0.82770888644741791 -6.3117123080950783;-3.6742877162200256 -3.836971851387347;-7.2391129606868647 0.058517960206877939;23.589306210055707 -0.0040149337550034357;19.335622182207207 0.0300225869748851;4.2773325948374827 -4.4108820728560794;-9.7333997956708895 0.032091377396602165;-9.1515473834661361 0.020803450641342518;-4.9563448493858395 0.00031929892321318291;-3.8537607265339502 -2.3712826282679322;-1.8768311256708115 8.7541604747683905;16.35996651273619 0.009555180130972311;-0.021749008295195389 1.854335586790431;-10.083256214130833 8.3644902567278553e-05;4.3942678443108667 2.4928925111971885;-19.33165136395915 -0.013861039995291199;15.624453492426708 0.012021446219398421;-0.27117778985455671 -1.1659206072284574;3.8447113563216626 2.1848369060981097;4.2749255917417655 -0.011758811299763739;-6.2386676373898124 0.0056422850674159482;9.6263942782501015 -0.082726916582368845;7.6811512915959907 -4.3680919050194076;3.8882205779141255 7.4563864191879228;-0.41001278738184821 -1.1185024875244354;5.8771545836581947 -3.2723058098608697;30.100379760337646 0.04900262849226357;-0.50292621351840983 5.317112406148528;-4.3091327437997053 -2.4142134822087389;-2.0778797258512807 -6.9951380030293162;-6.7506360203797335 -3.9309019951233162;0.50128525415563285 0.3967685349906675;0.63955007321844792 -6.2044787188668922;-5.2017306853696752 -3.0070458122323234;-7.3569384437420107 4.292368626097006;9.7071365209199936 0.0977840532517118;1.4563134727974301 2.996901379498742;8.1148845959306897 -0.024077725238236279;-6.9737085503972231 4.4195730375263489;-2.9419675059117014 -1.7256243703282936;7.5254979249817548 0.10363483671727157;5.4747851468959627 3.4844335238831956;-0.44857800682946891 -1.6180997114138778;2.6893763991488577 0.19454640606092993];
  
  % Layer 2
  b2 = [-1.040686950640179;0.86494744320011618;-0.60097418479727938;-1.9979108346556209;0.75093947555371032;-1.9979106394081956;0.20857204807205637;1.0831778143446449];
  LW2_1 = [0.0082946235854937326 0.045540688998588187 0.0096240121675339445 0.051676896998895126 -0.012206926806563444 -0.0030775831273490914 -0.04858597966571182 0.0021819875203537009 -0.035974782217024298 0.0021780472161020137 0.00018862964861334744 -0.00087199036611937668 -0.015832499454044909 -0.020480477329193766 0.023246782943054333 0.0031471874155255546 -0.000612223664840943 -0.0087275177771297015 -0.0048989648258013227 -0.064920905227199774 -0.001637065662796227 -0.018809543277193086 -0.047326717078148201 -0.00047697133400514415 -0.0017574373735446836 0.028220165076414522 0.052266682658144256 0.0018768968278221371 0.0013633241452873359 0.00055975711575964799 0.02554551741843622 0.0042715405374119256 -0.0011932667605026599 0.0076322365938029301 -0.0010776303776262365 0.00070545429590857965 -0.00073162632174383132 0.046012113945325686 0.011352222430390246 -0.0031536783602721858 -0.0055064249008264371 -0.0029138803373377482 -0.0069887254689433255 -0.032583771420313275 -0.014649187223676575 -0.0098589378555468225 -0.011514212659551862 -0.00074191707191635268 0.015642443919614821 0.14650805139812551;-0.71778116626868393 -0.69690694994132751 -0.19424581971393468 0.056231981569235326 1.0193259964065837 0.00072592253488746412 -0.048587845277023242 -0.0017181800740853658 2.0048084229345817 -0.099634922377868196 -0.8725759248643481 0.0013680103009338681 1.0856898674009441 1.3025517462048239 -3.2033499651910966 -0.0024081852080135874 0.0001492192848355639 1.6676703626680203 0.12879422857241904 6.09256188180309 0.0010164650144834026 1.9376594712596928 4.575016444741407 -0.44611517911071047 0.00017083750907927208 -2.7041415101763211 -5.6382163172253374 -0.16461040847102817 -0.0015532009657758888 0.00022740564154746153 -1.0858114051320231 -0.0020677732570865033 0.018670538807807606 0.010901224185353718 -0.00093181649778262276 -0.00050215948913881979 -0.00059774300726496996 -3.5180399126654618 -0.020680699527175377 -0.0018403307143611501 0.00088071322552761436 0.027406850112134135 0.015611991200365315 0.040427691278637691 -7.491480298273851e-05 -0.022360821999404114 0.027388670092944864 -0.0017006667392078325 -1.393541023352971 -0.2917677565035392;-0.093441225632162006 -0.13487179849649666 -0.071762933866589509 0.63008334642256292 0.049355328093097332 -0.085197028702572647 -0.032107972811952594 0.047292890221293772 -0.13197711815776658 0.0073449999291562923 0.14096164491810517 0.0090468174099260432 -0.1138794669494069 0.026204640712886657 2.7176539931174435e-05 0.17183953643454047 -0.054813552890699217 -0.18705259521984557 -0.36596760768196152 0.27111795505477554 -0.045708244049756028 0.049529110079139398 0.250722865690921 -0.80633205567210375 -0.12532352634962451 0.46079113385751819 0.088130303397438312 0.028806905061872182 0.017037679247521132 -0.017057060019861008 0.30843881253406646 0.06602417848349118 -0.050117474035153937 0.13983262430110058 0.093772664528907868 -0.01489461799618351 -0.0012111287349705787 -0.39781858006259102 -0.057289517462052596 0.13887390210998685 -0.07589870327817165 0.0089493859399267604 0.1648274876178317 -0.3316879912838348 -0.19831689927979093 -0.13908230446721631 -0.23719423692462596 -0.28419489057623515 0.12535674466443369 0.59909576441681112;0.44027145954569508 0.69608293436836643 -0.053773017944017315 -1.6893938445010279 -0.45286571871181591 -0.0011505566839048076 0.0048266704215510284 0.001977641034741239 -0.56539877900528912 0.0078526425738834303 0.68192360766299731 0.00049406013504586853 -0.44364740222510296 -0.79718996118470964 1.7702421316532271 0.0074691262747589443 -8.6187137656257114e-05 -1.1369669288723068 -0.022055790510474682 -1.1136969919170034 -0.011369673378842735 -0.34910388376045282 -0.82400151928179433 0.073748772291643949 -0.026342492502561432 0.17563102427434299 1.0360222341988017 0.030980010341584291 -0.0013153590870842763 -0.00010735268305287369 0.16721400598068023 -0.0034241709243485767 0.013702658166765819 -0.0014233074589913349 0.036344885723830239 -0.00037225824546832691 0.014715101956405538 3.041277667335665 0.0036480415041264414 0.03297975284993538 0.0036137795360056302 0.025275453397459423 -0.00069657483648410414 0.052109814666234495 0.0040579765519755647 0.18010502531168798 0.055532097000301373 0.02405900865276743 0.086868276376270356 1.2306757461574618;-0.07299549856514076 0.9362889668380503 -0.059539804862272297 0.068902074402448513 0.28038869800216892 -0.16350438196072711 -0.020282855346869737 0.16155319666376639 0.30711184855052232 0.011219804970566296 -0.12609207959960897 0.0035921682652826875 0.077238362576490985 0.0046753658080618014 -0.23607725587597364 0.17388940704473357 0.0048240286837716714 0.15860552831630806 0.4397753089873242 0.020968267198528658 -0.10863400970206506 0.65595169210503546 1.0096057470269333 -0.22759265880966248 -0.20263949351133645 0.24067548660429533 0.50088228345143748 0.11171338058497629 0.024899359437206937 0.0060251295644800857 0.16782664415543841 0.069495719179048343 0.013772361310544511 -0.064012621408392187 0.10945890314590073 -0.059670403937243113 0.084235129297273753 -0.41809459207967159 -0.039249721438640375 0.094390877497403561 -0.077997069117378109 -0.026882107421405132 0.083609427786696555 -0.26470565205091812 -0.1581961828337223 0.28343365683379934 -0.050513297513222803 -0.14532840762593227 -0.54988459283316682 0.0043939785896299271;0.44027146001305384 0.69608313483636974 -0.053773017892658599 -1.6893938347335105 -0.45286573278809888 -0.0011505565117193189 0.0048266703667477475 0.0019776410736554962 -0.56539880117131536 0.0078526423304589414 0.68192362162722475 0.00049405985237720455 -0.44364740556147092 -0.79718997167984729 1.7702421393816723 0.007469126510272016 -8.6187152907909174e-05 -1.1369669487712828 -0.022055790630139484 -1.1136969988115504 -0.011369673315743106 -0.34910388688368904 -0.82400152581154995 0.073748771275956498 -0.026342492885690905 0.17563102502745923 1.0360222382084516 0.030980010675852956 -0.0013153590091205924 -0.00010735257677882527 0.16721400974149825 -0.003424170825221476 0.01370265817512722 -0.0014233074370604512 0.03634488584466454 -0.0003722585551940563 0.014715102091228628 3.0412776784726718 0.0036480415882980195 0.032979753035223824 0.0036137794510301162 0.025275453356166093 -0.00069657354095748456 0.052109814803895343 0.0040579764598301198 0.18010502670481859 0.055532096959040295 0.024059008702486871 0.086868277710635808 1.2306757444237735;-0.44925950385757263 -0.17563163748165667 0.21244776995653478 -0.348765330146452 -0.23419869776589072 -0.11463407960789836 -0.054031314148464689 0.052728340492815176 -0.021488250681890864 0.023974030984542614 0.026218337602068011 0.08588891785554785 0.04628862188597143 0.090118398342626652 -0.03873576766895092 0.19344402660284712 -0.0074516204408895548 -0.071114408070420049 0.0034846517493581689 0.44238578040783177 -0.038056749393423461 0.35216062253802016 0.52043456479592531 0.31149745535636536 -0.15792069015760379 0.2493123345279904 -0.3076102136218436 0.10369556993925307 -0.019165961573989372 -0.034611043809317794 -0.16374450348349351 -0.019036080983763522 0.07860742194745976 0.017772162307579654 0.10086937270896386 0.073917374281559714 0.048027237377092843 0.097687540504250311 0.016502535197834466 0.055539331960328057 0.029172960400695731 0.074594475162660462 -0.26337149685151273 0.056776459209775802 0.023556352289191142 0.25094014697908745 0.16235712456027504 0.037937365082596701 0.50840983550481866 0.86201225813979776;-0.52238993834404779 -0.28188373800470201 -0.15579483613373926 0.26137705347416723 0.92527528652819369 0.00089222506207428946 -0.050339335447650999 -0.0012247929371567549 1.5810801555411322 -0.01188024333227943 -0.57754819018465997 0.00010660115072176653 0.68630124156963035 1.2742696697688629 -1.8410567842842764 0.0017800136424480457 -0.00034175796414365309 1.1583769763027842 0.13693643901540187 0.56206592893703333 -0.0050485609852485682 0.32672755579175716 0.62357629623714272 -0.44923551725626348 -0.013357666773805043 0.24235004040036803 -0.27258473153071827 0.0023303072951079114 0.00072991311452240979 0.00020489780476042258 -1.1235245728043801 0.0021484804648301248 0.019632465850364312 0.011266851718706858 0.013983329952360605 0.00054398540947025174 0.0056738966409439137 -3.3013998725166904 -0.021392549284854536 0.0082820655868040965 -0.001633504407311174 0.02803174497134768 0.0086205773922809412 0.061711503311118972 -0.0010381171465032608 0.03282422688567331 0.038343217394613556 0.0092831749777124387 -1.3774542596952351 -0.40484051471694754];
  
  % Output 1
  y1_step1_ymin = -1;
  y1_step1_gain = [1.132609172099;0.0455931174453629;64.6045706053985;0.0605876988613239;64.6045706053985;0.0605876988613239;48.3206519808931;0.0456337408578504];
  y1_step1_xoffset = [0.03792181;-83.57067;0.001553968;-34.72928;0.001553968;-34.72928;0.03795082;-83.53369];
  
  % ===== 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