Skip to content

mattmazzola/perceptron

Repository files navigation

perceptron

Build Status NPM Version NPM Total Downloads NPM Monthly Downloads

Perceptron library written in TypeScript

Installation

npm install --save @mattmazzola/perceptron

Usage

const and = new Perceptron(0.5, 0.1);

const learningData = and.train([
  { vector: [0,0], output: false },
  { vector: [1,0], output: false },
  { vector: [0,1], output: false },
  { vector: [1,1], output: true }
]);

and.perceive([0,1]); // false

Learning Data

The Perceptron.train function returns the learning data array which contains data useful for debugging how the perceptron trained itelf. Each element contains the input vector, weights, and shows how they changed during the train period.

Example

const learningData = and.train([
  { vector: [0,0], output: false },
  { vector: [1,0], output: false },
  { vector: [0,1], output: false },
  { vector: [1,1], output: true }
]);

learningData
  .forEach(({vector, weights, dotProduct, result, threshold, output}) => {
    console.log(`Vector: ${vector}, Weights: ${weights}, Output: ${dotProduct} - ${result}, Expected: ${threshold} - ${output}`);
  });