-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeval.py
34 lines (28 loc) · 787 Bytes
/
peval.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
import numpy as np
import ptest
def pEval(x, asubk):
x = x * 1.0
f = asubk[-1] * 1.0
k = len(asubk) - 2
while (k >= 0):
f = f * x + asubk[k] * 1.0
k = k - 1
return f
#below evaluates a cubuc spline.
#coeffs should have 4 coeffs per entry in x_k except for the last one.
#we are putting constant term on the left, cubic term on the right
# we use horners method again
def splineEval(x,xs,coeffs):
i = np.searchsorted(xs,x)-1
if(x <= xs[0]):
i =0
if(x > xs[-1]):
i = len(xs)-2
t = x - xs[i]
return ((coeffs[4*i+3] *t + coeffs[4*i+2]) * t + coeffs[4*i+1]) * t + coeffs[4*i]
def rEval(x,xs,ws,l):
sum =0
for i in range(len(xs)):
sum += ws[i] * ptest.phi(x - xs[i], l)
return sum
#dummy comment