aboutsummaryrefslogtreecommitdiff
path: root/model/rnn_lag_tgtcls.py
diff options
context:
space:
mode:
authorÉtienne Simon <esimon@esimon.eu>2015-07-21 18:26:43 -0400
committerÉtienne Simon <esimon@esimon.eu>2015-07-21 18:27:55 -0400
commite1673538607a7c8d784013b21b753f0c05c4cc34 (patch)
treef42e316e0c5bf67e3c9953aad6ba8fe9656829f2 /model/rnn_lag_tgtcls.py
parent58dcf7b17e9db6af53808994a7d39a759fcc5028 (diff)
downloadtaxi-e1673538607a7c8d784013b21b753f0c05c4cc34.tar.gz
taxi-e1673538607a7c8d784013b21b753f0c05c4cc34.zip
Genericize RNNs
Diffstat (limited to 'model/rnn_lag_tgtcls.py')
-rw-r--r--model/rnn_lag_tgtcls.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/model/rnn_lag_tgtcls.py b/model/rnn_lag_tgtcls.py
new file mode 100644
index 0000000..49d1f01
--- /dev/null
+++ b/model/rnn_lag_tgtcls.py
@@ -0,0 +1,31 @@
+import numpy
+import theano
+from theano import tensor
+from blocks.bricks.base import lazy
+from blocks.bricks import Softmax
+
+from model.rnn import RNN, Stream
+
+
+class Model(RNN):
+ @lazy()
+ def __init__(self, config, **kwargs):
+ super(Model, self).__init__(config, rec_input_len=4, output_dim=config.tgtcls.shape[0], **kwargs)
+ self.classes = theano.shared(numpy.array(config.tgtcls, dtype=theano.config.floatX), name='classes')
+ self.softmax = Softmax()
+ self.sequences.extend(['latitude_lag', 'longitude_lag'])
+ self.children.append(self.softmax)
+
+ def before_predict_all(self, kwargs):
+ super(Model, self).before_predict_all(kwargs)
+ kwargs['latitude_lag'] = tensor.extra_ops.repeat(kwargs['latitude'], 2, axis=0)
+ kwargs['longitude_lag'] = tensor.extra_ops.repeat(kwargs['longitude'], 2, axis=0)
+
+ def process_rto(self, rto):
+ return tensor.dot(self.softmax.apply(rto), self.classes)
+
+ def rec_input(self, latitude, longitude, latitude_lag, longitude_lag, **kwargs):
+ return (tensor.shape_padright(latitude),
+ tensor.shape_padright(longitude),
+ tensor.shape_padright(latitude_lag),
+ tensor.shape_padright(longitude_lag))