-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* linear2d_layer forward implementation * implement backward * introduce concurrency, outtroduce stupidity * fix style * add parameters api to linear2d_layer * add constructor for linear2d_layer * add integration for linear2d layer * set usage rules for linear2d_layer * add linear2d_layer to public api * update tests for linear2d layer * remove extra comment * remove rubbish * move linear2d layer logic into submodule * update cmake for linear2d_layer * update tests for linear2d_layer * update linear2d_layer tests * update linear2d_layer tests for batch last * make linear2d_layer with batch as last dimension (performance) * linear2d_layer: fix gradient updates * linear2d_layer: make it 2d * linear2d_layer: forgot a file * linear2d_layer: temporarily remove api * Don't expose the concrete layer type via nf * Report success to stdout * Include linear2d test in cmake * Add Linear2d to README * Plumbing of linear2d with input2d and linear2d * linear2d_layer: add flatten2d layer * linear2d_layer: make linear2d layer work with input2d and flatten2d * update cmake * linear2d_layer: use flatten layer instead of flatten2d * linear2d_layer: remove flatten2d layer * linear2d_layer: remove public api * linear2d_layer: update cmakelists * linear2d_layer: workaround cpu imprecision to make ci happy * Add linear2d example * linear2d_layer: remove redundant constructor args * linear2d_layer: make example converge * linear2d_layer: make weighs init with normal distribution * linear2d_layer: add loss stopping and more iterations * linear2d_layer: update tests * Tidy up * Require passing only out_features to linear2d(); tidy up * Remove linear2d example --------- Co-authored-by: milancurcic <[email protected]>
- Loading branch information
1 parent
4ad75bc
commit c316ee1
Showing
11 changed files
with
476 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module nf_linear2d_layer | ||
|
||
use nf_activation, only: activation_function | ||
use nf_base_layer, only: base_layer | ||
|
||
implicit none | ||
|
||
private | ||
public :: linear2d_layer | ||
|
||
type, extends(base_layer) :: linear2d_layer | ||
integer :: sequence_length, in_features, out_features, batch_size | ||
|
||
real, allocatable :: weights(:,:) | ||
real, allocatable :: biases(:) | ||
real, allocatable :: output(:,:) | ||
real, allocatable :: gradient(:,:) ! input gradient | ||
real, allocatable :: dw(:,:) ! weight gradients | ||
real, allocatable :: db(:) ! bias gradients | ||
|
||
contains | ||
|
||
procedure :: backward | ||
procedure :: forward | ||
procedure :: init | ||
procedure :: get_num_params | ||
procedure :: get_params | ||
procedure :: get_gradients | ||
procedure :: set_params | ||
|
||
end type linear2d_layer | ||
|
||
interface linear2d_layer | ||
module function linear2d_layer_cons(out_features) result(res) | ||
integer, intent(in) :: out_features | ||
type(linear2d_layer) :: res | ||
end function linear2d_layer_cons | ||
end interface linear2d_layer | ||
|
||
interface | ||
pure module subroutine forward(self, input) | ||
class(linear2d_layer), intent(in out) :: self | ||
real, intent(in) :: input(:,:) | ||
end subroutine forward | ||
|
||
pure module subroutine backward(self, input, gradient) | ||
class(linear2d_layer), intent(in out) :: self | ||
real, intent(in) :: input(:,:) | ||
real, intent(in) :: gradient(:,:) | ||
end subroutine backward | ||
|
||
module subroutine init(self, input_shape) | ||
class(linear2d_layer), intent(in out) :: self | ||
integer, intent(in) :: input_shape(:) | ||
end subroutine init | ||
|
||
pure module function get_num_params(self) result(num_params) | ||
class(linear2d_layer), intent(in) :: self | ||
integer :: num_params | ||
end function get_num_params | ||
|
||
module function get_params(self) result(params) | ||
class(linear2d_layer), intent(in), target :: self | ||
real, allocatable :: params(:) | ||
end function get_params | ||
|
||
module function get_gradients(self) result(gradients) | ||
class(linear2d_layer), intent(in), target :: self | ||
real, allocatable :: gradients(:) | ||
end function get_gradients | ||
|
||
module subroutine set_params(self, params) | ||
class(linear2d_layer), intent(in out) :: self | ||
real, intent(in), target :: params(:) | ||
end subroutine set_params | ||
end interface | ||
end module nf_linear2d_layer |
Oops, something went wrong.