-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refac: update sourcery depency version to 4.4.0
- Loading branch information
Showing
18 changed files
with
153 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
submodule(hyperparameters_m) hyperparameters_s | ||
use assert_m, only : assert, intrinsic_array_t | ||
use sourcery_m, only : string_t | ||
use assert_m, only : assert | ||
implicit none | ||
|
||
character(len=*), parameter :: mini_batches_key = "mini-batches" | ||
character(len=*), parameter :: learning_rate_key = "learning rate" | ||
character(len=*), parameter :: optimizer_key = "optimizer" | ||
|
||
contains | ||
|
||
module procedure construct_from_json_file | ||
integer l | ||
module procedure from_json | ||
type(string_t), allocatable :: lines(:) | ||
integer l | ||
logical hyperparameters_key_found | ||
|
||
lines = file_%lines() | ||
|
||
l = 1 | ||
call assert(adjustl(lines(l)%string())=="{", 'construct_from_json_file: adjustl(lines(l)%string())=="{"', lines(l)%string()) | ||
|
||
!{ | ||
! "activation" : "sigmoid", | ||
! "num_mini_batches" : 10, | ||
! "nodes per layer" : [2, 72, 2], | ||
! "initialization" : { | ||
! "type" : "perturbed identity", | ||
! "parameters" : [ { "spread" : 0.05 } ] | ||
! } | ||
!} | ||
|
||
|
||
l = l + 1 | ||
call assert(adjustl(lines(l)%string())=="}", 'construct_from_json_file: adjustl(lines(l)%string())=="}"', lines(l)%string()) | ||
hyperparameters_key_found = .false. | ||
|
||
loop_through_file: & | ||
do l=1,size(lines) | ||
if (lines(l)%get_json_key() == "hyperparameters") then | ||
hyperparameters_key_found = .true. | ||
hyperparameters%mini_batches_ = lines(l+1)%get_json_value(string_t(mini_batches_key), mold=0) | ||
hyperparameters%learning_rate_ = lines(l+2)%get_json_value(string_t(learning_rate_key), mold=0.) | ||
hyperparameters%optimizer_ = lines(l+3)%get_json_value(string_t(optimizer_key), mold=string_t("")) | ||
return | ||
end if | ||
end do loop_through_file | ||
|
||
call assert(hyperparameters_key_found, "hyperparameters_s(from_json): hyperparameters_found") | ||
end procedure | ||
|
||
module procedure to_json | ||
type(string_t), allocatable :: lines(:) | ||
integer, parameter :: outer_object_braces = 2 | ||
integer, parameter :: num_lines = outer_object_braces | ||
integer l | ||
|
||
allocate(lines(num_lines)) | ||
|
||
l = 1 | ||
lines(l) = string_t('{') | ||
|
||
l = l + 1 | ||
!lines(line) = string_t(' "modelName": "' // & | ||
!self%metadata_(findloc(key, "modelName", dim=1))%string() // '",') | ||
|
||
|
||
|
||
l = l + 1 | ||
call assert(l == num_lines, "hyperparameters_s(to_json): l == num_lines", intrinsic_array_t([l,num_lines])) | ||
lines(l) = string_t('}') | ||
character(len=*), parameter :: indent = repeat(" ",ncopies=4) | ||
integer, parameter :: max_digits = 12 | ||
character(len=max_digits) mini_batches_string, learning_rate_string | ||
|
||
write(mini_batches_string,*) self%mini_batches_ | ||
write(learning_rate_string,*) self%learning_rate_ | ||
|
||
lines = [ & | ||
string_t(indent // '"hyperparameters": {'), & | ||
string_t(indent // indent // '"' // mini_batches_key // '": ' // mini_batches_string ), & | ||
string_t(indent // indent // '"' // learning_rate_key // '": ' // learning_rate_string ), & | ||
string_t(indent // indent // '"' // optimizer_key // '": "' // self%optimizer_ // '"'), & | ||
string_t(indent // '}') & | ||
] | ||
end procedure | ||
|
||
end submodule hyperparameters_s |
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,39 @@ | ||
module network_configuration_m | ||
use sourcery_m, only : file_t | ||
implicit none | ||
|
||
private | ||
public :: network_configuration_t | ||
|
||
type network_configuration_t | ||
private | ||
type(string_t) activation_function_ | ||
integer, allocatable :: nodes_per_layer_(:) | ||
logical skip_connections_ | ||
contains | ||
procedure :: to_json | ||
end type | ||
|
||
end type | ||
|
||
interface network_configuration_t | ||
|
||
elemental module function from_json(file_) result(network_configuration) | ||
implicit none | ||
type(file_t), intent(in) :: file_ | ||
type(network_configuration_t) network_configuration | ||
end function | ||
|
||
end interface | ||
|
||
interface | ||
|
||
elemental module function to_json(self) result(json_file) | ||
implicit none | ||
class(network_configuration_t), intent(in) :: self | ||
type(file_t) json_file | ||
end function | ||
|
||
end interface | ||
|
||
end module |
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,54 @@ | ||
submodule(network_configuration_m) network_configuration_s | ||
use assert_m, only : assert | ||
use sourcery_m, only : string_t | ||
implicit none | ||
|
||
character(len=*), parameter :: activation_function_key = "activation function" | ||
character(len=*), parameter :: nodes_per_layer_key = "nodes per layer" | ||
character(len=*), parameter :: skip_connections_key = "skip connections" | ||
|
||
contains | ||
|
||
module procedure from_json | ||
type(string_t), allocatable :: lines(:) | ||
integer l | ||
logical network configuration_key_found | ||
|
||
lines = file_%lines() | ||
network configuration_key_found = .false. | ||
|
||
loop_through_file: & | ||
do l=1,size(lines) | ||
if (line(l)%get_key() == "network configuration") then | ||
network configuration_key_found = .true. | ||
self%activation_function_ = line(l+1)%get_json_value(activation_function_key, mold=string("")) | ||
self%nodes_per_layer_ = line(l+2)%get_json_value(nodes_per_layer_key , mold=[integer::]) | ||
self%skip_connections_ = line(l+2)%get_json_value(skip_connetions_key , mold=.true.) | ||
return | ||
end if | ||
end do loop_through_file | ||
|
||
call assert(network configuration_found, "network configuration_s(from_json): network configuration_found") | ||
end procedure | ||
|
||
module procedure to_json | ||
character(len=:), parameter :: indent = repeat(" ",ncopies=4) | ||
integer, parameter :: max_digits = 12, max_length=5 | ||
character(len=max_digits) activation_function_string, nodes_per_layer_string, skip_connections_string | ||
character(len=max_length) skip_connections_string | ||
|
||
|
||
write(activation_function_string,*) self%activation_function_ | ||
write(nodes_per_layer_string ,*) self%nodes_per_layer_ | ||
write(skip_connections_string ,*) merge("true ","false", self%skip_connections_) | ||
|
||
lines = [ & | ||
string_t(indent // '"network configuration": {'), & | ||
string_t(indent // indent // '"' // activation_function_key //'": ' // activation_function_string ), & | ||
string_t(indent // indent // '"' // nodes_per_layer_key //'": ' // nodes_per_layer_string ), & | ||
string_t(indent // indent // '"' // skip_connections_key //'": "' // skip_connections_string // '"'), & | ||
string_t(indent // '}') & | ||
] | ||
end procedure | ||
|
||
end submodule network_configuration_s |
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
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
Oops, something went wrong.