fork download
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2.  
  3. ;;; perceptron learning - single-layer neural networks
  4.  
  5. ;;; make-perceptron returns a one-layer network with m units, n inputs each
  6.  
  7. (defun make-perceptron (n m &optional (g #'(lambda (i) (step-function 0 i)))
  8. &aux (l nil))
  9. (dotimes (i m (list l))
  10. (push (make-unit :parents (iota (1+ n))
  11. :children nil
  12. :weights (random-weights (1+ n) -0.5 +0.5)
  13. :g g)
  14. l)))
  15.  
  16. (defun majority-perceptron (n &optional (g #'(lambda (i) (step-function 0 i))))
  17. (list (list (make-unit :parents (iota (1+ n))
  18. :children nil
  19. :weights (cons (/ n 4)
  20. (make-list n :initial-element 0.5))
  21. :g g))))
  22.  
  23.  
  24. ;;; perceptron-learning is the standard "induction algorithm"
  25. ;;; and interfaces to the learning-curve functions
  26.  
  27. (defun perceptron-learning (problem)
  28. (nn-learning problem
  29. (make-perceptron
  30. (length (learning-problem-attributes problem))
  31. (length (learning-problem-goals problem)))
  32. #'perceptron-update))
  33.  
  34. ;;; Perceptron updating - simple version without lower bound on delta
  35. ;;; Hertz, Krogh, and Palmer, eq. 5.19 (p.97)
  36.  
  37. (defun perceptron-update (perceptron actual-inputs predicted target
  38. &optional (learning-rate 0.1)
  39. &aux (all-inputs (cons -1 actual-inputs)))
  40. (mapc #'(lambda (unit predicted-i target-i)
  41. (mapl #'(lambda (weights inputs)
  42. (incf (car weights)
  43. (* learning-rate
  44. (- target-i predicted-i)
  45. (car inputs))))
  46. (unit-weights unit) all-inputs))
  47. (car perceptron) predicted target)
  48. perceptron)
  49.  
  50.  
Runtime error #stdin #stdout 0.02s 3028KB
stdin
Standard input is empty
stdout
[EXPRNPSR3] Missing function declaration for defun.

[EXPRNPSR3] Missing function declaration for defun.

[EXPRNPSR3] Missing function declaration for defun.

[EXPRNPSR3] Missing function declaration for defun.