src/convnet_magicnet.js
function() {
      var input_depth = this.data[0].w.length;
      var num_classes = this.unique_labels.length;

      // sample network topology and hyperparameters
      var layer_defs = [];
      layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth: input_depth});
      var nl = weightedSample([0,1,2,3], [0.2, 0.3, 0.3, 0.2]); // prefer nets with 1,2 hidden layers
      for(var q=0;q<nl;q++) {
        var ni = randi(this.neurons_min, this.neurons_max);
        var act = ['tanh','maxout','relu'][randi(0,3)];
        if(randf(0,1)<0.5) {
          var dp = Math.random();
          layer_defs.push({type:'fc', num_neurons: ni, activation: act, drop_prob: dp});
        } else {
          layer_defs.push({type:'fc', num_neurons: ni, activation: act});
        }
      }
      layer_defs.push({type:'softmax', num_classes: num_classes});
      var net = new Net();
      net.makeLayers(layer_defs);

      // sample training hyperparameters
      var bs = randi(this.batch_size_min, this.batch_size_max); // batch size
      var l2 = Math.pow(10, randf(this.l2_decay_min, this.l2_decay_max)); // l2 weight decay
      var lr = Math.pow(10, randf(this.learning_rate_min, this.learning_rate_max)); // learning rate
      var mom = randf(this.momentum_min, this.momentum_max); // momentum. Lets just use 0.9, works okay usually ;p
      var tp = randf(0,1); // trainer type
      var trainer_def;
      if(tp<0.33) {
        trainer_def = {method:'adadelta', batch_size:bs, l2_decay:l2};
      } else if(tp<0.66) {
        trainer_def = {method:'adagrad', learning_rate: lr, batch_size:bs, l2_decay:l2};
      } else {
        trainer_def = {method:'sgd', learning_rate: lr, momentum: mom, batch_size:bs, l2_decay:l2};
      }
      
      var trainer = new Trainer(net, trainer_def);

      var cand = {};
      cand.acc = [];
      cand.accv = 0; // this will maintained as sum(acc) for convenience
      cand.layer_defs = layer_defs;
      cand.trainer_def = trainer_def;
      cand.net = net;
      cand.trainer = trainer;
      return cand;
    }
function() {
      var input_depth = this.data[0].w.length;
      var num_classes = this.unique_labels.length;

      // sample network topology and hyperparameters
      var layer_defs = [];
      layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth: input_depth});
      var nl = weightedSample([0,1,2,3], [0.2, 0.3, 0.3, 0.2]); // prefer nets with 1,2 hidden layers
      for(var q=0;q<nl;q++) {
        var ni = randi(this.neurons_min, this.neurons_max);
        var act = ['tanh','maxout','relu'][randi(0,3)];
        if(randf(0,1)<0.5) {
          var dp = Math.random();
          layer_defs.push({type:'fc', num_neurons: ni, activation: act, drop_prob: dp});
        } else {
          layer_defs.push({type:'fc', num_neurons: ni, activation: act});
        }
      }
      layer_defs.push({type:'softmax', num_classes: num_classes});
      var net = new Net();
      net.makeLayers(layer_defs);

      // sample training hyperparameters
      var bs = randi(this.batch_size_min, this.batch_size_max); // batch size
      var l2 = Math.pow(10, randf(this.l2_decay_min, this.l2_decay_max)); // l2 weight decay
      var lr = Math.pow(10, randf(this.learning_rate_min, this.learning_rate_max)); // learning rate
      var mom = randf(this.momentum_min, this.momentum_max); // momentum. Lets just use 0.9, works okay usually ;p
      var tp = randf(0,1); // trainer type
      var trainer_def;
      if(tp<0.33) {
        trainer_def = {method:'adadelta', batch_size:bs, l2_decay:l2};
      } else if(tp<0.66) {
        trainer_def = {method:'adagrad', learning_rate: lr, batch_size:bs, l2_decay:l2};
      } else {
        trainer_def = {method:'sgd', learning_rate: lr, momentum: mom, batch_size:bs, l2_decay:l2};
      }
      
      var trainer = new Trainer(net, trainer_def);

      var cand = {};
      cand.acc = [];
      cand.accv = 0; // this will maintained as sum(acc) for convenience
      cand.layer_defs = layer_defs;
      cand.trainer_def = trainer_def;
      cand.net = net;
      cand.trainer = trainer;
      return cand;
    }
function ( ) { var input_depth = this . data [ 0 ] . w . length ; var num_classes = this . unique_labels . length ; // sample network topology and hyperparameters var layer_defs = [ ] ; layer_defs . push ( { type : 'input' , out_sx : 1 , out_sy : 1 , out_depth : input_depth } ) ; var nl = weightedSample ( [ 0 , 1 , 2 , 3 ] , [ 0.2 , 0.3 , 0.3 , 0.2 ] ) ; // prefer nets with 1,2 hidden layers for ( var q = 0 ; q < nl ; q ++ ) { var ni = randi ( this . neurons_min , this . neurons_max ) ; var act = [ 'tanh' , 'maxout' , 'relu' ] [ randi ( 0 , 3 ) ] ; if ( randf ( 0 , 1 ) < 0.5 ) { var dp = Math . random ( ) ; layer_defs . push ( { type : 'fc' , num_neurons : ni , activation : act , drop_prob : dp } ) ; } else { layer_defs . push ( { type : 'fc' , num_neurons : ni , activation : act } ) ; } } layer_defs . push ( { type : 'softmax' , num_classes : num_classes } ) ; var net = new Net ( ) ; net . makeLayers ( layer_defs ) ; // sample training hyperparameters var bs = randi ( this . batch_size_min , this . batch_size_max ) ; // batch size var l2 = Math . pow ( 10 , randf ( this . l2_decay_min , this . l2_decay_max ) ) ; // l2 weight decay var lr = Math . pow ( 10 , randf ( this . learning_rate_min , this . learning_rate_max ) ) ; // learning rate var mom = randf ( this . momentum_min , this . momentum_max ) ; // momentum. Lets just use 0.9, works okay usually ;p var tp = randf ( 0 , 1 ) ; // trainer type var trainer_def ; if ( tp < 0.33 ) { trainer_def = { method : 'adadelta' , batch_size : bs , l2_decay : l2 } ; } else if ( tp < 0.66 ) { trainer_def = { method : 'adagrad' , learning_rate : lr , batch_size : bs , l2_decay : l2 } ; } else { trainer_def = { method : 'sgd' , learning_rate : lr , momentum : mom , batch_size : bs , l2_decay : l2 } ; } var trainer = new Trainer ( net , trainer_def ) ; var cand = { } ; cand . acc = [ ] ; cand . accv = 0 ; // this will maintained as sum(acc) for convenience cand . layer_defs = layer_defs ; cand . trainer_def = trainer_def ; cand . net = net ; cand . trainer = trainer ; return cand ; }
returns a random candidate network
returns a random candidate network