Skip to content

Commit

Permalink
Add interface files from the remainder of the camlgrad project
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelltaylor committed Apr 21, 2024
1 parent dfa1328 commit 474bd78
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lib/loss.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(* Loss Interface *)

(* Imports *)
open Tensor

(* Loss Functions *)
val mean_squared_error : tensor -> tensor -> tensor
val binary_cross_entropy : tensor -> tensor -> tensor
10 changes: 9 additions & 1 deletion lib/mlp.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
open Types
open Tensor

type dimensions = int * int
type mlp_layer = {
weights : tensor;
bias : tensor;
activation: tensor -> tensor
}
type mlp = mlp_layer array

let get_mlp_layer ?(activation = Tensor.sigmoid) dims =
let (_, d2) = dims in
Expand Down
22 changes: 22 additions & 0 deletions lib/mlp.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(* Mlp Interface *)

(* Imports *)
open Tensor

(* Type Definitions *)
type dimensions = int * int
type mlp_layer = {
weights : tensor;
bias : tensor;
activation: tensor -> tensor
}
type mlp = mlp_layer array

(* Creating *)
val get_mlp : ((tensor -> tensor) * dimensions) array -> mlp
val get_mlp_layer : ?activation:(tensor -> tensor) -> dimensions -> mlp_layer

(* Forward Pass *)
val mlp_forward : mlp -> tensor -> (tensor * tensor array)
val mlp_layer_forward : mlp_layer -> tensor -> tensor

1 change: 1 addition & 0 deletions lib/optimizer.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Tensor
open Types
open Mlp

let apply_update mlp_layer learning_rate =
let weight_acc_grad = mlp_layer.weights.acc_grad in
Expand Down
16 changes: 16 additions & 0 deletions lib/optimizer.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(* Optimizer interface *)

(* Imports *)
open Mlp
open Tensor

(* Optimizer Backward Functions *)
val apply_update : mlp_layer -> float -> unit
val update : mlp -> float -> unit
val gradient_descent : mlp -> tensor -> float -> unit

(* Optimizer Zero Grad Functions *)
val zero_grad_mlp_layer : mlp_layer -> unit
val zero_grad_mlp : mlp -> unit


9 changes: 0 additions & 9 deletions lib/types.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
open Tensor

exception InvalidArgumentException of string

type mlp_layer = {
weights : tensor;
bias : tensor;
activation: tensor -> tensor
}

type mlp = mlp_layer array

0 comments on commit 474bd78

Please sign in to comment.