-
Notifications
You must be signed in to change notification settings - Fork 91
Weight initialization #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,7 @@ module nf_random | |||||||||
implicit none | ||||||||||
|
||||||||||
private | ||||||||||
public :: random_normal | ||||||||||
public :: random_normal, random_he, random_xavier | ||||||||||
|
||||||||||
real, parameter :: pi = 4 * atan(1.d0) | ||||||||||
|
||||||||||
|
@@ -23,4 +23,22 @@ impure elemental subroutine random_normal(x) | |||||||||
x = sqrt(- 2 * log(u(1))) * cos(2 * pi * u(2)) | ||||||||||
end subroutine random_normal | ||||||||||
|
||||||||||
impure elemental subroutine random_he(x, n_prev) | ||||||||||
!! Kaiming weight initialization | ||||||||||
real, intent(in out) :: x | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
integer, intent(in) :: n_prev | ||||||||||
call random_number(x) | ||||||||||
x = x * sqrt(2. / n_prev) | ||||||||||
end subroutine random_he | ||||||||||
|
||||||||||
impure elemental subroutine random_xavier(x, n_prev) | ||||||||||
!! Kaiming weight initialization | ||||||||||
real, intent(in out) :: x | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
integer, intent(in) :: n_prev | ||||||||||
real :: lower, upper | ||||||||||
lower = -(1. / sqrt(real(n_prev))) | ||||||||||
upper = 1. / sqrt(real(n_prev)) | ||||||||||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
call random_number(x) | ||||||||||
x = lower + x * (upper - lower) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct if |
||||||||||
end subroutine random_xavier | ||||||||||
end module nf_random |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be as default? Or should the user be able to choose for another pseudo-random generator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how it's done here: #151
In the DL Framework of my dreams, I would have an option to pass the algorithm of weights initialization into a layer's constructor. So: