From 793be7b049cecba43072858341dc7006fef352e7 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 6 Jul 2015 10:40:41 -0400 Subject: Add batch shuffle preprocessing step --- config/dest_mlp_tgtcls_1_cswdtx_batchshuffle.py | 40 +++++++++++++++++++++++++ model/mlp.py | 9 +++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 config/dest_mlp_tgtcls_1_cswdtx_batchshuffle.py diff --git a/config/dest_mlp_tgtcls_1_cswdtx_batchshuffle.py b/config/dest_mlp_tgtcls_1_cswdtx_batchshuffle.py new file mode 100644 index 0000000..a4db33c --- /dev/null +++ b/config/dest_mlp_tgtcls_1_cswdtx_batchshuffle.py @@ -0,0 +1,40 @@ +import os +import cPickle + +from blocks.initialization import IsotropicGaussian, Constant +from blocks.algorithms import Momentum + +import data +from model.dest_mlp_tgtcls import Model, Stream + + +n_begin_end_pts = 5 # how many points we consider at the beginning and end of the known trajectory + +with open(os.path.join(data.path, 'arrival-clusters.pkl')) as f: tgtcls = cPickle.load(f) + +dim_embeddings = [ + ('origin_call', data.origin_call_train_size, 10), + ('origin_stand', data.stands_size, 10), + ('week_of_year', 52, 10), + ('day_of_week', 7, 10), + ('qhour_of_day', 24 * 4, 10), + ('day_type', 3, 10), + ('taxi_id', 448, 10), +] + +dim_input = n_begin_end_pts * 2 * 2 + sum(x for (_, _, x) in dim_embeddings) +dim_hidden = [1000] +dim_output = tgtcls.shape[0] + +embed_weights_init = IsotropicGaussian(0.01) +mlp_weights_init = IsotropicGaussian(0.1) +mlp_biases_init = Constant(0.01) + +step_rule = Momentum(learning_rate=0.01, momentum=0.9) + +batch_size = 200 + +shuffle_batch_size = 5000 + +valid_set = 'cuts/test_times_0' +max_splits = 100 diff --git a/model/mlp.py b/model/mlp.py index 7e7d092..1f53e8c 100644 --- a/model/mlp.py +++ b/model/mlp.py @@ -1,9 +1,10 @@ from theano import tensor +import numpy import fuel import blocks -from fuel.transformers import Batch, MultiProcessing +from fuel.transformers import Batch, MultiProcessing, Mapping, SortMapping, Unpack from fuel.streams import DataStream from fuel.schemes import ConstantScheme, ShuffledExampleScheme from blocks.bricks import application, MLP, Rectifier, Initializable @@ -73,6 +74,12 @@ class Stream(object): stream = transformers.taxi_add_datetime(stream) stream = transformers.taxi_add_first_last_len(stream, self.config.n_begin_end_pts) stream = transformers.Select(stream, tuple(req_vars)) + + if hasattr(self.config, 'shuffle_batch_size'): + stream = transformers.Batch(stream, iteration_scheme=ConstantScheme(self.config.shuffle_batch_size)) + rng = numpy.random.RandomState(123) + stream = Mapping(stream, SortMapping(lambda x: float(rng.uniform()))) + stream = Unpack(stream) stream = Batch(stream, iteration_scheme=ConstantScheme(self.config.batch_size)) -- cgit v1.2.3