# Algodiff.Generic Functor¶

This document is auto-generated for Owl’s APIs. #137 entries have been extracted.

Github: {Signature} {Implementation}

## Type definition¶

type trace_op


Trace type

type t =
| F    of A.elt                                           (* constructor of float numbers *)
| Arr  of A.arr                                           (* constructor of ndarrays *)
| DF   of t * t * int                                     (* primal, tangent, tag *)
| DR   of t * t ref * trace_op * int ref * int * int ref  (* primal, adjoint, op, fanout, tag *)


Abstract number type

## Supported Maths functions¶

val ( + )  : t -> t -> t


Refer to Dense.Ndarray.Generic

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


Refer to Dense.Ndarray.Generic

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


Refer to Dense.Ndarray.Generic

val ( / )  : t -> t -> t


Refer to Dense.Ndarray.Generic

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


Refer to Dense.Ndarray.Generic

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


Refer to Dense.Ndarray.Generic

val add : t -> t -> t


Refer to Dense.Ndarray.Generic

val sub : t -> t -> t


Refer to Dense.Ndarray.Generic

val mul : t -> t -> t


Refer to Dense.Ndarray.Generic

val div : t -> t -> t


Refer to Dense.Ndarray.Generic

val dot : t -> t -> t


Refer to Dense.Ndarray.Generic

val pow : t -> t -> t


Refer to Dense.Ndarray.Generic

val atan2 : t -> t -> t


Refer to Dense.Ndarray.Generic

val min2 : t -> t -> t


Refer to Dense.Ndarray.Generic

val max2 : t -> t -> t


Refer to Dense.Ndarray.Generic

val cross_entropy : t -> t -> t


Refer to Dense.Ndarray.Generic

val inv : t -> t


Refer to Dense.Ndarray.Generic

val chol : ?upper:bool -> t -> t


Refer to Dense.Ndarray.Generic

val qr : t -> t * t


Refer to Dense.Ndarray.Generic

val svd : ?thin:bool -> t -> t * t * t


Refer to Dense.Ndarray.Generic

val lyapunov : t -> t -> t


Refer to Dense.Ndarray.Generic

val neg : t -> t


Refer to Dense.Ndarray.Generic

val abs : t -> t


Refer to Dense.Ndarray.Generic

val signum : t -> t


Refer to Dense.Ndarray.Generic

val floor : t -> t


Refer to Dense.Ndarray.Generic

val ceil : t -> t


Refer to Dense.Ndarray.Generic

val round : t -> t


Refer to Dense.Ndarray.Generic

val sqr : t -> t


Refer to Dense.Ndarray.Generic

val sqrt : t -> t


Refer to Dense.Ndarray.Generic

val log : t -> t


Refer to Dense.Ndarray.Generic

val log2 : t -> t


Refer to Dense.Ndarray.Generic

val log10 : t -> t


Refer to Dense.Ndarray.Generic

val exp : t -> t


Refer to Dense.Ndarray.Generic

val sin : t -> t


Refer to Dense.Ndarray.Generic

val cos : t -> t


Refer to Dense.Ndarray.Generic

val tan : t -> t


Refer to Dense.Ndarray.Generic

val sinh : t -> t


Refer to Dense.Ndarray.Generic

val cosh : t -> t


Refer to Dense.Ndarray.Generic

val tanh : t -> t


Refer to Dense.Ndarray.Generic

val asin : t -> t


Refer to Dense.Ndarray.Generic

val acos : t -> t


Refer to Dense.Ndarray.Generic

val atan : t -> t


Refer to Dense.Ndarray.Generic

val asinh : t -> t


Refer to Dense.Ndarray.Generic

val acosh : t -> t


Refer to Dense.Ndarray.Generic

val atanh : t -> t


Refer to Dense.Ndarray.Generic

val sum' : t -> t


Refer to Dense.Ndarray.Generic

val sum : ?axis:int -> t -> t


Refer to Dense.Ndarray.Generic

val sum_reduce : ?axis:int array -> t -> t


Refer to Dense.Ndarray.Generic

val mean : t -> t


Refer to Dense.Ndarray.Generic

source code

val transpose : t -> t


Refer to Dense.Ndarray.Generic

val l1norm' : t -> t


Refer to Dense.Ndarray.Generic

val l2norm' : t -> t


Refer to Dense.Ndarray.Generic

val l2norm_sqr' : t -> t


Refer to Dense.Ndarray.Generic

val sigmoid : t -> t


Refer to Dense.Ndarray.Generic

val relu : t -> t


Refer to Dense.Ndarray.Generic

val softplus : t -> t


Refer to Dense.Ndarray.Generic

val softsign: t -> t


Refer to Dense.Ndarray.Generic

val softmax : ?axis:int -> t -> t


Refer to Dense.Ndarray.Generic

val dropout : ?rate:float -> t -> t


Refer to Dense.Ndarray.Generic

val conv1d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val conv2d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val conv3d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val dilated_conv1d : ?padding:padding -> t -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val dilated_conv2d : ?padding:padding -> t -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val dilated_conv3d : ?padding:padding -> t -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val transpose_conv1d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val transpose_conv2d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val transpose_conv3d : ?padding:padding -> t -> t -> int array -> t


Refer to Dense.Ndarray.Generic

val max_pool1d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val max_pool2d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val max_pool3d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val avg_pool1d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val avg_pool2d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val avg_pool3d : padding -> t -> int array -> int array -> t


Refer to Dense.Ndarray.Generic

val upsampling2d : t -> int array -> t


Refer to Dense.Ndarray.Generic

val pad : ?v:A.elt -> int list list -> t -> t


Refer to Dense.Ndarray.Generic

val reshape : t -> int array -> t


Refer to Dense.Ndarray.Generic

val flatten : t -> t


Refer to Dense.Ndarray.Generic

val concat : int -> t -> t -> t


Refer to Dense.Ndarray.Generic

val get_slice : int list list -> t -> t


Refer to Dense.Ndarray.Generic

val set_slice : int list list -> t -> t -> t


Refer to Dense.Ndarray.Generic

val diag : ?k:int -> t -> t


Refer to Dense.Ndarray.Generic

val diagm : ?k:int -> t -> t


Refer to Dense.Ndarray.Generic

val trace : t -> t


Refer to Dense.Ndarray.Generic

val triu: ?k:int -> t -> t


Refer to Dense.Ndarray.Generic

val tril: ?k:int -> t -> t


Refer to Dense.Ndarray.Generic

## Core functions¶

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 |> ...

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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

source code

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


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

source code

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)).

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

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


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

source code

## Low-level functions¶

val pack_elt : A.elt -> t


convert from elt type to t type.

source code

val unpack_elt : t -> A.elt


convert from t type to elt type.

source code

val pack_flt : float -> t


convert from float type to t type.

source code

val unpack_flt : t -> float


convert from t type to float type.

source code

val pack_arr : A.arr -> t


convert from arr type to t type.

source code

val unpack_arr : t -> A.arr


convert from t type to arr type.

source code

val tag : unit -> int


TODO

source code

val primal : t -> t


TODO

source code

val primal' : t -> t


TODO

val adjval : t -> t


TODO

source code

val adjref : t -> t ref


TODO

source code

val tangent : t -> t


TODO

source code

val make_forward : t -> t -> int -> t


TODO

source code

val make_reverse : t -> int -> t


TODO

source code

val reverse_prop : t -> t -> unit


TODO

source code

val type_info : t -> string


TODO

source code

val shape : t -> int array


TODO

val copy_primal' : t -> t


TODO

source code

val _f : float -> t


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

source code

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


other functions, without tracking gradient

source code

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


other functions, without tracking gradient

source code

## Helper functions¶

val to_trace : t list -> string


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

source code

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.

source code

val pp_num : Format.formatter -> t -> unit [@@ocaml.toplevel_printer]


pp_num t pretty prints the abstract number used in Algodiff.

source code