OpenCores
URL https://opencores.org/ocsvn/artificial_neural_network/artificial_neural_network/trunk

Subversion Repositories artificial_neural_network

[/] [artificial_neural_network/] [trunk/] [test_bench/] [octave/] [wb_gen.m] - Diff between revs 8 and 12

Only display areas with differences | Details | Blame | View Log

Rev 8 Rev 12
function wb_gen(NET)
function wb_gen(NET)
 
 
[wbMat NLayers] = getwbc(NET);
[wbMat NLayers] = getwbc(NET);
MaxNeuronCnt = max_dim(wbMat);
MaxNeuronCnt = max_dim(wbMat);
 
 
fileid = fopen ('wb_init.vhd','w');
fileid = fopen ('wb_init.vhd','w');
 
 
% addr weights:
% addr weights:
% |_ _|  |0|  |_ _ _ _ _| |_ _ _ _ _ _|
% |_ _|  |0|  |_ _ _ _ _| |_ _ _ _ _ _|
% layer  bias    neuron      input
% layer  bias    neuron      input
% *2^12+  0   + *2^5    +   *2^0
% *2^12+  0   + *2^5    +   *2^0
% addr biases:
% addr biases:
% |_ _|  |1|  |0 0 0 0 0 0| |_ _ _ _ _|
% |_ _|  |1|  |0 0 0 0 0 0| |_ _ _ _ _|
% layer  bias                 neuron
% layer  bias                 neuron
% *2^12+ 2^11 +     0      +   *2^0
% *2^12+ 2^11 +     0      +   *2^0
 
 
fprintf(fileid,'library ieee;\n');
fprintf(fileid,'library ieee;\n');
fprintf(fileid,'use ieee.std_logic_1164.all;\n');
fprintf(fileid,'use ieee.std_logic_1164.all;\n');
fprintf(fileid,'use ieee.numeric_std.all;\n');
fprintf(fileid,'use ieee.numeric_std.all;\n');
fprintf(fileid,'library work;\n');
fprintf(fileid,'library work;\n');
fprintf(fileid,'use work.support_pkg.all;\n');
fprintf(fileid,'use work.support_pkg.all;\n');
fprintf(fileid,'use work.layers_pkg.all;\n');
fprintf(fileid,'use work.layers_pkg.all;\n');
fprintf(fileid,'package wb_init is\n');
fprintf(fileid,'package wb_init is\n');
 
 
fprintf(fileid,'  type ramd_type is array (%i downto 0) of std_logic_vector(NbitW-1 downto 0);\n',MaxNeuronCnt);
fprintf(fileid,'  type ramd_type is array (%i downto 0) of std_logic_vector(NbitW-1 downto 0);\n',MaxNeuronCnt);
fprintf(fileid,'  type layer_ram is array (%i downto 0) of ramd_type;\n',MaxNeuronCnt);
fprintf(fileid,'  type layer_ram is array (%i downto 0) of ramd_type;\n',MaxNeuronCnt);
fprintf(fileid,'  type w_ram  is array (integer range <>) of layer_ram;\n');
fprintf(fileid,'  type w_ram  is array (integer range <>) of layer_ram;\n');
fprintf(fileid,'  type b_type is array (integer range <>) of ramd_type;\n');
fprintf(fileid,'  type b_type is array (integer range <>) of ramd_type;\n');
 
 
fprintf(fileid,'  constant w_init : w_ram :=\n');
fprintf(fileid,'  constant w_init : w_ram :=\n');
fprintf(fileid,'  (\n');
fprintf(fileid,'  (\n');
for(k=1:NLayers)
for(k=1:NLayers)
  fprintf(fileid,'    %i => (\n',k-1);
  fprintf(fileid,'    %i => (\n',k-1);
  for(i=1:size(cell2mat(wbMat(k,1)),2))  % neurons
  for(i=1:size(cell2mat(wbMat(k,1)),2))  % neurons
    fprintf(fileid,'      %i => (\n',i-1);
    fprintf(fileid,'      %i => (\n',i-1);
    for(j=1:size(cell2mat(wbMat(k,1)),1))    % inputs
    for(j=1:size(cell2mat(wbMat(k,1)),1))    % inputs
      fprintf(fileid,'        %i => real2stdlv(NbitW,%1.4f)',j-1, cell2mat(wbMat(k,1))(j,i));
      fprintf(fileid,'        %i => real2stdlv(NbitW,%1.4f)',j-1, cell2mat(wbMat(k,1))(j,i));
      if j != size(cell2mat(wbMat(k,1)),1)
      if j ~= size(cell2mat(wbMat(k,1)),1)
        fprintf(fileid,',\n');
        fprintf(fileid,',\n');
      else
      else
        fprintf(fileid,',\n        others =>(others => ''0'')\n');
        fprintf(fileid,',\n        others =>(others => ''0'')\n');
      end;
      end;
    end;
    end;
    if i != size(cell2mat(wbMat(k,1)),2)
    if i ~= size(cell2mat(wbMat(k,1)),2)
      fprintf(fileid,'      ),\n');
      fprintf(fileid,'      ),\n');
    else
    else
      fprintf(fileid,'      ),\n      others=>(others =>(others => ''0''))\n');
      fprintf(fileid,'      ),\n      others=>(others =>(others => ''0''))\n');
    end;
    end;
  end;
  end;
  if k != NLayers
  if k ~= NLayers
    fprintf(fileid,'    ),\n');
    fprintf(fileid,'    ),\n');
  else
  else
    fprintf(fileid,'    )\n');
    fprintf(fileid,'    )\n');
  end;
  end;
end;
end;
fprintf(fileid,'  );\n\n');
fprintf(fileid,'  );\n\n');
 
 
fprintf(fileid,'  constant b_init : b_type :=\n');
fprintf(fileid,'  constant b_init : b_type :=\n');
fprintf(fileid,'  (\n');
fprintf(fileid,'  (\n');
for(k=1:NLayers)
for(k=1:NLayers)
  fprintf(fileid,'    %i => (\n',k-1);
  fprintf(fileid,'    %i => (\n',k-1);
  for(j=1:length(cell2mat(wbMat(k,2))))    % inputs
  for(j=1:length(cell2mat(wbMat(k,2))))    % inputs
    fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%1.4f))',j-1, cell2mat(wbMat(k,2))(j));
    fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%1.4f))',j-1, cell2mat(wbMat(k,2))(j));
    if j != length(cell2mat(wbMat(k,2)))
    if j ~= length(cell2mat(wbMat(k,2)))
      fprintf(fileid,',\n');
      fprintf(fileid,',\n');
    else
    else
      fprintf(fileid,',\n      others =>(others => ''0'')\n');
      fprintf(fileid,',\n      others =>(others => ''0'')\n');
    end;
    end;
  end;
  end;
  if k != NLayers
  if k ~= NLayers
    fprintf(fileid,'    ),\n');
    fprintf(fileid,'    ),\n');
  else
  else
    fprintf(fileid,'    )\n');
    fprintf(fileid,'    )\n');
  end;
  end;
end;
end;
fprintf(fileid,'  );\n');
fprintf(fileid,'  );\n');
 
 
 
 
% fprintf(fileid,'    constant b0_init : ramd_type0 :=\n');
 
% fprintf(fileid,'    (\n');
 
% for(i=1:length(nn_data.b1))
 
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b1(i));
 
%     if i != length(nn_data.b1)
 
%       fprintf(fileid,',\n');
 
%     else
 
%       fprintf(fileid,'\n');
 
%     end;
 
 
 
% end;
 
% fprintf(fileid,'    );\n');
 
 
 
% fprintf(fileid,'    constant b1_init : ramd_type1 :=\n');
 
% fprintf(fileid,'    (\n');
 
% for(i=1:length(nn_data.b2))
 
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b2(i));
 
%     if i != length(nn_data.b2)
 
%       fprintf(fileid,',\n');
 
%     else
 
%       fprintf(fileid,'\n');
 
%     end;
 
% end;
 
% fprintf(fileid,'    );\n');
 
 
 
% fprintf(fileid,'    constant b2_init : ramd_type2 :=\n');
 
% fprintf(fileid,'    (\n');
 
% for(i=1:length(nn_data.b3))
 
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b3(i));
 
%     if i != length(nn_data.b3)
 
%       fprintf(fileid,',\n');
 
%     else
 
%       fprintf(fileid,'\n');
 
%     end;
 
% end;
 
% fprintf(fileid,'    );\n');
 
 
 
fprintf(fileid,'end wb_init;\n');
fprintf(fileid,'end wb_init;\n');
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.