12345678910111213141516171819202122232425262728293031323334 |
- (load "test-framework")
- (defstruct perceptron theta weights)
- (defun compute-class (perceptron inputs)
- (> (+ (perceptron-theta perceptron)
- (dot-product (perceptron-weights perceptron)
- inputs))
- 0.0))
- (defun dot-product (vector-1 vector-2)
- (apply #'+ (mapcar #'* vector-1 vector-2)))
- (defun bad-dot-product (vector-1 vector-2)
- (apply #'* (mapcar #'+ vector-1 vector-2)))
- (def-unit-tests
- dp1 ()
- (test (= 11 (dot-product '(1 2) '(3 4))) "test dp 1")
- (assert= 3 (dot-product '(1 0) '(3 4)) "test dp 2")
- (test (= 11 (bad-dot-product '(1 2) '(3 4))) "bad-dp"))
- (def-process-tests
- perceptron1 ()
- (let ((p (make-perceptron :theta 0.5 :weights '(0.2 0.7))))
- (assert-true (compute-class p '(3 4)))))
- (def-canonical-result-tests
- cr1 ()
- (let ((p (make-perceptron :theta 0.5 :weights '(0.2 0.7))))
- (assert-true (and (compute-class p '(0 1))
- (not (compute-class p '(0 -1)))))))
|