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 8

Go to most recent revision | 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
      if j != size(cell2mat(wbMat(k,1)),1)
39
        fprintf(fileid,',\n');
40
      else
41
        fprintf(fileid,',\n        others =>(others => ''0'')\n');
42
      end;
43
    end;
44
    if i != size(cell2mat(wbMat(k,1)),2)
45
      fprintf(fileid,'      ),\n');
46
    else
47
      fprintf(fileid,'      ),\n      others=>(others =>(others => ''0''))\n');
48
    end;
49
  end;
50
  if k != NLayers
51
    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
    if j != length(cell2mat(wbMat(k,2)))
65
      fprintf(fileid,',\n');
66
    else
67
      fprintf(fileid,',\n      others =>(others => ''0'')\n');
68
    end;
69
  end;
70
  if k != NLayers
71
    fprintf(fileid,'    ),\n');
72
  else
73
    fprintf(fileid,'    )\n');
74
  end;
75
end;
76
fprintf(fileid,'  );\n');
77
 
78
 
79
% fprintf(fileid,'    constant b0_init : ramd_type0 :=\n');
80
% fprintf(fileid,'    (\n');
81
% for(i=1:length(nn_data.b1))
82
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b1(i));
83
%     if i != length(nn_data.b1)
84
%       fprintf(fileid,',\n');
85
%     else
86
%       fprintf(fileid,'\n');
87
%     end;
88
 
89
% end;
90
% fprintf(fileid,'    );\n');
91
 
92
% fprintf(fileid,'    constant b1_init : ramd_type1 :=\n');
93
% fprintf(fileid,'    (\n');
94
% for(i=1:length(nn_data.b2))
95
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b2(i));
96
%     if i != length(nn_data.b2)
97
%       fprintf(fileid,',\n');
98
%     else
99
%       fprintf(fileid,'\n');
100
%     end;
101
% end;
102
% fprintf(fileid,'    );\n');
103
 
104
% fprintf(fileid,'    constant b2_init : ramd_type2 :=\n');
105
% fprintf(fileid,'    (\n');
106
% for(i=1:length(nn_data.b3))
107
%     fprintf(fileid,'      %i => real2stdlv(NbitW,(2.0**LSB_OUT)*(%.4f))',i-1,nn_data.b3(i));
108
%     if i != length(nn_data.b3)
109
%       fprintf(fileid,',\n');
110
%     else
111
%       fprintf(fileid,'\n');
112
%     end;
113
% end;
114
% fprintf(fileid,'    );\n');
115
 
116
fprintf(fileid,'end wb_init;\n');
117
fclose(fileid);

powered by: WebSVN 2.1.0

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