File tree 2 files changed +30
-24
lines changed
2 files changed +30
-24
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ const net = new LSTM();
18
18
const mathProblems = [
19
19
'0+0=0' ,
20
20
'0+1=1' ,
21
- '1+0=2 ' ,
21
+ '1+0=1 ' ,
22
22
'0+2=2' ,
23
- '2+0=3 ' ,
23
+ '2+0=2 ' ,
24
24
'0+3=3' ,
25
25
'3+0=3' ,
26
26
'0+4=4' ,
@@ -108,22 +108,25 @@ const mathProblems = [
108
108
'6+9=15' ,
109
109
'9+6=15' ,
110
110
'7+7=14' ,
111
- '7+8=16 ' ,
112
- '8+7=16 ' ,
113
- '7+9=17 ' ,
114
- '9+7=17 ' ,
115
- '8+8=17 ' ,
116
- '8+9=18 ' ,
117
- '9+8=18 ' ,
111
+ '7+8=15 ' ,
112
+ '8+7=15 ' ,
113
+ '7+9=16 ' ,
114
+ '9+7=16 ' ,
115
+ '8+8=16 ' ,
116
+ '8+9=17 ' ,
117
+ '9+8=17 ' ,
118
118
'9+9=18'
119
119
] ;
120
120
121
121
net . train ( mathProblems , { log : true , errorThresh : 0.03 } ) ;
122
122
123
+ let errors = 0 ;
123
124
for ( let i = 0 ; i < mathProblems . length ; i ++ ) {
124
125
const input = mathProblems [ i ] . split ( '=' ) [ 0 ] + '=' ;
125
126
const output = net . run ( input ) ;
126
127
const predictedMathProblem = input + output ;
127
- console . log ( input + output ) ;
128
- assert ( mathProblems . indexOf ( predictedMathProblem ) > - 1 ) ;
129
- }
128
+ const error = mathProblems . indexOf ( predictedMathProblem ) <= - 1 ? 1 : 0 ;
129
+ errors += error ;
130
+ console . log ( input + output + ( error ? " - error" : "" ) ) ;
131
+ }
132
+ console . log ( "Errors: " + errors / mathProblems . length ) ;
Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ const net = new LSTM();
18
18
const mathProblems = [
19
19
'0+0=0' ,
20
20
'0+1=1' ,
21
- '1+0=2 ' ,
21
+ '1+0=1 ' ,
22
22
'0+2=2' ,
23
- '2+0=3 ' ,
23
+ '2+0=2 ' ,
24
24
'0+3=3' ,
25
25
'3+0=3' ,
26
26
'0+4=4' ,
@@ -108,22 +108,25 @@ const mathProblems = [
108
108
'6+9=15' ,
109
109
'9+6=15' ,
110
110
'7+7=14' ,
111
- '7+8=16 ' ,
112
- '8+7=16 ' ,
113
- '7+9=17 ' ,
114
- '9+7=17 ' ,
115
- '8+8=17 ' ,
116
- '8+9=18 ' ,
117
- '9+8=18 ' ,
111
+ '7+8=15 ' ,
112
+ '8+7=15 ' ,
113
+ '7+9=16 ' ,
114
+ '9+7=16 ' ,
115
+ '8+8=16 ' ,
116
+ '8+9=17 ' ,
117
+ '9+8=17 ' ,
118
118
'9+9=18'
119
119
] ;
120
120
121
121
net . train ( mathProblems , { log : true , errorThresh : 0.03 } ) ;
122
122
123
+ let errors = 0 ;
123
124
for ( let i = 0 ; i < mathProblems . length ; i ++ ) {
124
125
const input = mathProblems [ i ] . split ( '=' ) [ 0 ] + '=' ;
125
126
const output = net . run ( input ) ;
126
127
const predictedMathProblem = input + output ;
127
- console . log ( input + output ) ;
128
- assert ( mathProblems . indexOf ( predictedMathProblem ) > - 1 ) ;
129
- }
128
+ const error = mathProblems . indexOf ( predictedMathProblem ) <= - 1 ? 1 : 0 ;
129
+ errors += error ;
130
+ console . log ( input + output + ( error ? " - error" : "" ) ) ;
131
+ }
132
+ console . log ( "Errors: " + errors / mathProblems . length ) ;
You can’t perform that action at this time.
0 commit comments