HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Neural Networks are used in applications like Facial Recognition
Imagine a strait line (a linear graph) in a space with scattered x y points.
How can you classify the points over and under the line?
// Line Function function f(x) { return x * 1.2 + 50; } // Create a Plotter let plotter = new XYPlotter("myCanvas1"); plotter.transformXY(); let xMax = plotter.xMax; let yMax = plotter.yMax; let xMin = plotter.xMin; let yMin = plotter.yMin; plotter.plotLine(xMin, f(xMin), xMax, f(xMax), "black"); // Create Random XY Points let numPoints = 500; let xPoints = []; let yPoints = []; for (let i = 0; i < numPoints; i++) { xPoints[i] = Math.random() * xMax; yPoints[i] = Math.random() * yMax; } plotter.plotPoints(numPoints, xPoints, yPoints, "blue");
A perceptron can be trained to recognize the points over the line, without knowing the formula for the line.
A Perceptron is often used to classify data into two parts.
A Perceptron is also known as a Linear Binary Classifier.
To learn more about how to program a perceptron, we will create a very simple JavaScript program that will:
Use the simple plotter object described in the AI Plotter Chapter.
const plotter = new XYPlotter("myCanvas");
plotter.transformXY();
const xMax = plotter.xMax;
const yMax = plotter.yMax;
const xMin = plotter.xMin;
const yMin = plotter.yMin;
Create as many xy points as wanted.
Let the x values be random, between 0 and maximum.
Let the y values be random, between 0 and maximum.
Display the points in the plotter:
const numPoints = 500;
const xPoints = [];
const yPoints = [];
for (let i = 0; i < numPoints; i++) {
xPoints[i] = Math.random() * xMax;
yPoints[i] = Math.random() * yMax;
}
Display the line in the plotter:
Compute the desired answers based on the line function:
y = x * 1.2 + 50.
The desired answer is 1 if y is over the line and 0 if y is under the line.
Store the desired answers in an array (desired[]).
let desired = [];
for (let i = 0; i < numPoints; i++) {
desired[i] = 0;
if (yPoints[i] > f(xPoints[i])) {desired[i] = 1;}
}
For each point, if desired[i] = 1 display a black point, else display a blue point.
for (let i = 0; i < numPoints; i++) {
let color = "blue";
if (desired[i]) color = "black";
plotter.plotPoint(xPoints[i], yPoints[i], color);
}
In the next chapters, you will learn more about how to Train the Perceptron