forked from csxiaoyaojianxian/JavaScriptStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (32 loc) · 818 Bytes
/
script.js
File metadata and controls
35 lines (32 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* @Author: victorsun
* @Date: 2019-12-04 20:15:29
* @LastEditors: victorsun - csxiaoyao
* @LastEditTime: 2020-03-21 08:51:39
* @Description: [email protected]
*/
import * as tf from '@tensorflow/tfjs';
// tensor 张量
// 存储神经元,使用 tensor
/**
* 传统 for 循环方式
*/
// 输入,如五官、身材、家境等
const input = [1, 2, 3, 4];
// 神经元权重
const w = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]];
// 输出
const output = [0, 0, 0, 0];
// 循环神经元
for (let i = 0; i < w.length; i++) {
for (let j = 0; j < input.length; j++) {
output[i] += input[j] * w[i][j];
}
}
// 每个神经元等值
console.log(output); // [30, 40, 50, 60]
/**
* tensor方式
* 语法简洁,GPU加速
*/
tf.tensor(w).dot(tf.tensor(input)).print();