The entry point of this library is Owl_opt.
'a t in some module Prms@@deriving prms to type 'a t so that Prms has type Owl_opt.Prms.PTPrms through your favourite algorithm functor to create an optimisation module Of that takes as input your record type 'a tprms0lr with Owl_opt.Lrs0 with O.init ~prms0 ~fstop: state -> boolO.min ~stop s0 module Prms = struct
type 'a t = {a: 'a; b: 'a} [@@deriving prms]
end
(* make an Adam optimisation module for the parameter definition Prms *)
module O = Owl_opt.D.Adam.Make (Prms)
(* define the objective function *)
let f prms = Owl.Algodiff.D.Maths.(l2norm' (y - ((prms.a *@ x) + prms.b)))
(* define initial parameters *)
let prms0 = {a = Owl.Algodiff.D.Mat.gaussian 5 5; b = Owl.Algodiff.D.gaussian 5 1}
(* define fixed learning rate *)
let lr = Owl_opt.Lr.(Fix 1E-4)
(* initialise an optimisation session *)
let s0 = O.init ~prms0 ~f ()
(* define stopping criteria: stop when function value is smaller than 1E-4 *)
let stop s = O.(fv s) < 1E-4
(* minimise objective function f *)
let s = O.min ~stop ~beta1:0.99 ~beta2:0.999 ~lr f
(* final objective function value *)
let c = O.fv s
(* final prms *)
let prms = O.prms s Owl_opt.Prms and module type definition Owl_opt.Prms.PTOwl_opt.LrOwl_opt.D.Gd.MakeOwl_opt.D.Adam.MakeOwl_opt.D.Rmsprop.MakeOwl_opt.S.Gd.MakeOwl_opt.S.Adam.MakeOwl_opt.S.Rmsprop.Make