Skip to content

Instantly share code, notes, and snippets.

@ryanrhymes
Created March 11, 2017 22:27
Show Gist options
  • Save ryanrhymes/347acf8416615447254bfb3bf179f95d to your computer and use it in GitHub Desktop.
Save ryanrhymes/347acf8416615447254bfb3bf179f95d to your computer and use it in GitHub Desktop.
let backprop nn eta x y =
let t = tag () in
Array.iter (fun l ->
l.w <- make_reverse l.w t;
l.b <- make_reverse l.b t;
) nn.layers;
let loss = Maths.(cross_entropy y (run_network x nn) / (F (Mat.row_num x |> float_of_int))) in
reverse_prop (F 1.) loss;
Array.iter (fun l ->
l.w <- Maths.((primal l.w) - (eta * (adjval l.w))) |> primal;
l.b <- Maths.((primal l.b) - (eta * (adjval l.b))) |> primal;
) nn.layers;
loss |> unpack_flt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment