@@ -91,7 +91,11 @@ async function cost_function(features, labels, weights,r){
91
91
}
92
92
async function train ( features , labels , weights , lr , iters = 100 , r = 0 ) {
93
93
cost_history = new Array ( ) ;
94
+ var bar = document . getElementById ( 'bar' ) ;
94
95
for ( var i = 0 ; i < iters ; i ++ ) {
96
+ bar . style . width = Math . ceil ( i * 100 / ( iters - 1 ) ) + '%' ;
97
+ bar . innerHTML = Math . ceil ( i * 100 / ( iters - 1 ) ) + '%' ;
98
+
95
99
weights = await update_weights ( features , labels , weights , lr , r ) ;
96
100
var cost = await cost_function ( features , labels , weights , r ) ;
97
101
cost_history . push ( { x :i , y :Number ( cost ) } ) ;
@@ -104,6 +108,8 @@ async function train(features, labels, weights, lr, iters=100,r=0){
104
108
}
105
109
106
110
async function trainclick ( ) {
111
+ var ele = document . getElementById ( 'barc' ) ;
112
+ ele . style . display = "block" ;
107
113
await loaddata ( ) ;
108
114
degree = Number ( document . getElementById ( 'd' ) . value ) ;
109
115
var lr = tf . pow ( tf . tensor ( 10 ) , Number ( document . getElementById ( 'l' ) . value ) ) ;
@@ -117,9 +123,12 @@ async function trainclick(){
117
123
var res = await train ( X , y , initial_weight , lr , epoch , r ) ;
118
124
weights_calculated = res [ 0 ] ; cost_history = res [ 1 ] ;
119
125
await plotdecisionboundary ( ) ;
120
-
126
+ ele . style . display = "none" ;
127
+ var bar = document . getElementById ( 'bar' ) ;
128
+ bar . style . width = '0%' ;
129
+ bar . innerHTML = '' ;
121
130
}
122
- trainclick ( ) ;
131
+ document . addEventListener ( 'DOMContentLoaded' , trainclick ( ) ) ;
123
132
124
133
document . getElementById ( 'train' ) . addEventListener ( 'click' , trainclick ) ;
125
134
0 commit comments