コード例 #1
0
def train_example(dataset=None):
    model = GaussianBinaryRBM(nvis=1296,
                              nhid=61,
                              irange=0.5,
                              energy_function_class=grbm_type_1(),
                              learn_sigma=True,
                              init_sigma=.4,
                              init_bias_hid=2.,
                              mean_vis=False,
                              sigma_lr_scale=1e-3)
    cost = SMD(corruptor=GaussianCorruptor(stdev=0.4))
    algorithm = SGD(learning_rate=.1,
                    batch_size=5,
                    monitoring_batches=20,
                    monitoring_dataset=dataset,
                    cost=cost,
                    termination_criterion=MonitorBased(prop_decrease=0.01,
                                                       N=1))
    train = Train(dataset=dataset,
                  model=model,
                  save_path="./experiment/training.pkl",
                  save_freq=10,
                  algorithm=algorithm,
                  extensions=[])
    train.main_loop()
コード例 #2
0
def get_layer_trainer_sgd_rbm(layer, trainset):
    train_algo = SGD(
        learning_rate = 1e-1,
        batch_size =  5,
        #"batches_per_iter" : 2000,
        monitoring_batches =  20,
        monitoring_dataset =  trainset,
        cost = SMD(corruptor=GaussianCorruptor(stdev=0.4)),
        termination_criterion =  EpochCounter(max_epochs=MAX_EPOCHS_UNSUPERVISED),
        )
    model = layer
    extensions = [MonitorBasedLRAdjuster()]
    return Train(model = model, algorithm = train_algo,
                 save_path='grbm.pkl',save_freq=1,
                 extensions = extensions, dataset = trainset)
コード例 #3
0
def get_layer_trainer_sgd_rbm(layer, trainset):
    train_algo = SGD(
        learning_rate = 1e-1,
        batch_size =  5,
        #"batches_per_iter" : 2000,
        monitoring_batches =  20,
        monitoring_dataset =  trainset,
        cost = SMD(corruptor=GaussianCorruptor(stdev=0.4)),
        termination_criterion =  EpochCounter(max_epochs=MAX_EPOCHS),
        # another option:
        # MonitorBasedTermCrit(prop_decrease=0.01, N=10),
        )
    model = layer
    callbacks = [MonitorBasedLRAdjuster(), ModelSaver()]
    return Train(model = model, algorithm = train_algo,
            callbacks = callbacks, dataset = trainset)
コード例 #4
0
    def __init__(self,
                 energy_function_class=GRBM_Type_1,
                 nhid=10,
                 irange=0.5,
                 rng=None,
                 mean_vis=False,
                 init_sigma=.4,
                 learn_sigma=True,
                 sigma_lr_scale=1.,
                 init_bias_hid=-2.,
                 min_sigma=.1,
                 max_sigma=10.,
                 dataset_adaptor=VectorDataset(),
                 trainer=SGDTrainer(
                     SMD(corruptor=GaussianCorruptor(stdev=0.00)))):
        # trainer = SGDTrainer(SMD() )):

        self.config = {
            'energy_function_class': energy_function_class,
            'nhid': nhid,
            'irange': irange,
            'rng': rng,
            'mean_vis': mean_vis,
            'init_sigma': init_sigma,
            'learn_sigma': True,
            'sigma_lr_scale': sigma_lr_scale,
            'init_bias_hid': init_bias_hid,
            'min_sigma': min_sigma,
            'max_sigma': max_sigma,
            'learn_sigma': learn_sigma
        }

        self.dataset_adaptor = dataset_adaptor
        self.trainer = trainer

        return