-
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
9bebca2
commit 6f584f9
Showing
7 changed files
with
48 additions
and
7 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,2 +1,3 @@ | ||
smolgrad/_build/* | ||
smolgrad/_opam/* | ||
_build/* | ||
_opam/* | ||
.vscode/* |
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,2 +1,2 @@ | ||
(lang dune 2.0) | ||
(name smolgrad.ml) | ||
(name smolgrad-ml) |
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,3 @@ | ||
(library | ||
(name nn) | ||
(modules Neuron Network)) |
Empty file.
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,29 @@ | ||
module Neuron = struct | ||
type t = { | ||
mutable data : float; | ||
mutable grad : float; | ||
mutable backward : unit -> unit; | ||
op : string; | ||
prev : t list; | ||
} | ||
|
||
let create data operator = { data; grad = 0.; | ||
backward = (fun () -> ()); op = operator; prev = [] | ||
} | ||
|
||
let add a b = | ||
let out = create (a.data +. b.data) "+" in | ||
out.backward <- (fun () -> | ||
a.grad <- a.grad +. out.grad; | ||
b.grad <- b.grad +. out.grad; | ||
); | ||
out | ||
|
||
let mul a b = | ||
let out = create (a.data *. b.data) "*" in | ||
out.backward <- (fun () -> | ||
a.grad <- a.grad +. b.data *. out.grad; | ||
b.grad <- b.grad +. a.data *. out.grad; | ||
); | ||
out | ||
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,12 @@ | ||
module Neuron : sig | ||
type t | ||
|
||
(* Constructor; constructs a unit neuron of a value and an operator. *) | ||
val create : float -> string -> t | ||
|
||
(* Adds two values, resulting in a new value. *) | ||
val add : t -> t -> t | ||
|
||
(* Multiplies two values, resulting in a new value. *) | ||
val mul : t -> t -> t | ||
end |
This file was deleted.
Oops, something went wrong.