Code Monkey home page Code Monkey logo

perceptron's Introduction

Overview

This is a Python implementation of the Perceptron algorithm. I wanted to write my own artificial neural network to gain an understanding of how they work and started with the simplest one. I make use of no external libraries and the code, although easy to understand, is not very efficient. It uses .txt files!

A Perceptron is used to define a hyperplane which divides the input space into two half-spaces and can be used to make binary classification.

perceptron

About the files
  • perceptron.py : Python script used to run the algorithm.
  • constants.txt : Used to read constant values for the algorithm- number of input nodes, bias factor and learning rate.
  • trainingData.txt : Each line contains an input vector + subsequent output, used to train the perceptron.
  • testingData.txt : Each line contains an input vector for which the classification has to be made.
  • weights.txt : Used to read weights for each node of the input vector. Gets created/overwritten on training.
  • output.txt : Contains input vector + predicted output combinations for the test data.

Learning Boolean Functions

A boolean function is a two-class classification problem- the inputs are binary and the output is 1 if the corresponding function value is true and 0 otherwise.

Functions like AND and OR are linearly separable and are solvable using the perceptron. A perceptron implementing the AND function can be found in the /res folder. The OR can also be implemented by modifying the trainingData.txt file.

AND

Functions like XOR cannot be solved with the simple perceptron because their graphs are not linearly separable. Hence, there is no single line/hyperplane that can divide the input space into two classes. Note that a multilayer perceptron (MLP) can be used to solve problems like the XOR.

XOR

Usage

Modify the values in constants.txt, trainingData.txt and testingData.txt to your own data.

Then, train the perceptron algorithm using the following command (This will create/overwrite weights.txt):

python perceptron.py

Run the algorithm on the test data using the following command (This will create output.txt):

python perceptron.py test

perceptron's People

Contributors

chaitjo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.