package owl-base

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file owl_algodiff_generic_sig.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# 1 "src/base/algodiff/owl_algodiff_generic_sig.ml"
(*
 * OWL - OCaml Scientific Computing
 * Copyright (c) 2016-2022 Liang Wang <liang@ocaml.xyz>
 *)

module type Sig = sig
  include Owl_algodiff_core_sig.Sig

  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)] *)

  (* Operations *)
  include
    Owl_algodiff_ops_sig.Sig
      with type t := t
       and type elt := A.elt
       and type arr := A.arr
       and type op := op

  (** {5 Helper functions} *)

  include Owl_algodiff_graph_convert_sig.Sig with type t := t
end