-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e041c7f
commit 1ecf443
Showing
6 changed files
with
46 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(library | ||
(name smolgrad) | ||
(public_name smolgrad) | ||
(modules variable neuron layer)) | ||
(modules variable neuron layer network)) |
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,28 @@ | ||
module Network = struct | ||
type t = { | ||
layers : Layer.Layer.t list; | ||
} | ||
|
||
(* the number of output parameters of a layer is the number of neurons in that layer *) | ||
(* important to understand that the input layer isn't truly a layer with weights and biases; just an abstraction *) | ||
let create number_of_input_dimensions number_of_neurons_per_layer = | ||
let size_of_each_layer = number_of_input_dimensions :: number_of_neurons_per_layer in | ||
|
||
let rec build_layers stacked_layers sizes = | ||
match sizes with | ||
| input :: output :: rest -> | ||
let layer = Layer.Layer.create input output true in | ||
|
||
(* note how we are stacking the layers in reverse order *) | ||
build_layers (layer :: stacked_layers) (output :: rest) | ||
|
||
(* hence we got to reverse it at the end *) | ||
| _ -> List.rev stacked_layers | ||
in | ||
{ layers = build_layers [] size_of_each_layer } | ||
|
||
(* the input vector as it propagates through each layer, is considered the intermediate output | ||
and of course the input for the next layer, until the last one is the final output vector *) | ||
let propagate_input (network: t) input_vector = | ||
List.fold_left (fun intermediate_output layer -> Layer.Layer.propagate_input layer intermediate_output) input_vector network.layers | ||
end |
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,8 @@ | ||
(* Multi-Layer Perceptron so that we can connect multiple stacked layers *) | ||
module Network : sig | ||
type t | ||
|
||
val create : int -> int list -> t | ||
|
||
val propagate_input : t -> Variable.Variable.t list -> Variable.Variable.t list | ||
end |
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