TorchLean API

NN.Proofs.Models.Mlp

Closed MLP Model Facts #

Small rational MLP examples belong in the proof layer. The forward composition law is already proved generally by Examples.mlp_spec_forward_eq; the facts below state a deterministic backward calculation as coordinate-level Lean theorems.

@[reducible, inline]

Input width of the worked example: two features.

Instances For
    @[reducible, inline]

    Hidden width of the worked example: three ReLU units.

    Instances For
      @[reducible, inline]

      Output width of the worked example: one scalar prediction.

      Instances For

        Hidden weight matrix, with entries chosen as small rationals.

        Everything in this file is over , so the numbers below are exact and the examples at the end of the file close by simp alone. The same computation in Float would only be true up to rounding, which is the point of keeping the closed-form check separate from the runtime.

        Instances For

          Hidden bias of the worked example.

          Instances For

            Output weight row of the worked example. All entries are positive, so the single output unit is active and the backward pass exercises the interesting branch of reluDerivSpec.

            Instances For

              Output bias of the worked example.

              Instances For

                The hidden layer, packaging its weight and bias.

                Instances For

                  The output layer, packaging its weight and bias.

                  Instances For

                    The single input vector used by every example below.

                    Instances For

                      The two-layer network as a Chain, built by the general mlpSpec constructor.

                      Instances For

                        Output obtained by running the chain, that is, by the generic module forward pass.

                        Instances For

                          The same output written out by hand: linear, ReLU, linear.

                          Stating both and proving them equal is the whole point. It checks that Chain.forward really does compose the layers in the order a reader would expect, rather than only that it type-checks.

                          Instances For

                            Incoming cotangent, taken to be all ones so the backward pass reads off plain derivatives.

                            Instances For

                              Input gradient from the OpSpec backward pass, which composes per-operation adjoints instead.

                              Instances For

                                Input gradient projected out of exGrad, so the two routes can be compared directly.

                                Instances For