aboutsummaryrefslogtreecommitdiff
path: root/model/dest_mlp.py
blob: 78d713111c80d706f1dce1573c42fd8bcdb73955 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from theano import tensor
from blocks.bricks import application, Identity

import data
import error
from model.mlp import FFMLP, Stream


class Model(FFMLP):
    def __init__(self, config, **kwargs):
        super(Model, self).__init__(config, output_layer=Identity, **kwargs)

    @application(outputs=['destination'])
    def predict(self, **kwargs):
        outputs = super(Model, self).predict(**kwargs)
        return data.train_gps_std * outputs + data.train_gps_mean

    @predict.property('inputs')
    def predict_inputs(self):
        return self.inputs

    @application(outputs=['cost'])
    def cost(self, **kwargs):
        y_hat = self.predict(**kwargs)
        y = tensor.concatenate((kwargs['destination_latitude'][:, None],
                                kwargs['destination_longitude'][:, None]), axis=1)

        return error.erdist(y_hat, y).mean()

    @cost.property('inputs')
    def cost_inputs(self):
        return self.inputs + ['destination_latitude', 'destination_longitude']