-
Notifications
You must be signed in to change notification settings - Fork 0
/
inner_product_forward.m
41 lines (32 loc) · 1.11 KB
/
inner_product_forward.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function [output] = inner_product_forward(input, layer, param)
%% function input:
% input.batch_size: batch_size of input
% input.height: height of input
% input.width : width of input
% input.data: the actual data of input
% input.data is of size (input.height*input.width*input.channel, input.batch_size)
% layer.num: output dimension of this layer
% param.w: weight parameter of this layer, is of size
% (input.height*input.width*input.channel, layer.num)
% param.b: bias parameter of this layer, is of size
% (1, layer.num);
%% function output
% output: the output of inner_product_forward
%% here begins the inner product forward computation
% set the shape of output
output.height = 1;
output.width = 1;
output.channel = layer.num;
output.batch_size = input.batch_size;
% sanity check
d = size(input.data, 1);
assert(size(param.w, 1) == d, 'dimension mismatch in inner_product layer');
% initialize the outupt data
output.data = zeros(layer.num, input.batch_size);
temp = (param.w.')*input.data;
for i =1:size(temp,2)
temp(:,i)=temp(:,i)+param.b.';
end
output.data=temp;
% start to work here to compute output.data
end