time_mlp.py (931B)
1 from blocks.bricks import application, Identity 2 3 import error 4 from model.mlp import FFMLP, Stream 5 6 7 class Model(FFMLP): 8 def __init__(self, config, **kwargs): 9 super(Model, self).__init__(config, output_layer=Identity, **kwargs) 10 self.inputs.append('input_time') 11 12 @application(outputs=['duration']) 13 def predict(self, **kwargs): 14 outputs = super(Model, self).predict(**kwargs).flatten() 15 if hasattr(self.config, 'exp_base'): 16 outputs = self.config.exp_base ** outputs 17 return kwargs['input_time'] + outputs 18 19 @predict.property('inputs') 20 def predict_inputs(self): 21 return self.inputs 22 23 @application(outputs=['cost']) 24 def cost(self, **kwargs): 25 y_hat = self.predict(**kwargs) 26 y = kwargs['travel_time'] 27 return error.rmsle(y_hat, y) 28 29 @cost.property('inputs') 30 def cost_inputs(self): 31 return self.inputs + ['travel_time']