Brain.js

Brain.js هي مكتبة JavaScript تسهل فهم الشبكات العصبية لأنها تخفي تعقيد الرياضيات.

بناء شبكة عصبية

بناء شبكة عصبية باستخدام Brain.js:

مثال:

// Create a Neural Network
const network = new brain.NeuralNetwork();

// Train the Network with 4 input objects
network.train([
 {input:[0,0], output:{zero:1}},
 {input:[0,1], output:{one:1}},
 {input:[1,0], output:{one:1},
 {input:[1,1], output:{zero:1},
]);

// What is the expected output of [1,0]?
result = network.run([1,0]);

// Display the probability for "zero" and "one"
... result["one"] + " " + result["zero"];

شرح المثال:

يتم إنشاء الشبكة العصبية باستخدام:new brain.NeuralNetwork()

تم تدريب الشبكة معnetwork.train([examples])

تمثل الأمثلة 4 قيم إدخال مع قيمة إخراج مقابلة.

مع network.run([1,0])، تسأل "ما هو الناتج المحتمل لـ [1،0]؟"

الجواب من الشبكة هو:

  • واحد: 93٪ (قريب من 1)
  • صفر: 6٪ (قريب من 0)

كيفية توقع التباين

باستخدام CSS ، يمكن ضبط الألوان بواسطة RGB:

مثال

Color RGB
BlackRGB(0,0,0)
YellowRGB(255,255,0)
RedRGB(255,0,0)
WhiteRGB(255,255,255)
Light GrayRGB(192,192,192)
Dark GrayRGB(65,65,65)

يوضح المثال أدناه كيفية التنبؤ بظلام اللون:

مثال:

// Create a Neural Network
const net = new brain.NeuralNetwork();

// Train the Network with 4 input objects
net.train([
// White RGB(255, 255, 255)
{input:[255/255, 255/255, 255/255], output:{light:1}},
// Light grey (192,192,192)
{input:[192/255, 192/255, 192/255], output:{light:1}},
// Darkgrey (64, 64, 64)
{ input:[65/255, 65/255, 65/255], output:{dark:1}},
// Black (0, 0, 0)
{ input:[0, 0, 0], output:{dark:1}},
]);

// What is the expected output of Dark Blue (0, 0, 128)?
let result = net.run([0, 0, 128/255]);

// Display the probability of "dark" and "light"
... result["dark"] + " " + result["light"];

شرح المثال:

يتم إنشاء الشبكة العصبية باستخدام:new brain.NeuralNetwork()

تم تدريب الشبكة معnetwork.train([examples])

تمثل الأمثلة 4 قيم إدخال ذات قيمة إخراج مقابلة.

مع network.run([0,0,128/255])، تسأل "ما هو الناتج المحتمل للأزرق الداكن؟"

الجواب من الشبكة هو:

  • الظلام: 95٪
  • ضوء: 4٪

لماذا لا تقوم بتحرير المثال لاختبار الناتج المحتمل باللون الأصفر أو الأحمر؟