Editing
User:Kaufman/LISP Perceptron
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Over 3 days I taught myself just enough LISP to implement this. :) Copy the code block into your LISP interpreter (and hit enter, usually), and launch it by typing: (perceptron) <code><pre> (defun perceptron () (setq inputs (list (list 1 0 0) (list 1 0 1) (list 1 1 0) (list 1 1 1) )) (format t "inputs : ~a~%" inputs) (setq answers (list 1 1 1 0)) (format t "answers : ~a~%" answers) (setq weight (list 0.0 0.0 0.0)) (format t "starting weight : ~a~%" weight) (mainfunc inputs answers weight)) (defun mainfunc (inputs answer weight) (setq checked (check-all inputs weight answer)) (if (equal checked weight) weight (mainfunc inputs answer checked))) (defun check-all (inputs weight answer) (if (first inputs) (check-all (rest inputs) (check-product (first inputs) weight (first answer)) (rest answer)) weight)) (defun check-product (inputs weight answer) (if (> (dot-product inputs weight) 0.5) (setq error (- answer 1)) (setq error (- answer 0))) (if error (if (< error 0) (pushvalue inputs weight -0.1) (if (> error 0) (pushvalue inputs weight 0.1) weight)))) (defun dot-product (input weight) (setq product (map 'vector #'* input weight)) (setq sum (reduce #'+ product)) sum) (defun pushvalue (input weight direction) (if (first input) (progn (if (> (first input) 0) (setq newweight (+ (first weight) direction)) (setq newweight (first weight))) (setq returnweight (append (list newweight) (pushvalue (rest input) (rest weight) direction))) returnweight ))) </pre></code>
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
User page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
User contributions
Logs
View user groups
Special pages
Page information