taxi

Winning entry to the Kaggle taxi competition
git clone https://esimon.eu/repos/taxi.git
Log | Files | Refs | README

dest_mlp.py (1007B)


      1 from theano import tensor
      2 from blocks.bricks import application, Identity
      3 
      4 import data
      5 import error
      6 from model.mlp import FFMLP, Stream
      7 
      8 
      9 class Model(FFMLP):
     10     def __init__(self, config, **kwargs):
     11         super(Model, self).__init__(config, output_layer=Identity, **kwargs)
     12 
     13     @application(outputs=['destination'])
     14     def predict(self, **kwargs):
     15         outputs = super(Model, self).predict(**kwargs)
     16         return data.train_gps_std * outputs + data.train_gps_mean
     17 
     18     @predict.property('inputs')
     19     def predict_inputs(self):
     20         return self.inputs
     21 
     22     @application(outputs=['cost'])
     23     def cost(self, **kwargs):
     24         y_hat = self.predict(**kwargs)
     25         y = tensor.concatenate((kwargs['destination_latitude'][:, None],
     26                                 kwargs['destination_longitude'][:, None]), axis=1)
     27 
     28         return error.erdist(y_hat, y).mean()
     29 
     30     @cost.property('inputs')
     31     def cost_inputs(self):
     32         return self.inputs + ['destination_latitude', 'destination_longitude']