⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gensim.m

📁 RBF网络逼近、RBF-建模、RBF网络训练与测试程序
💻 M
📖 第 1 页 / 共 2 页
字号:
    add_block(netInputBlock,netInputNameL,...
      'inputs',num2str(numSignals),...
      'position',[240 y-dy 260 y+dy],...
      'BackgroundColor','lightblue')
  else
    % Special case: numSignals == 1
    % netInputBlocks fail when there is only 1 signal,
    % summing across neurons instead of across signals.
    add_block('built-in/Gain',netInputNameL,...
      'gain','1',...
      'position',[240 y-dy 260 y+dy],...
      'BackgroundColor','lightblue')
  end

%======================================================================
function genLayerBias(net,i,pos,layerNameL,bName)

    add_block('built-in/Constant',[layerNameL '/' bName],...
      'value',mat2str(net.b{i},100),...
      'position',[160 pos*40 200 pos*40+20],...
      'maskdisplay','disp(''bias'')',...
    'BackgroundColor','lightblue')
    
%======================================================================
function genInputSignal(net,i,j,pos,layerNameL,PName,st)

  % Input Signal
  add_block('built-in/Inport',[layerNameL '/' PName],...
    'port',sprintf('%g',pos),...
  'portwidth',num2str(net.inputs{j}.size),...
  'sampletime',st,...
    'position',[40 pos*40 60 pos*40+20],...
  'BackgroundColor','Magenta')

%======================================================================
function genInputDelays(net,i,j,pos,layerNameL,IDName,st)

  % System
  name = IDName;
  nameL = [layerNameL '/' name];
  add_block('built-in/SubSystem',nameL)
  set_param(nameL,...
  'position',[100 pos*40 120 pos*40+20],...
    'maskdisplay','disp(''TDL'')',...
  'BackgroundColor','lightblue');

  % Constants
  delays = net.inputWeights{i,j}.delays;
  numDelays = length(delays);
  maxDelay = delays(end);
  
  % Names
  PName = sprintf('p{%g}',i);
  for k=1:maxDelay
    DName{k} = sprintf('Delay %g',k);
  end
  MuxName = 'mux';
  PDName = sprintf('pd{%g,%g}',i,j);
  
  % Blocks
  y = numDelays*20;
  add_block('built-in/Inport',[nameL '/' PName],...
    'port',sprintf('%g',1),...
  'portwidth',num2str(net.inputs{j}.size),...
  'sampletime',st,...
    'position',[60 40 80 60],...
  'Orientation','down',...
  'NamePlacement','alternate',...
  'BackgroundColor','Magenta')
  for k=1:maxDelay
    add_block('built-in/UnitDelay',[nameL '/' DName{k}],...
    'SampleTime',st,...
    'position',[60 40+k*40 80 60+k*40],...
    'BackgroundColor','lightblue',...
    'Orientation','down',...
    'NamePlacement','alternate')
  end
  add_block('built-in/Mux',[nameL '/' MuxName],...
    'inputs',num2str(numDelays),...
    'position',[200 40+y 240 60+y],...
  'BackgroundColor','lightblue')
  add_block('built-in/Outport',[nameL '/' PDName],...
    'port','1',...
    'position',[300 40+y 320 60+y],...
  'BackgroundColor','Magenta')
  
  % Connections
  for k=1:maxDelay
    if k == 1
    add_line(nameL,[PName '/1'],[DName{k} '/1'])
  else
    add_line(nameL,[DName{k-1} '/1'],[DName{k} '/1'])
  end
  end
  for k=1:numDelays
    if delays(k) == 0
    add_line(nameL,[PName '/1'],[MuxName '/' num2str(k)])
  else
    add_line(nameL,[DName{delays(k)} '/1'],[MuxName '/' num2str(k)])
  end
  end
  add_line(nameL,[MuxName '/1'],[PDName '/1'])

%======================================================================
function genInputWeight(net,i,j,pos,layerNameL,IWName,st)

  % System
  weightName = IWName;
  weightNameL = [layerNameL '/' weightName];
  add_block('built-in/SubSystem',weightNameL)
  set_param(weightNameL,...
  'position',[160 pos*40 200 pos*40+20],...
    'maskdisplay','disp(''weight'')',...
  'BackgroundColor','lightblue');

  % Names
  for k=1:net.layers{i}.size
    weightVectorName{k} = sprintf('IW{%g,%g}(%g,:)''',i,j,k);
    vectorOpName{k} = [net.inputWeights{i,j}.weightFcn num2str(k)];
  end
  muxName = 'Mux';
  outputName = ['iz{' num2str(i) ',' num2str(j) '}'];
  PName = sprintf('pd{%g,%g}',i,j);
  
  % Blocks
  y = net.layers{i}.size * 30 + 40;
  add_block('built-in/Inport',[weightNameL '/' PName],...
    'port',sprintf('%g',1),...
  'portwidth',num2str(net.inputWeights{i,j}.size(2)),...
  'sampletime',st,...
    'position',[40 y-10 60 y+10],...
  'BackgroundColor','Magenta')

  for k=1:net.layers{i}.size
    nameL = [weightNameL '/' vectorOpName{k}];
    block = ['neural/Weight Functions/' net.inputWeights{i,j}.weightFcn];
    add_block(block,nameL,...
      'position',[240 40+(k-1)*60 260 80+(k-1)*60],...
      'BackgroundColor','lightblue')
    
    add_block('built-in/Constant',[weightNameL '/' weightVectorName{k}],...
      'value',mat2str(net.IW{i,j}(k,:)',100),...
      'position',[140 40+(k-1)*60 180 60+(k-1)*60],...
      'maskdisplay','disp(''weights'')',...
    'BackgroundColor','lightblue')
  end

  add_block('built-in/Mux',[weightNameL '/' muxName],...
  'inputs',num2str(net.layers{i}.size),...
    'position',[340 y-10 380 y+10])

  outputNameL = [weightNameL '/' outputName];
  add_block('built-in/Outport',outputNameL,...
    'port','1',...
    'position',[420 y-10 440 y+10],...
  'BackgroundColor','Magenta')
  
  % Connections
  for k=1:net.layers{i}.size
    add_line(weightNameL,[weightVectorName{k} '/1'],[vectorOpName{k} '/1'])
    add_line(weightNameL,[PName '/1'],[vectorOpName{k} '/2'])
    add_line(weightNameL,[vectorOpName{k} '/1'],[muxName '/' num2str(k)])
  end
  add_line(weightNameL,[muxName '/1'],[outputName '/1'])

%======================================================================
function genLayerSignal(net,i,j,pos,layerNameL,AName,st)

  % Layer Signal
  add_block('built-in/Inport',[layerNameL '/' AName],...
    'port',sprintf('%g',pos),...
  'portwidth',num2str(net.layers{j}.size),...
  'sampletime',st,...
    'position',[40 pos*40 60 pos*40+20],...
  'BackgroundColor','Magenta')
 
%======================================================================
function genLayerDelays(net,i,j,pos,layerNameL,LDName,st)

  % System
  name = LDName;
  nameL = [layerNameL '/' name];
  add_block('built-in/SubSystem',nameL)
  set_param(nameL,...
  'position',[100 pos*40 120 pos*40+20],...
    'maskdisplay','disp(''TDL'')',...
  'BackgroundColor','lightblue');

  % Constants
  delays = net.layerWeights{i,j}.delays;
  numDelays = length(delays);
  maxDelay = delays(end);
  
  % Names
  PName = sprintf('p{%g}',i);
  for k=1:maxDelay
    DName{k} = sprintf('Delay %g',k);
  end
  MuxName = 'mux';
  ADName = sprintf('pd{%g,%g}',i,j);
  
  % Blocks
  y = numDelays*20;
  add_block('built-in/Inport',[nameL '/' PName],...
    'port',sprintf('%g',1),...
  'portwidth',num2str(net.layers{j}.size),...
  'sampletime',st,...
    'position',[60 40 80 60],...
  'Orientation','down',...
  'NamePlacement','alternate',...
  'BackgroundColor','Magenta')
  for k=1:maxDelay
    add_block('built-in/UnitDelay',[nameL '/' DName{k}],...
    'SampleTime',st,...
    'position',[60 40+k*40 80 60+k*40],...
    'BackgroundColor','lightblue',...
    'Orientation','down',...
    'NamePlacement','alternate')
  end
  add_block('built-in/Mux',[nameL '/' MuxName],...
    'inputs',num2str(numDelays),...
    'position',[200 40+y 240 60+y],...
  'BackgroundColor','lightblue')
  add_block('built-in/Outport',[nameL '/' ADName],...
    'port','1',...
    'position',[300 40+y 320 60+y],...
  'BackgroundColor','Magenta')
  
  % Connections
  for k=1:maxDelay
    if k == 1
    add_line(nameL,[PName '/1'],[DName{k} '/1'])
  else
    add_line(nameL,[DName{k-1} '/1'],[DName{k} '/1'])
  end
  end
  for k=1:numDelays
    if delays(k) == 0
    add_line(nameL,[PName '/1'],[MuxName '/' num2str(k)])
  else
    add_line(nameL,[DName{delays(k)} '/1'],[MuxName '/' num2str(k)])
  end
  end
  add_line(nameL,[MuxName '/1'],[ADName '/1'])

%======================================================================
function genLayerWeight(net,i,j,pos,layerNameL,LWName,st)

  % System
  weightName = LWName;
  weightNameL = [layerNameL '/' weightName];
  add_block('built-in/SubSystem',weightNameL)
  set_param(weightNameL,...
  'position',[160 pos*40 200 pos*40+20],...
    'maskdisplay','disp(''weight'')',...
  'BackgroundColor','lightblue');

  % Names
  for k=1:net.layers{i}.size
    weightVectorName{k} = sprintf('IW{%g,%g}(%g,:)''',i,j,k);
    vectorOpName{k} = [net.layerWeights{i,j}.weightFcn num2str(k)];
  end
  muxName = 'Mux';
  outputName = ['lz{' num2str(i) ',' num2str(j) '}'];
  AName = sprintf('ad{%g,%g}',i,j);
  
  % Blocks
  y = net.layers{i}.size * 30 + 40;
  add_block('built-in/Inport',[weightNameL '/' AName],...
    'port',sprintf('%g',1),...
  'portwidth',num2str(net.layerWeights{i,j}.size(2)),...
  'sampletime',st,...
    'position',[40 y-10 60 y+10],...
  'BackgroundColor','Magenta')

  for k=1:net.layers{i}.size
    nameL = [weightNameL '/' vectorOpName{k}];
    block = ['neural/Weight Functions/' net.layerWeights{i,j}.weightFcn];
    add_block(block,nameL,...
      'position',[240 40+(k-1)*60 260 80+(k-1)*60],...
      'BackgroundColor','lightblue')
    
    add_block('built-in/Constant',[weightNameL '/' weightVectorName{k}],...
      'value',mat2str(net.LW{i,j}(k,:)',100),...
      'position',[140 40+(k-1)*60 180 60+(k-1)*60],...
      'maskdisplay','disp(''weights'')',...
    'BackgroundColor','lightblue')
  end

  add_block('built-in/Mux',[weightNameL '/' muxName],...
  'inputs',num2str(net.layers{i}.size),...
    'position',[340 y-10 380 y+10])

  outputNameL = [weightNameL '/' outputName];
  add_block('built-in/Outport',outputNameL,...
    'port','1',...
    'position',[420 y-10 440 y+10],...
  'BackgroundColor','Magenta')
  
  % Connections
  for k=1:net.layers{i}.size
    add_line(weightNameL,[weightVectorName{k} '/1'],[vectorOpName{k} '/1'])
    add_line(weightNameL,[AName '/1'],[vectorOpName{k} '/2'])
    add_line(weightNameL,[vectorOpName{k} '/1'],[muxName '/' num2str(k)])
  end
  add_line(weightNameL,[muxName '/1'],[outputName '/1'])

%======================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -