Perceptron

Overview


Example Calculations


The value of a perceptron can be calculated using the linear algebra library.


let la = await import('/lib/liniear-albgebra/v1.0.0/linear-algebra.mjs');

let inputs = [1, 0.5, 0.7, 0];
let weights = [0.1, 0.5, 0.2, 0.2]

let calculate = function(inputs, weights){

  let value = la.multiply([weights], inputs.map(p=>[p]))[0][0];
  if(value >=0)return 1;
  else return -1;
}

let y = calculate(inputs, weights);
					


Library


The perceptron library located at


/lib/machine-learning/perceptron/v1.0.0/perceptron.mjs
					


The following example demonstrates using the percentron library.


let pt = await import('/lib/machine-learning/perceptron/v1.0.0/perceptron.js');
let data= [
	{x1:-1,x2:-1, y:0},
	{x1:-5,x2:-2.5, y:0},
	{x1:-7.5,x2:-1.5, y:0},
	{x1:10,x2:7.5, y:1},
	{x1:-2.5,x2:12.5, y:0},
	{x1:5,x2:10, y:1},
	{x1:5,x2:5, y:1},
]

let w= [[0],[0],[0]]

let data2 = data.map(p=>{
	return {x:[1,p.x1, p.x2], y:[p.y]};
});

w = pt.iterate(data2,w);
w = pt.iterate(data2,w);
w = pt.iterate(data2,w);
w = pt.iterate(data2,w);
w = pt.iterate(data2,w);
w = pt.iterate(data2,w);
					
Try it!

Contents