;;; A simple function that makes a list of length len with
;;;   each element being element
;;; Example: (setf weights (make-nlist 25 1.0))
(defun make-nlist (len element)		
  (let ((ret nil))
    (dotimes (i len ret) (push element ret))))

;;; A simple function that makes a list of length len with
;;;   each element being 0 - (len - 1)
;;; Example: (setf attributes (make-clist 10))
(defun make-clist (len)		
  (let ((ret nil))
    (dotimes (i len ret) (push i ret))))

;;; A simple function that returns a list of:
;;;   %incorrect, %positives incorrect, %negatives incorrect
;;; It would probably be better named evaluate-classifier but it *is*
;;;   evaluating how good your learner was at generating a
;;;   classifier. It's a toss-up.
(defun evaluate-learner (classifier test-set test-answers)
  (let ((f 0)
	(fp 0)
	(fn 0)
	(np 0)
	(nn 0)
	(pairs (mapcar #'(lambda (e a) (list e a)) test-set test-answers)))
    (dolist (pair pairs (list (/ f (+ np nn)) (/ fp np) (/ fn nn)))
      (let* ((prediction (funcall classifier (first pair)))
	     (answer (second pair)))
	(if answer 
	    (incf np)
	  (incf nn))
	(unless (equal prediction answer)
	  (incf f)
	  (if answer
	      (incf fp)
	    (incf fn)))))))

;;;; a simple classification problem:
;;;; can you guess what the true function is?
;;;; The answer is in utils-gen.lisp
;;;; http://www.cc.gatech.edu/~isbell/classes/cs4600_fall/projects/project5/utils-gen.lisp

;; Notice the use of defvar.  defvar is like (setf) or (setq) except that
;; it doesn't change the value of the variable if it has already been
;; set.  This is convenient for setting default values but can cause bugs
;; for the unexperienced if you decided to change your default and don't
;; use (setf) or reload your LISP.  You might want to use (setf) while
;; debugging and change to (defvar) before turning your code in.
(defvar *sample-training-examples*
  (list 
   #(1 0 0 1 0 0)
   #(1 1 1 0 0 0)
   #(0 1 1 1 0 1)
   #(1 1 0 1 1 1)
   #(1 0 0 1 1 0)
   #(1 0 1 1 0 0)
   #(1 1 1 1 1 0)
   #(0 1 0 1 1 1)
   #(0 0 0 1 0 0)
   #(1 1 1 1 0 0)
   #(0 1 1 0 1 0)
   #(0 0 1 0 0 1)
   #(1 1 0 1 1 0)
   #(0 0 1 0 1 0)
   #(0 0 1 1 0 1)
   #(0 1 0 1 1 0)
   #(0 0 1 0 1 1)
   #(1 1 1 1 1 1)
   #(1 1 0 1 0 0)
   #(1 0 0 0 1 1)
   #(1 0 1 0 0 1)
   #(0 0 1 1 1 1)
   #(1 0 0 1 1 1)
   #(1 0 1 1 1 0)
   #(0 0 1 1 0 0)
   #(1 1 1 0 1 1)
   #(1 1 0 0 1 1)
   #(0 0 0 0 0 1)
   #(0 1 0 0 1 0)
   #(1 1 0 0 0 1)
   #(1 0 0 0 0 1)
   #(0 0 0 0 1 1)
   #(0 1 1 1 0 0)
   #(0 0 1 0 0 0)
   #(1 0 1 1 1 1)
   #(1 0 0 0 1 0)
   #(1 1 0 0 0 0)
   #(1 1 0 1 0 1)
   #(0 1 0 0 0 0)
   #(1 0 1 0 1 1)
   #(0 0 0 1 1 1)
   #(0 0 1 1 1 0)
   #(0 1 1 1 1 1)
   #(0 1 0 1 0 1)))

(defvar *sample-test-examples*
  (list 
   #(1 0 1 1 0 1)
   #(0 1 1 0 0 1)
   #(0 1 1 0 1 1)
   #(1 1 0 0 1 0)
   #(0 0 0 1 1 0)
   #(1 0 0 0 0 0)
   #(1 0 1 0 1 0)
   #(0 1 0 0 1 1)
   #(1 0 0 1 0 1)
   #(1 1 1 1 0 1)
   #(0 0 0 0 0 0)
   #(0 1 1 1 1 0)
   #(0 1 1 0 0 0)
   #(1 1 1 0 0 1)
   #(1 1 1 0 1 0)
   #(0 1 0 0 0 1)
   #(0 1 0 1 0 0)
   #(1 0 1 0 0 0)
   #(0 0 0 0 1 0)
   #(0 0 0 1 0 1)))

(defvar *sample-training-classes*
  (list T T NIL T NIL T T NIL T T T NIL T T NIL NIL NIL T T NIL NIL NIL NIL NIL T T T NIL T T NIL NIL T NIL NIL T T T NIL NIL NIL NIL NIL NIL))

(defvar *sample-test-classes*
  (list NIL NIL NIL T NIL NIL T NIL NIL T NIL NIL NIL T T NIL T NIL T NIL))