forked from opencog/python-destin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclustering_theano.py
56 lines (46 loc) · 1.03 KB
/
clustering_theano.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
__author__ = 'teddy'
# Steven's incremental clustering re-implemented in Theano
from time import time
import math
import theano
import theano.tensor as T
# implementing sample Theano functions
'''
def logFunctionOne(var1, var2):
x = T.scalar('x')
y = T.scalar('y')
z = T.log10(x+y)
f = theano.function([x,y],z)
return f(var1, var2)
'''
def logMath(var1, var2):
return math.log10(var1 + var2)
def logTheano(var1, var2):
return f(var1, var2)
A = [[10, 10], [100, 100]]
x = T.scalar('x')
y = T.scalar('y')
z = T.log10(x + y)
f = theano.function([x, y], z)
print('Theano')
start = time()
# print start
for I in range(1000):
ans1 = logTheano(I, 1)
# print ans
elapsed1 = time() - start
print elapsed1
print('Math Module')
start = time()
for I in range(1000):
ans2 = logMath(I, 1)
# print ans
elapsed2 = time() - start
print elapsed2
print('theano w.o function call')
start = time()
for I in range(1000):
ans1 = f(I, 1)
elapsed3 = time() - start
print elapsed3
# print('Diff %f' % (elapsed1-elapsed2))