aboutsummaryrefslogtreecommitdiff
path: root/hdist.py
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-04-28 15:57:35 -0400
committerAlex Auvolat <alex.auvolat@ens.fr>2015-04-28 15:57:35 -0400
commitd58b121de641c0122652bc3d6096a9d0e1048391 (patch)
tree294e0e7bcf033c9c1c2bec9efdb5fcf6900c4ec1 /hdist.py
parent902a8dcb40b3da9492093edd5bda356240f29eb0 (diff)
downloadtaxi-d58b121de641c0122652bc3d6096a9d0e1048391.tar.gz
taxi-d58b121de641c0122652bc3d6096a9d0e1048391.zip
Add function for applying model
Diffstat (limited to 'hdist.py')
-rw-r--r--hdist.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/hdist.py b/hdist.py
index ca9dba6..d5d7aec 100644
--- a/hdist.py
+++ b/hdist.py
@@ -1,10 +1,16 @@
from theano import tensor
+import theano
import numpy
+def const(v):
+ if theano.config.floatX == 'float32':
+ return numpy.float32(v)
+ else:
+ return numpy.float64(v)
def hdist(a, b):
- rearth = numpy.float32(6371)
- deg2rad = numpy.float32(3.14159265358979 / 180)
+ rearth = const(6371)
+ deg2rad = const(3.141592653589793 / 180)
lat1 = a[:, 1] * deg2rad
lon1 = a[:, 0] * deg2rad
@@ -15,9 +21,9 @@ def hdist(a, b):
dlon = abs(lon1-lon2)
al = tensor.sin(dlat/2)**2 + tensor.cos(lat1) * tensor.cos(lat2) * (tensor.sin(dlon/2)**2)
- d = tensor.arctan2(tensor.sqrt(al), tensor.sqrt(numpy.float32(1)-al))
+ d = tensor.arctan2(tensor.sqrt(al), tensor.sqrt(const(1)-al))
- hd = 2 * rearth * d
+ hd = const(2) * rearth * d
return tensor.switch(tensor.eq(hd, float('nan')), (a-b).norm(2, axis=1), hd)