anchor.diff:    (unless (boundp '*test-images*)
       (setq *test-images* (load-test)))
     (flet ((train-dbn ()
  -           (init-mnist-dbn *dbn/2* :stddev '(0.001 0.01))
  -           (train-mnist-dbn *dbn/2* :n-epochs 100 :n-gibbs '(1 5)
  -                            :learning-rate '(0.05 0.01)
  -                            :decay 0.001 :visible-sampling t)
  +           (load-weights (merge-pathnames "mnist-2.dbn" *mnist-dir*) *dbn/2*)
  +           (init-mnist-dbn *dbn/2* :stddev '(0.001 0.01) :start-level 1)
  +           ;;(init-mnist-dbn *dbn/2* :stddev '(0.001 0.01) :start-level 0)
  +           (train-mnist-dbn
  +            *dbn/2*
  +            :start-level 1
  +            :n-epochs 100
  +            :n-gibbs (list 1
  +                           (lambda (trainer)
  +                             (ceiling (1+ (n-inputs trainer))
  +                                      (* 20 (length *training-images*)))))
  +            :learning-rate
  +            (list (flt 0.05)
  +                  (lambda (trainer)
  +                    (/ (flt 0.05)
  +                       (ceiling (1+ (n-inputs trainer))
  +                                (* 20 (length *training-images*))))))
  +            :decay 0.001
  +            :visible-sampling t)
              (save-weights (merge-pathnames "mnist-2.dbn" *mnist-dir*)
                            *dbn/2*))
            (train-dbm ()
  
positive.code:                         (setf (aref nodes (+ start (image-label image)))
                                #.(flt 1)))))))))
  
  (defmethod set-input (images (rbm mnist-rbm/2))
    (call-next-method)
    ;; All samples have the same SAMPLE-VISIBLE-P, look at the first
    ;; only.
    (when (and images (getf (rest (elt images 0)) :sample-visible-p))
      (sample-visible rbm))
    (let ((label-chunk (find-chunk 'label rbm)))
      (when label-chunk
        (clamp-labels images label-chunk))))
  
negative.code:     (reset-counter counter)))
  
  (defmethod log-test-error ((trainer mnist-dbm-trainer) (dbm mnist-dbm))
    (describe-trainer trainer)
    (unless (zerop (n-inputs trainer))
      (log-msg "DBM TEST RMSE: ~{~,5F~^, ~} (~D)~%"
               (map 'list
                    #'get-error
                    (bm-mean-field-errors (make-sampler *test-images*
                                                        :max-n #+nil
                                                        1000
                                                        (length *test-images*))
                                          dbm))
               (n-inputs trainer))
      (let ((counters-and-measurers
             (make-bm-reconstruction-misclassification-counters-and-measurers dbm)))
        (when counters-and-measurers
          (let ((errors (map 'list
                             #'get-error
                             (bm-mean-field-errors (make-sampler *test-images*
                                                                 :max-n #+nil
                                                                 1000
                                                                 (length
                                                                  *test-images*)
                                                                 :omit-label-p t)
                                                   dbm
                                                   :counters-and-measurers
                                                   counters-and-measurers))))
            (log-msg "DBM TEST CLASSIFICATION ACCURACY: ~{~,2F%~^, ~} (~D)~%"
                     (mapcar (lambda (e)
                               (* 100 (- 1 e)))
                             errors)
                     (n-inputs trainer)))))))
  
  (defmethod positive-phase :around (batch trainer (dbm mnist-dbm))
    (call-next-method)
    (set-visible-mean dbm)
    (multiple-value-call #'add-error (counter trainer)
                         (reconstruction-rmse
                          (remove-if (lambda (chunk)
                                       (typep chunk 'labeled))
                                     (visible-chunks dbm)))))
  
  (defclass mnist-dbm-segment-trainer (batch-gd-trainer) ())
  
  