Example [efr-37F7]
Example [efr-37F7]
Let \mathsf {CartSp} denote the category of Cartesian spaces \mathbb {R}^n and smooth maps between them, which acts on itself by Cartesian product. Then there is a functor \mathsf {SmMfd} \to \mathsf {Optic}(\mathsf {SmMfd}) (= \mathsf {Lens}(\mathsf {SmMfd})) which carries \mathbb {R}^n to the pair {\mathbb {R}^n \choose \mathbb {R}^n} and a smooth map f: \mathbb {R}^n \to \mathbb {R}^m to the pair (f, Rf) where Rf: \mathbb {R}^n \times \R ^m \to \mathbb {R}^n is the reverse derivative, where Rf(x,-) : \mathbb {R}^m \to \mathbb {R}^n is the linear map given by the transpose of the Jacobian.
Moreover this is monoidal for the Hancock tensor on \mathsf {Optic}(\mathsf {CartSp}). Since \mathsf {Para}(-) is functorial, we obtain a functor \mathsf {Para}(\mathsf {CartSp}) \to \mathsf {Para}(\mathsf {Optic}(\mathsf {CartSp})). Given some parametrized (smooth) map X \times P \to Y, we obtain an optic {X \choose X} \otimes {P \choose P} \to {Y \choose Y}. After choosing x \in X and a section d: Y \to Y---for example, by sampling x,y^* from a dataset and letting d(y) be the gradient of (y-y^*)^2 at y---the resulting gradient P \to P describes how to update the parameters to move y in the desired direction. The fact that this is functorial is essentially the mechanism behind the backpropagation algorithm---see Reference [backprop-as-functor], Reference [bruno-etal-categorical-learning-2021] for more.
(Note that this construction can also be generalized to smooth manifolds, but one must pass to dependent lenses and use the cotangent manifold instead.)