def initialize(self, params, repetition):
    """
    Initialize experiment parameters and default values from configuration file.
    Called by reset() at the beginning of each experiment and each repetition.
    """
    self.name = params["name"]
    self.dataDir = params.get("datadir", "data")
    self.seed = params.get("seed", 42) + repetition

    torch.manual_seed(self.seed)
    np.random.seed(self.seed)
    random.seed(self.seed)

    # Training
    self.epochs = params.get("epochs", 1)
    self.batch_size = params.get("batch_size", 128)
    self.batches_in_epoch = params.get("batches_in_epoch", 100000)
    self.first_epoch_batch_size = params.get("first_epoch_batch_size",
                                             self.batch_size)
    self.batches_in_first_epoch = params.get("batches_in_first_epoch",
                                             self.batches_in_epoch)

    # Testing
    self.test_batch_size = params.get("test_batch_size", 1000)
    self.test_batches_in_epoch = params.get("test_batches_in_epoch", 100000)
    self.noise_values = map(float,
                            params.get("noise_values", "0.0, 0.1").split(", "))
    self.best_noise_score = 0.0
    self.best_epoch = -1

    # Optimizer
    self.optimizer_class = eval(params.get("optimizer", "torch.optim.SGD"))
    self.lr = params.get("learning_rate", 0.05)
    self.momentum = params.get("momentum", 0.9)
    self.weight_decay = params.get("weight_decay", 0.0)
    self.optimizer_params = eval(params.get("optimizer_params", "{}"))
    self.lr_scheduler_gamma = params.get("lr_scheduler_gamma", 0.9)
    self.loss_function = eval(params.get("loss_function",
                                         "torch.nn.functional.cross_entropy"))

    # Network parameters
    self.conv1_sparsity = params.get("conv1_sparsity", 1.0)
    self.network_type = params.get("network_type", "sparse")
    self.growth_rate = params.get("growth_rate", 12)
    self.nblocks = map(int,
                       params.get("nblocks", "6, 12, 24, 16").split(", "))
    self.k_inference_factor = params.get("k_inference_factor", 1.5)

    self.dense_sparsities = map(float,
                                params.get("dense_sparsities",
                                           "1.0, 1.0, 1.0, 1.0").split(", "))
    self.transition_sparsities = map(float,
                                     params.get("transition_sparsities",
                                                "0.1, 0.1, 0.2").split(", "))
    self.linear_sparsity = params.get("linear_sparsity", 0.0)
    self.linear_weight_sparsity = params.get("linear_weight_sparsity", 0.3)
    self.linear_n = params.get("linear_n", 500)
    self.avg_pool_size = params.get("avg_pool_size", 2)
    self.dense_c1_out_planes = params.get("dense_c1_out_planes", 4*self.growth_rate)
def initialize ( self , params , repetition ) : self . name = params [ "name" ] self . dataDir = params . get ( "datadir" , "data" ) self . seed = params . get ( "seed" , 42 ) + repetition torch . manual_seed ( self . seed ) np . random . seed ( self . seed ) random . seed ( self . seed ) self . epochs = params . get ( "epochs" , 1 ) self . batch_size = params . get ( "batch_size" , 128 ) self . batches_in_epoch = params . get ( "batches_in_epoch" , 100000 ) self . first_epoch_batch_size = params . get ( "first_epoch_batch_size" , self . batch_size ) self . batches_in_first_epoch = params . get ( "batches_in_first_epoch" , self . batches_in_epoch ) self . test_batch_size = params . get ( "test_batch_size" , 1000 ) self . test_batches_in_epoch = params . get ( "test_batches_in_epoch" , 100000 ) self . noise_values = map ( float , params . get ( "noise_values" , "0.0, 0.1" ) . split ( ", " ) ) self . best_noise_score = 0.0 self . best_epoch = - 1 self . optimizer_class = eval ( params . get ( "optimizer" , "torch.optim.SGD" ) ) self . lr = params . get ( "learning_rate" , 0.05 ) self . momentum = params . get ( "momentum" , 0.9 ) self . weight_decay = params . get ( "weight_decay" , 0.0 ) self . optimizer_params = eval ( params . get ( "optimizer_params" , "{}" ) ) self . lr_scheduler_gamma = params . get ( "lr_scheduler_gamma" , 0.9 ) self . loss_function = eval ( params . get ( "loss_function" , "torch.nn.functional.cross_entropy" ) ) self . conv1_sparsity = params . get ( "conv1_sparsity" , 1.0 ) self . network_type = params . get ( "network_type" , "sparse" ) self . growth_rate = params . get ( "growth_rate" , 12 ) self . nblocks = map ( int , params . get ( "nblocks" , "6, 12, 24, 16" ) . split ( ", " ) ) self . k_inference_factor = params . get ( "k_inference_factor" , 1.5 ) self . dense_sparsities = map ( float , params . get ( "dense_sparsities" , "1.0, 1.0, 1.0, 1.0" ) . split ( ", " ) ) self . transition_sparsities = map ( float , params . get ( "transition_sparsities" , "0.1, 0.1, 0.2" ) . split ( ", " ) ) self . linear_sparsity = params . get ( "linear_sparsity" , 0.0 ) self . linear_weight_sparsity = params . get ( "linear_weight_sparsity" , 0.3 ) self . linear_n = params . get ( "linear_n" , 500 ) self . avg_pool_size = params . get ( "avg_pool_size" , 2 ) self . dense_c1_out_planes = params . get ( "dense_c1_out_planes" , 4 * self . growth_rate )
Initialize experiment parameters and default values from configuration file.
    Called by reset() at the beginning of each experiment and each repetition.