Esempio n. 1
0
    def _create_mlp(self):
        model = NeuralRegressor(input_dim=self.unit_counts[0])
        initializer = UniformInitializer(seed=self.random_state)

        if self.spec.is_convolution:
            model.stack_layer(layers.DimShuffle((0, 'x', 1, 2)))

        for l, n in zip(self.layers, self.unit_counts[1:]):
            t = None
            if l.type in ('Tanh', 'Sigmoid'): t = l.type.lower()
            if l.type in ('Rectifier'): t = 'relu'
            if l.type in ('Linear', 'Softmax'): t = 'linear'
            assert t is not None, "Unknown activation type `%s`." % l.type

            if isinstance(l, Layer):
                # self._check_layer(l, ['units'])
                model.stack_layer(layers.Dense(n, t, init=initializer))
                if l.type == 'Softmax':
                    model.stack_layer(layers.Softmax())
            if isinstance(l, layers.Convolution):
                # self._check_layer(l, ['channel', 'kernel_shape'])
                model.stack_layer(layers.Convolution(
                    activation=t,
                    filter_shape=(l.channels, l.kernel_shape[0], l.kernel_shape[1]),
                    pool_size=l.pool_shape,
                    border_mode=l.border_mode,
                    init=initializer))

        self.mlp = model
Esempio n. 2
0
def get_model(state_num, action_num):
    model = NeuralRegressor(state_num)
    model.stack(
        Dense(HIDDEN_UNITS,
              activation='tanh',
              init=GaussianInitializer(deviation=0.01)),
        Dense(action_num, init=GaussianInitializer(deviation=0.01)))
    return model
Esempio n. 3
0
 def _create_mlp(self):
     model = NeuralRegressor(input_dim=self.unit_counts[0])
     for l, n in zip(self.layers, self.unit_counts[1:]):
         t = 'relu'
         if l.type == 'Rectifier': t = 'relu'
         if l.type == 'Linear': t = 'linear'
         model.stack_layer(Dense(n, t))
     model.stack_layer(Softmax())
     self.mlp = model
Esempio n. 4
0
valid_size = int(1000)
train_set = data[valid_size:]
valid_set = data[:valid_size]

dataset = SequentialDataset(train_set, valid=valid_set)
dataset.report()

batch_set = MiniBatches(dataset, batch_size=32)

if __name__ == '__main__':

    ap = ArgumentParser()
    ap.add_argument("--model", default=os.path.join(os.path.dirname(__file__), "models", "sequence_adding_100_2.gz"))
    args = ap.parse_args()

    model = NeuralRegressor(input_dim=2, input_tensor=3)
    model.stack(IRNN(hidden_size=100, input_type="sequence",
                     output_type="one"),
                      Dense(1))

    if os.path.exists(args.model):
        model.load_params(args.model)

    conf = TrainerConfig()
    conf.learning_rate = LearningRateAnnealer.learning_rate(0.01)
    conf.gradient_clipping = 3
    conf.patience = 50
    conf.gradient_tolerance = 5
    conf.avoid_nan = False
    trainer = SGDTrainer(model, conf)
Esempio n. 5
0
def get_model(state_num, action_num):
    model = NeuralRegressor(state_num)
    model.stack(Dense(HIDDEN_UNITS, activation='tanh', init=GaussianInitializer(deviation=0.01)),
                Dense(action_num, init=GaussianInitializer(deviation=0.01)))
    return model
Esempio n. 6
0
valid_size = int(1000)
train_set = data[valid_size:]
valid_set = data[:valid_size]

dataset = SequentialDataset(train_set, valid=valid_set)
dataset.report()

batch_set = MiniBatches(dataset, batch_size=32)

if __name__ == '__main__':

    ap = ArgumentParser()
    ap.add_argument("--model", default=os.path.join(os.path.dirname(__file__), "models", "sequence_adding_100_2.gz"))
    args = ap.parse_args()

    model = NeuralRegressor(input_dim=2, input_tensor=3, clip_value=3.)
    model.stack_layer(IRNN(hidden_size=100, output_size=1, input_type="sequence",
                     output_type="one", output_activation="linear"))

    if os.path.exists(args.model):
        model.load_params(args.model)

    conf = TrainerConfig()
    conf.learning_rate = LearningRateAnnealer.learning_rate(0.01)
    conf.max_norm = 1
    conf.patience = 50
    conf.gradient_tolerance = 5
    trainer = SGDTrainer(model, conf)

    annealer = LearningRateAnnealer(trainer, patience=20)