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] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 jstefanowi
function wb_gen(NET)
2
 
3
[wbMat NLayers] = getwbc(NET);
4
MaxNeuronCnt = max_dim(wbMat);
5
 
6
fileid = fopen ('wb_init.vhd','w');
7
 
8
% addr weights:
9
% |_ _|  |0|  |_ _ _ _ _| |_ _ _ _ _ _|
10
% layer  bias    neuron      input
11
% *2^12+  0   + *2^5    +   *2^0
12
% addr biases:
13
% |_ _|  |1|  |0 0 0 0 0 0| |_ _ _ _ _|
14
% layer  bias                 neuron
15
% *2^12+ 2^11 +     0      +   *2^0
16
 
17
fprintf(fileid,'library ieee;\n');
18
fprintf(fileid,'use ieee.std_logic_1164.all;\n');
19
fprintf(fileid,'use ieee.numeric_std.all;\n');
20
fprintf(fileid,'library work;\n');
21
fprintf(fileid,'use work.support_pkg.all;\n');
22
fprintf(fileid,'use work.layers_pkg.all;\n');
23
fprintf(fileid,'package wb_init is\n');
24
 
25
fprintf(fileid,'  type ramd_type is array (%i downto 0) of std_logic_vector(NbitW-1 downto 0);\n',MaxNeuronCnt);
26
fprintf(fileid,'  type layer_ram is array (%i downto 0) of ramd_type;\n',MaxNeuronCnt);
27
fprintf(fileid,'  type w_ram  is array (integer range <>) of layer_ram;\n');
28
fprintf(fileid,'  type b_type is array (integer range <>) of ramd_type;\n');
29
 
30
fprintf(fileid,'  constant w_init : w_ram :=\n');
31
fprintf(fileid,'  (\n');
32
for(k=1:NLayers)
33
  fprintf(fileid,'    %i => (\n',k-1);
34
  for(i=1:size(cell2mat(wbMat(k,1)),2))  % neurons
35
    fprintf(fileid,'      %i => (\n',i-1);
36
    for(j=1:size(cell2mat(wbMat(k,1)),1))    % inputs
37
      fprintf(fileid,'        %i => real2stdlv(NbitW,%1.4f)',j-1, cell2mat(wbMat(k,1))(j,i));
38 12 jstefanowi
      if j ~= size(cell2mat(wbMat(k,1)),1)
39 8 jstefanowi
        fprintf(fileid,',\n');
40
      else
41
        fprintf(fileid,',\n        others =>(others => ''0'')\n');
42
      end;
43
    end;
44 12 jstefanowi
    if i ~= size(cell2mat(wbMat(k,1)),2)
45 8 jstefanowi
      fprintf(fileid,'      ),\n');
46
    else
47
      fprintf(fileid,'      ),\n      others=>(others =>(others => ''0''))\n');
48
    end;
49
  end;
50 12 jstefanowi
  if k ~= NLayers
51 8 jstefanowi
    fprintf(fileid,'    ),\n');
52
  else
53
    fprintf(fileid,'    )\n');
54
  end;
55
end;
56
fprintf(fileid,'  );\n\n');
57
 
58
fprintf(fileid,'  constant b_init : b_type :=\n');
59
fprintf(fileid,'  (\n');
60
for(k=1:NLayers)
61
  fprintf(fileid,'    %i => (\n',k-1);
62
  for(j=1:length(cell2mat(wbMat(k,2))))    % inputs
63
    fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%1.4f))',j-1, cell2mat(wbMat(k,2))(j));
64 12 jstefanowi
    if j ~= length(cell2mat(wbMat(k,2)))
65 8 jstefanowi
      fprintf(fileid,',\n');
66
    else
67
      fprintf(fileid,',\n      others =>(others => ''0'')\n');
68
    end;
69
  end;
70 12 jstefanowi
  if k ~= NLayers
71 8 jstefanowi
    fprintf(fileid,'    ),\n');
72
  else
73
    fprintf(fileid,'    )\n');
74
  end;
75
end;
76
fprintf(fileid,'  );\n');
77
 
78
fprintf(fileid,'end wb_init;\n');
79
fclose(fileid);

powered by: WebSVN 2.1.0

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