-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneural.html
171 lines (135 loc) · 3.46 KB
/
neural.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
<script type="text/javascript" src = 'https://code.jquery.com/jquery-3.4.1.min.js'></script>
<meta charset="utf-8">
<canvas id = 'ca'></canvas>
<script type="text/javascript" src = 'net.js'></script>
<script type="text/javascript" src = 'initCanvas.js'></script>
<script type="text/javascript">
var net, go = true;
var alph = ['а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я'];
var gMatrix = [];
var gMatrix1 = [];
window.onload = function(){
initializtionCanvas();
var arr = new Array(33);
var arr1 = new Array(33);
net = new Net({data:arr},
{data:[[0,0,0,0,0,0,0,0]]},
{data:arr1},0.5);
net.draw();
}
function lrn(){
setInterval(update,100);
}
function detected(){
gMatrix = [];
var str = $('.inp1').val();
var t0 = new Array(33);
for(var i = 0; i < t0.length; ++i) t0[i] = 0;
for(var i = 0; i < str.length; ++i){
for(var j = 0; j < alph.length; ++j){
if(str[i] == alph[j]){
t0[j] = 1;
}
}
}
gMatrix.push(t0);
net.forward({input:gMatrix[0],output:gMatrix1[0]},false);
$('.inp2').val('');
for(var i = 0; i < net.output.data.length; ++i){
if(net.output.data[i] > 0.3){
$('.inp2').val($('.inp2').val() + alph[i]);
}
}
}
function mem(){
var str = $('.inp1').val();
var t0 = new Array(33);
for(var i = 0; i < t0.length; ++i) t0[i] = 0;
for(var i = 0; i < str.length; ++i){
for(var j = 0; j < alph.length; ++j){
if(str[i] == alph[j]){
t0[j] = 1;
}
}
}
gMatrix.push(t0);
str = $('.inp2').val();
for(var i = 0; i < t0.length; ++i) t0[i] = 0;
for(var i = 0; i < str.length; ++i){
for(var j = 0; j < alph.length; ++j){
if(str[i] == alph[j]){
t0[j] = 1;
}
}
}
gMatrix1.push(t0);
}
function update(){
if(go){
for(var i = 0; i < gMatrix.length; ++i){
net.forward({input:gMatrix[i],output:gMatrix1[i]},true);
}
net.update();
}
}
</script>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
table{
position: absolute;
z-index: 999;
top:40px;
width:800px;
border-collapse: collapse;
text-align: center;
left: 550px;
font-family: 'Tahoma';
}
table tr th{
width: 80px;
}
.d{
font-weight: normal;
}
.btn{
position: absolute;
padding: 3px;
font-family: 'Tahoma';
font-size:17px;
width:130px;
}
.inp{
position: absolute;
top:650px;
}
.inp1{
left:550px;
}
.inp2{
left:750px;
}
.memory{
left: 550px;
top:550px;
}
.learn{
left: 700px;
top:550px;
}
.detected{
left: 850px;
top:550px;
}
body{
}
</style>
<table border="1" width="100%" cellpadding="5"></table>
<input type="button" name="" value="Запомнить" onclick="mem()" class = 'memory btn'>
<input type="button" name="" value="Обучить" onclick="lrn()" class = 'learn btn'>
<input type="button" name="" value="Распознать" onclick="detected()" class = 'detected btn'>
<input type="" name="" class = 'inp1 inp'>
<input type="" name="" class = 'inp2 inp'>