aboutsummaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/dest_simple_mlp.py (renamed from model/simple_mlp.py)10
-rw-r--r--model/dest_simple_mlp_tgtcls.py (renamed from model/simple_mlp_tgtcls.py)10
-rw-r--r--model/time_simple_mlp.py65
3 files changed, 77 insertions, 8 deletions
diff --git a/model/simple_mlp.py b/model/dest_simple_mlp.py
index fc065f7..896f219 100644
--- a/model/simple_mlp.py
+++ b/model/dest_simple_mlp.py
@@ -6,7 +6,7 @@ from blocks.initialization import IsotropicGaussian, Constant
from theano import tensor
import data
-import hdist
+import error
class Model(object):
def __init__(self, config):
@@ -51,9 +51,9 @@ class Model(object):
outputs.name = 'outputs'
# Calculate the cost
- cost = hdist.erdist(outputs, y).mean()
+ cost = error.erdist(outputs, y).mean()
cost.name = 'cost'
- hcost = hdist.hdist(outputs, y).mean()
+ hcost = error.hdist(outputs, y).mean()
hcost.name = 'hcost'
# Initialization
@@ -67,5 +67,7 @@ class Model(object):
mlp.initialize()
self.cost = cost
- self.hcost = hcost
+ self.monitor = [cost, hcost]
self.outputs = outputs
+ self.pred_vars = ['destination_latitude', 'destination_longitude']
+
diff --git a/model/simple_mlp_tgtcls.py b/model/dest_simple_mlp_tgtcls.py
index b2a1a6e..d8fdeb3 100644
--- a/model/simple_mlp_tgtcls.py
+++ b/model/dest_simple_mlp_tgtcls.py
@@ -9,7 +9,7 @@ from blocks.bricks.lookup import LookupTable
from blocks.initialization import IsotropicGaussian, Constant
import data
-import hdist
+import error
class Model(object):
def __init__(self, config):
@@ -53,9 +53,9 @@ class Model(object):
outputs.name = 'outputs'
# Calculate the cost
- cost = hdist.erdist(outputs, y).mean()
+ cost = error.erdist(outputs, y).mean()
cost.name = 'cost'
- hcost = hdist.hdist(outputs, y).mean()
+ hcost = error.hdist(outputs, y).mean()
hcost.name = 'hcost'
# Initialization
@@ -69,5 +69,7 @@ class Model(object):
mlp.initialize()
self.cost = cost
- self.hcost = hcost
+ self.monitor = [cost, hcost]
self.outputs = outputs
+ self.pred_vars = ['destination_latitude', 'destination_longitude']
+
diff --git a/model/time_simple_mlp.py b/model/time_simple_mlp.py
new file mode 100644
index 0000000..1568ed3
--- /dev/null
+++ b/model/time_simple_mlp.py
@@ -0,0 +1,65 @@
+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 error
+
+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.lvector('time')
+
+ # 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 = tensor.exp(mlp.apply(inputs) + 2)
+
+ # outputs = theano.printing.Print("outputs")(outputs)
+ # y = theano.printing.Print("y")(y)
+
+ outputs.name = 'outputs'
+
+ # Calculate the cost
+ cost = error.rmsle(outputs.flatten(), y.flatten())
+ cost.name = 'cost'
+
+ # 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.monitor = [cost]
+ self.outputs = outputs
+ self.pred_vars = ['time']