I am trying to vectorise, this equation to make it faster (i.e not use a loop) this was the idea of sslow as oppsed to sfast.
mu2 = [1.0, 0.11264281499520618, 0.012799179048180226]
alpha = np.array([ 52.64173932, -1016.96156872, 4514.08903276])
def sslow(alpha):
t0 = time()
u = lambda x: np.exp(-(1+np.poly1d(list(reversed(alpha)))(x)))
k = sp.integrate.quad(lambda x: u(x), 1e-16, 1)[0]+np.dot(mu2,alpha),(time()-t0)
return k
def sfast(alpha):
t0 = time()
def int1(b):
j = 1
for q in range(0,len(alpha)):
j = j + alpha[q]*(b**q)
return np.exp(-j)
ans, err = sp.integrate.quad(int1, 1e-16, 1)
u = ans+np.dot(mu2,alpha);
return u,(time()-t0)
t = []
r = int(1e3)
for d in range(0,r):
t = (np.append(t,sslow(alpha)[1]))
print sum(t)/r
t = []
for d in range(0,r):
t = (np.append(t,sfast(alpha)[1]))
print sum(t)/r
Am I missing something completely? Is there a better way to the dot product between a vector and a polynomial basis and then integrate?