diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-05-05 14:15:21 -0400 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-05-05 14:15:21 -0400 |
commit | 54613c1f9cf510ca7a71d6619418f2247515aec6 (patch) | |
tree | bed9a5a11ef5b7feecee44095a29400e32f76b05 /model/simple_mlp.py | |
parent | 712035b88be1816d3fbd58ce69ae6464767c780e (diff) | |
download | taxi-54613c1f9cf510ca7a71d6619418f2247515aec6.tar.gz taxi-54613c1f9cf510ca7a71d6619418f2247515aec6.zip |
Add models for time predictioAdd models for time prediction
Diffstat (limited to 'model/simple_mlp.py')
-rw-r--r-- | model/simple_mlp.py | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/model/simple_mlp.py b/model/simple_mlp.py deleted file mode 100644 index fc065f7..0000000 --- a/model/simple_mlp.py +++ /dev/null @@ -1,71 +0,0 @@ -from blocks.bricks import MLP, Rectifier, Linear, Sigmoid, Identity -from blocks.bricks.lookup import LookupTable - -from blocks.initialization import IsotropicGaussian, Constant - -from theano import tensor - -import data -import hdist - -class Model(object): - def __init__(self, config): - # The input and the targets - x_firstk_latitude = (tensor.matrix('first_k_latitude') - data.porto_center[0]) / data.data_std[0] - x_firstk_longitude = (tensor.matrix('first_k_longitude') - data.porto_center[1]) / data.data_std[1] - - x_lastk_latitude = (tensor.matrix('last_k_latitude') - data.porto_center[0]) / data.data_std[0] - x_lastk_longitude = (tensor.matrix('last_k_longitude') - data.porto_center[1]) / data.data_std[1] - - input_list = [x_firstk_latitude, x_firstk_longitude, x_lastk_latitude, x_lastk_longitude] - embed_tables = [] - - self.require_inputs = ['first_k_latitude', 'first_k_longitude', 'last_k_latitude', 'last_k_longitude'] - - for (varname, num, dim) in config.dim_embeddings: - self.require_inputs.append(varname) - vardata = tensor.lvector(varname) - tbl = LookupTable(length=num, dim=dim, name='%s_lookup'%varname) - embed_tables.append(tbl) - input_list.append(tbl.apply(vardata)) - - y = tensor.concatenate((tensor.vector('destination_latitude')[:, None], - tensor.vector('destination_longitude')[:, None]), axis=1) - - # Define the model - mlp = MLP(activations=[Rectifier() for _ in config.dim_hidden] + [Identity()], - dims=[config.dim_input] + config.dim_hidden + [config.dim_output]) - - # Create the Theano variables - inputs = tensor.concatenate(input_list, axis=1) - # inputs = theano.printing.Print("inputs")(inputs) - outputs = mlp.apply(inputs) - - # Normalize & Center - # outputs = theano.printing.Print("normal_outputs")(outputs) - outputs = data.data_std * outputs + data.porto_center - - # outputs = theano.printing.Print("outputs")(outputs) - # y = theano.printing.Print("y")(y) - - outputs.name = 'outputs' - - # Calculate the cost - cost = hdist.erdist(outputs, y).mean() - cost.name = 'cost' - hcost = hdist.hdist(outputs, y).mean() - hcost.name = 'hcost' - - # Initialization - for tbl in embed_tables: - tbl.weights_init = IsotropicGaussian(0.001) - mlp.weights_init = IsotropicGaussian(0.01) - mlp.biases_init = Constant(0.001) - - for tbl in embed_tables: - tbl.initialize() - mlp.initialize() - - self.cost = cost - self.hcost = hcost - self.outputs = outputs |