anchor.diff:                                     :learning-rate (flt 1)
                                      :learning-rate-decay (flt 0.998)
                                      :l2-upper-bound nil
  +                                   :set-dropout-p t
                                      :rescale-on-dropout-p t)
                  (unless quick-run-p
                    (save-weights bpn-filename bpn)))
  
positive.code:              (* final weight)))
          final)))
  
  (defun make-grouped-segmenter (name-groups segmenter)
    (let ((group-to-trainer (make-hash-table :test #'equal)))
      (lambda (segment)
        (let* ((name (name segment))
               (group (find-if (lambda (names)
                                 (member name names :test #'name=))
                               name-groups)))
          (assert group () "Can't find group for ~S." name)
          (or (gethash group group-to-trainer)
              (setf (gethash group group-to-trainer)
                    (funcall segmenter segment)))))))
  
  (defun train-mnist-bpn-gd (bpn training test &key (n-softmax-epochs 5)
                             (n-epochs 200) l2-upper-bound
                             class-weights learning-rate learning-rate-decay
                             rescale-on-dropout-p)
    (when class-weights
      (setf (class-weights (find-lump 'predictions bpn)) class-weights))
    (setf (max-n-stripes bpn) 100)
    (let ((name-groups '(((:cloud (c0 f1))
                          (:cloud (inputs f1))
                          (:bias f1)
                          (inputs f1))
                         ((:cloud (c1 f2))
                          (:cloud (f1 f2))
                          (:bias f2)
                          (f1 f2))
                         ((:cloud (c2 f3))
                          (:cloud (f2 f3))
                          (:bias f3)
                          (f2 f3))
                         ;; for mnist/3
                         ((:bias predictions)
                          (f3 predictions))
                         ;; for mnist/4
                         ((:bias predictions)
                          (f2 predictions)))))
      (flet ((make-trainer (lump &key softmaxp)
               (declare (ignore lump))
               (let ((trainer (make-instance
                               'mnist-bpn-gd-segment-trainer
                               :n-inputs-in-epoch (length training)
                               :n-epochs-to-reach-final-momentum
                               (min 500
                                    (/ (if softmaxp n-softmax-epochs n-epochs)
                                       2))
                               :learning-rate (flt learning-rate)
                               :learning-rate-decay (flt learning-rate-decay)
                               :batch-size 100)))
                 (when l2-upper-bound
                   (arrange-for-renormalizing-activations
                    bpn trainer l2-upper-bound))
                 trainer))
             (make-segmenter (fn)
               (if l2-upper-bound
                   (make-grouped-segmenter name-groups fn)
                   fn)))
        (unless (zerop n-softmax-epochs)
          (log-msg "Starting to train the softmax layer of BPN~%")
          (train (make-sampler training :n-epochs n-softmax-epochs)
                 (make-instance 'mnist-bpn-gd-trainer
                                :training training
                                :test test
                                :segmenter
                                (make-segmenter
                                 (lambda (lump)
                                   (when (prediction-weight-p lump)
                                     (make-trainer lump :softmaxp t)))))
                 (make-instance 'bp-learner :bpn bpn)))
        (map nil (lambda (lump)
                   (when (and (typep lump '->dropout)
                              (not (typep lump '->input)))
  
negative.code: (defun build-maxout-mnist-bpn (&key (n-units-1 1200) (n-units-2 1200)
                                 (group-size 5))
    (build-bpn (:class 'mnist-bpn :max-n-stripes 100)
      (inputs (->input :size 784 :dropout (flt 0.2)))
      (f1-activations (add-activations :name 'f1 :inputs '(inputs)
                                       :size n-units-1))
      (f1* (->max :x f1-activations :group-size group-size))
      (f1 (->dropout :x f1* :dropout (flt 0.5)))
      (f2-activations (add-activations :name 'f2 :inputs '(f1) :size n-units-2))
      (f2* (->max :x f2-activations :group-size group-size))
      (f2 (->dropout :x f2* :dropout (flt 0.5)))
      (predictions (tack-cross-entropy-softmax-error-on
                    mgl-bp::*bpn-being-built* '(f2)))))
  
  