@@ -910,18 +910,17 @@ var Network = function () {
910910 } , {
911911 key : 'worker' ,
912912 value : function worker ( memory , set , options ) {
913-
914913 // Copy the options and set defaults (options might be different for each worker)
915914 var workerOptions = { } ;
916915 if ( options ) workerOptions = options ;
917- workerOptions . rate = options . rate || .2 ;
918- workerOptions . iterations = options . iterations || 100000 ;
919- workerOptions . error = options . error || .005 ;
920- workerOptions . cost = options . cost || null ;
921- workerOptions . crossValidate = options . crossValidate || null ;
916+ workerOptions . rate = workerOptions . rate || .2 ;
917+ workerOptions . iterations = workerOptions . iterations || 100000 ;
918+ workerOptions . error = workerOptions . error || .005 ;
919+ workerOptions . cost = workerOptions . cost || null ;
920+ workerOptions . crossValidate = workerOptions . crossValidate || null ;
922921
923922 // Cost function might be different for each worker
924- costFunction = 'var cost = ' + ( options && options . cost || this . cost || _Trainer2 . default . cost . MSE ) + ';\n' ;
923+ var costFunction = '// REPLACED BY WORKER\nvar cost = ' + ( options && options . cost || this . cost || _Trainer2 . default . cost . MSE ) + ';\n' ;
925924 var workerFunction = Network . getWorkerSharedFunctions ( ) ;
926925 workerFunction = workerFunction . replace ( / v a r c o s t = o p t i o n s & & o p t i o n s \. c o s t \| \| t h i s \. c o s t \| \| T r a i n e r \. c o s t \. M S E ; / g, costFunction ) ;
927926
@@ -978,19 +977,18 @@ var Network = function () {
978977
979978 // Load and name the train function
980979 var train_f = _Trainer2 . default . prototype . train . toString ( ) ;
981- train_f = train_f . replace ( 'function (set' , 'function train(set' ) + '\n' ;
980+ train_f = train_f . replace ( / t h i s ._ t r a i n S e t / g, '_trainSet' ) ;
981+ train_f = train_f . replace ( / t h i s .t e s t / g, 'test' ) ;
982+ train_f = train_f . replace ( / t h i s .c r o s s V a l i d a t e / g, 'crossValidate' ) ;
983+ train_f = train_f . replace ( 'crossValidate = true' , '// REMOVED BY WORKER' ) ;
982984
983985 // Load and name the _trainSet function
984986 var _trainSet_f = _Trainer2 . default . prototype . _trainSet . toString ( ) . replace ( / t h i s .n e t w o r k ./ g, '' ) ;
985- _trainSet_f = _trainSet_f . replace ( 'function (set' , 'function _trainSet(set' ) + '\n' ;
986- _trainSet_f = _trainSet_f . replace ( 'this.crossValidate' , 'crossValidate' ) ;
987- _trainSet_f = _trainSet_f . replace ( 'crossValidate = true' , 'crossValidate = { }' ) ;
988987
989988 // Load and name the test function
990989 var test_f = _Trainer2 . default . prototype . test . toString ( ) . replace ( / t h i s .n e t w o r k ./ g, '' ) ;
991- test_f = test_f . replace ( 'function (set' , 'function test(set' ) + '\n' ;
992990
993- return Network . _SHARED_WORKER_FUNCTIONS = train_f + _trainSet_f + test_f ;
991+ return Network . _SHARED_WORKER_FUNCTIONS = train_f + '\n' + _trainSet_f + '\n' + test_f ;
994992 }
995993 } , {
996994 key : 'fromJSON' ,
0 commit comments