Brain.js
Brain.jsเป็นไลบรารี JavaScript ที่ทำให้ Neural Networks เข้าใจได้ง่าย เนื่องจากมันซ่อนความซับซ้อนของคณิตศาสตร์
การสร้างโครงข่ายประสาทเทียม
การสร้างโครงข่ายประสาทเทียมด้วย 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 |
---|---|
Black | RGB(0,0,0) |
Yellow | RGB(255,255,0) |
Red | RGB(255,0,0) |
White | RGB(255,255,255) |
Light Gray | RGB(192,192,192) |
Dark Gray | RGB(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%
ทำไมไม่แก้ไขตัวอย่างเพื่อทดสอบผลลัพธ์ที่น่าจะเป็นของสีเหลืองหรือสีแดง