Module Optimise.Algodiff

include Owl_algodiff_core_sig.Sig
Type definition
include Owl_algodiff_types_sig.Sig with type elt := A.elt and type arr := A.arr
type t =
  1. | F of A.elt
  2. | Arr of A.arr
  3. | DF of t * t * int
  4. | DR of t * t Stdlib.ref * op * int Stdlib.ref * int * int Stdlib.ref
and adjoint = t -> t Stdlib.ref -> (t * t) list -> (t * t) list
and register = t list -> t list
and label = string * t list
and op = adjoint * register * label
Core functions
val tag : unit -> int

start global tagging counter

val primal : t -> t

get primal component of DF or DR type

val primal' : t -> t

iteratively get primal component of DF or DR type until the component itself is not DF/DR

val zero : t -> t

return a zero value, which type decided by the input value

val reset_zero : t -> t

reset_zero x iteratively resets all elements included in x

val tangent : t -> t

get the tangent component of input, if the data type is suitable

val adjref : t -> t Stdlib.ref

get the adjref component of input, if the data type is suitable

val adjval : t -> t

get the adjval component of input, if the data type is suitableTODO

val shape : t -> int array

get the shape of primal' value of input

val is_float : t -> bool

check if input is of float value; if input is of type DF/DR, check its primal' value

val is_arr : t -> bool

check if input is of ndarray value; if input is of type DF/DR, check its primal' value

val row_num : t -> int

get the shape of primal' value of input; and then get the first dimension

val col_num : t -> int

get the shape of primal' value of input; and then get the second dimension

val numel : t -> int

for ndarray type input, return its total number of elements.

val clip_by_value : amin:A.elt -> amax:A.elt -> t -> t

other functions, without tracking gradient

val clip_by_l2norm : A.elt -> t -> t

other functions, without tracking gradient

val copy_primal' : t -> t

if primal' value of input is ndarray, copy its value in a new AD type ndarray

val tile : t -> int array -> t

if primal' value of input is ndarray, apply the tile function

val repeat : t -> int array -> t

if primal' value of input is ndarray, apply the repeat function

val pack_elt : A.elt -> t

convert from elt type to t type.

val unpack_elt : t -> A.elt

convert from t type to elt type.

val pack_flt : float -> t

convert from float type to t type.

val _f : float -> t

A shortcut function for F A.(float_to_elt x).

val unpack_flt : t -> float

convert from t type to float type.

val pack_arr : A.arr -> t

convert from arr type to t type.

val unpack_arr : t -> A.arr

convert from t type to arr type.

val deep_info : t -> string
val type_info : t -> string
val error_binop : string -> t -> t -> 'a
val error_uniop : string -> t -> 'a
val make_forward : t -> t -> int -> t

make_forward p t i construct a forward algodiff data type DF, consisting of primal p, tangent t, and tag i.

val make_reverse : t -> int -> t

make_reverse p i construct a reverse algodiff data type DR, consisting of primal, adjoint, op, fanout, tag, and tracker.

val reverse_prop : t -> t -> unit

reverse_prop f x performs reverse propagation for function f using the output value x.

val diff : (t -> t) -> t -> t

diff f x returns the exat derivative of a function f : scalar -> scalar at point x. Simply calling diff f will return its derivative function g of the same type, i.e. g : scalar -> scalar.

Keep calling this function will give you higher-order derivatives of f, i.e. f |> diff |> diff |> diff |> ...

val diff' : (t -> t) -> t -> t * t

similar to diff, but return (f x, diff f x).

val grad : (t -> t) -> t -> t

gradient of f : (vector -> scalar) at x, reverse ad.

val grad' : (t -> t) -> t -> t * t

similar to grad, but return (f x, grad f x).

val jacobian : (t -> t) -> t -> t

jacobian of f : (vector -> vector) at x, both x and y are row vectors.

val jacobian' : (t -> t) -> t -> t * t

similar to jacobian, but return (f x, jacobian f x)

val jacobianv : (t -> t) -> t -> t -> t

jacobian vector product of f : (vector -> vector) at x along v, forward ad. Namely, it calcultes (jacobian x) v

val jacobianv' : (t -> t) -> t -> t -> t * t

similar to jacobianv', but return (f x, jacobianv f x v)

val jacobianTv : (t -> t) -> t -> t -> t

transposed jacobian vector product of f : (vector -> vector) at x along v, backward ad. Namely, it calculates transpose ((jacobianv f x v)).

val jacobianTv' : (t -> t) -> t -> t -> t * t

similar to jacobianTv, but return (f x, transpose (jacobianv f x v))

val hessian : (t -> t) -> t -> t

hessian of f : (scalar -> scalar) at x.

val hessian' : (t -> t) -> t -> t * t

simiarl to hessian, but return (f x, hessian f x)

val hessianv : (t -> t) -> t -> t -> t

hessian vector product of f : (scalar -> scalar) at x along v. Namely, it calculates (hessian x) v.

val hessianv' : (t -> t) -> t -> t -> t * t

similar to hessianv, but return (f x, hessianv f x v).

val laplacian : (t -> t) -> t -> t

laplacian of f : (scalar -> scalar) at x.

val laplacian' : (t -> t) -> t -> t * t

similar to laplacian, but return (f x, laplacian f x).

val gradhessian : (t -> t) -> t -> t * t

return (grad f x, hessian f x), f : (scalar -> scalar)

val gradhessian' : (t -> t) -> t -> t * t * t

return (f x, grad f x, hessian f x)

val gradhessianv : (t -> t) -> t -> t -> t * t

return (grad f x v, hessian f x v)

val gradhessianv' : (t -> t) -> t -> t -> t * t * t

return (f x, grad f x v, hessian f x v)

include Owl_algodiff_ops_sig.Sig with type t := t and type elt := A.elt and type arr := A.arr and type op := op
module Builder : Owl_algodiff_ops_builder_sig.Sig with type t := t and type elt := A.elt and type arr := A.arr and type op := op
Supported Maths functions
module Maths : sig ... end
Supported Linalg functions
module Linalg : sig ... end
Supported Neural Network functions
module NN : sig ... end
Supported Mat functions
module Mat : sig ... end
Supported Arr functions
module Arr : sig ... end
Helper functions
include Owl_algodiff_graph_convert_sig.Sig with type t := t
val to_trace : t list -> string

to_trace [t0; t1; ...] outputs the trace of computation graph on the terminal in a human-readable format.

val to_dot : t list -> string

to_dot [t0; t1; ...] outputs the trace of computation graph in the dot file format which you can use other tools further visualisation, such as Graphviz.

val pp_num : Stdlib.Format.formatter -> t -> unit

pp_num t pretty prints the abstract number used in Algodiff.