anchor.diff:    (declare (ignore dbm))
     (when (next-method-p)
       (call-next-method))
  -  (set-input (sample-batch (make-sampler *training-images*
  -                                         :max-n (length *training-images*)
  -                                         :sample-visible-p t)
  +  (set-input (sample-batch (make-sampler (training trainer) :sample-visible-p t)
                              (n-particles learner))
                (persistent-chains learner))
     (up-dbm (persistent-chains learner)))
   
  -(defun train-mnist-dbm (dbm &key (n-epochs 500))
  +(defun train-mnist-dbm (dbm training test &key (n-epochs 500))
     (log-msg "Starting to train DBM.~%")
  -  (train (make-sampler *training-images*
  -                       :max-n (* n-epochs (length *training-images*))
  -                       :sample-visible-p t)
  -         (make-instance 'mnist-dbm-trainer
  -                        :segmenter
  -                        (lambda (cloud)
  -                          (make-instance 'mnist-dbm-segment-trainer
  -                                         :learning-rate (flt 0.001)
  -                                         :weight-decay
  -                                         (if (conditioning-cloud-p cloud)
  -                                             (flt 0)
  -                                             (flt 0.0002))
  -                                         :batch-size 100)))
  -         (make-instance 'bm-pcd-learner
  -                        :bm dbm
  -                        :n-particles 100
  -                        :visible-sampling t
  -                        :n-gibbs 5
  -                        :sparser
  -                        (lambda (cloud chunk)
  -                          (when (and (member (name chunk) '(f1 f2))
  -                                     (not (equal 'label (name (chunk1 cloud))))
  -                                     (not (equal 'label (name (chunk2 cloud)))))
  -                            (make-instance
  -                             'cheating-sparsity-gradient-source
  -                             :cloud cloud
  -                             :chunk chunk
  -                             :sparsity (flt (if (eq 'f2 (name chunk))
  -                                                0.1
  -                                                0.2))
  -                             :cost (flt 0.001)
  -                             :damping (flt 0.9)))))))
  +  (let ((n (length training)))
  +    (train (make-sampler training :max-n (* n-epochs n) :sample-visible-p t)
  +           (make-instance 'mnist-dbm-trainer
  +                          :training training
  +                          :test test
  +                          :segmenter
  +                          (lambda (cloud)
  +                            (make-instance 'mnist-dbm-segment-trainer
  +                                           :n-inputs-in-epoch n
  +                                           :learning-rate (flt 0.001)
  +                                           :weight-decay
  +                                           (if (conditioning-cloud-p cloud)
  +                                               (flt 0)
  +                                               (flt 0.0002))
  +                                           :batch-size 100)))
  +           (make-instance 'bm-pcd-learner
  +                          :bm dbm
  +                          :n-particles 100
  +                          :visible-sampling t
  +                          :n-gibbs 5
  +                          :sparser
  +                          (lambda (cloud chunk)
  +                            (when (and (member (name chunk) '(f1 f2))
  +                                       (not (equal 'label
  +                                                   (name (chunk1 cloud))))
  +                                       (not (equal 'label
  +                                                   (name (chunk2 cloud)))))
  +                              (make-instance
  +                               'cheating-sparsity-gradient-source
  +                               :cloud cloud
  +                               :chunk chunk
  +                               :sparsity (flt (if (eq 'f2 (name chunk))
  +                                                  0.1
  +                                                  0.2))
  +                               :cost (flt 0.001)
  +                               :damping (flt 0.9))))))))
   
   (defun make-mnist-dbn/2 (dbm)
     (mgl-bm:dbm->dbn dbm :dbn-class 'mnist-dbn :rbm-class 'mnist-rbm/2
  
positive.code:                               (eq (name lump) 'prediction-weights))))
           (make-instance 'bp-learner :bpn bpn))
    (log-msg "Starting to train the whole BPN~%")
    (train (make-sampler *training-images*
                         :max-n (* (- n-epochs n-softmax-epochs)
                                   (length *training-images*))
                         :omit-label-p t)
           (make-instance 'mnist-cg-bp-trainer
                          :cg-args (list :max-n-line-searches 3)
                          :batch-size batch-size)
           (make-instance 'bp-learner :bpn bpn)))
  
negative.code:                                       (log-msg "populated: ~S~%" n))))))
      (unless (populate-map-cache-lazily-from-dbm *bpn/2*)
        (log-msg "Populating MAP cache~%")
        (populate-map-cache *bpn/2* *dbm/2* (concatenate 'vector (training-images)
                                                         (test-images))
                            :if-exists :error))
      (cond (dropoutp
             (train-mnist-bpn-gd *bpn/2*
  