Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shawn Nithyan Stanley
uwnet
Commits
d7619d48
Commit
d7619d48
authored
Oct 31, 2021
by
Shawn Nithyan Stanley
Browse files
Replace connected_layer.c
parent
82640837
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/connected_layer.c
View file @
d7619d48
...
...
@@ -49,9 +49,9 @@ matrix forward_connected_layer(layer l, matrix x)
*
l
.
x
=
copy_matrix
(
x
);
// TODO: 3.1 - run the network forward
matrix
y
=
make_matrix
(
x
.
rows
,
l
.
w
.
cols
);
// Going to want to change this!
//
matrix y = make_matrix(x.rows, l.w.cols); // Going to want to change this!
matrix
y
=
matmul
(
x
,
l
.
w
);
y
=
forward_bias
(
y
,
l
.
b
);
return
y
;
}
...
...
@@ -71,9 +71,12 @@ matrix backward_connected_layer(layer l, matrix dy)
// updates for our weights, which are stored in l.dw
// Calculate dL/dx and return it
matrix
dx
=
copy_matrix
(
x
);
// Change this
axpy_matrix
(
1
.
0
,
backward_bias
(
dy
),
l
.
db
);
matrix
dw
=
matmul
(
transpose_matrix
(
x
),
dy
);
// Change this
axpy_matrix
(
1
.
0
,
dw
,
l
.
dw
);
matrix
dx
=
matmul
(
dy
,
transpose_matrix
(
l
.
w
));
return
dx
;
}
...
...
@@ -93,6 +96,12 @@ void update_connected_layer(layer l, float rate, float momentum, float decay)
// we want it to be (-momentum * update) so we just need to scale it a little
// Do the same for biases as well but no need to use weight decay on biases
axpy_matrix
(
decay
,
l
.
w
,
l
.
dw
);
axpy_matrix
(
-
rate
,
l
.
dw
,
l
.
w
);
scal_matrix
(
momentum
,
l
.
dw
);
axpy_matrix
(
-
rate
,
l
.
db
,
l
.
b
);
scal_matrix
(
momentum
,
l
.
db
);
}
layer
make_connected_layer
(
int
inputs
,
int
outputs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment