You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#An implementation of the Faul - Goodsen - Powell algorithm. Given data to interpolate,
7
+
#the algorithm returns the coefficents (the lambda_i) and the constant term (alpha)
8
+
#for a multiquadric interpolant s(x) of the form
9
+
10
+
#s(x) = sum_i^n lambda_i phi(x-x_i) + alpha
11
+
12
+
#This interpolant is accurate to within your prescribed error
13
+
#The x_i are the data centers, phi(x) is the multiquadric radial basis fuction (x^2+c^2)^0.5 and
14
+
#alpha is a constant term.
15
+
16
+
#INPUT VARIABLES:
17
+
#n is number of data points
18
+
#c is the multiquadric parameter >0. Using a smaller value is generally quicker
19
+
#q is a variable controlling the size of sets for the cardinal functions generated as part of the algorithm. Usually we use 5<q<50 - q=30 is a safe value to use. The smaller the value of q, the quicker and dirtier the algorithm will be.
20
+
#d is the dimension of the data to interpolate.
21
+
#error is the error you wish to be within.
22
+
#We generate our own random data for this implementation.
23
+
24
+
# x_i are the centers
25
+
#f_i are the function values,
26
+
#c is the multiquadric shape parameter
27
+
#In this case we use randomly generated points in the unit ball - d controls the dimension of the data.
28
+
#q is a parameter for the algorithm
29
+
30
+
31
+
defFGP_DEMO(n,c,q,d,error):
32
+
start_time=time.time()
33
+
#set up intial interpolation data - here we use randomly generated points in the unit d-ball.
34
+
x_i=rf.points_in_unit_ball(n,d)
35
+
f_i= [random.random() for_inrange(n)]
36
+
#set up intital values
37
+
lambdas=np.zeros(n)
38
+
alpha=0.5*(np.max(f_i)+np.min(f_i))
39
+
r=f_i-np.ones(n)*alpha
40
+
41
+
#randomly shuffling the order of the datapoints to avoid combinations that result in slow convergence.
42
+
omeg=list(range(1,n+1))
43
+
random.shuffle(omeg)
44
+
data= []
45
+
46
+
#setting up the interpolation matrix
47
+
phi=np.ones((n,n))
48
+
fori, pointinenumerate(x_i):
49
+
forj, centerinenumerate(x_i):
50
+
phi[i,j] =rf.MQ(point-center,c)
51
+
52
+
#step3 returns the 'lsets' - approximations for the q nearest neighbours for each point (apart from 1)
53
+
forminrange(1, n):
54
+
newomeg, lset, lvalue=rf.step3(omeg,phi,q,m, n)
55
+
omeg=newomeg
56
+
data.append([lvalue,lset,rf.step4(lset,x_i,c)])
57
+
data=sorted(data, key=lambdax:x[0])
58
+
59
+
#setup complete, we now look to find the coeffificents for the interpolant to within the prescribed error.
#An implementation of the Faul - Goodsen - Powell algorithm. Given data to interpolate,
7
+
#the algorithm returns the coefficents (the lambda_i) and the constant term (alpha)
8
+
#for a multiquadric interpolant s(x) of the form
9
+
10
+
#s(x) = sum_i^n lambda_i phi(x-x_i) + alpha
11
+
12
+
#This interpolant is accurate to within your prescribed error
13
+
#The x_i are the data centers, phi(x) is the multiquadric radial basis fuction (x^2+c^2)^0.5 and
14
+
#alpha is a constant term.
15
+
16
+
#INPUT VARIABLES:
17
+
#data are the data centers
18
+
#values are the data values at the centers
19
+
#c is the multiquadric parameter >0. Using a smaller value is generally quicker
20
+
#q is a variable controlling the size of sets for the cardinal functions generated as part of the algorithm. Usually we use 5<q<50 - q=30 is a safe value to use. The smaller the value of q, the quicker and dirtier the algorithm will be.
21
+
#error is the error you wish to be within.
22
+
#We generate our own random data for this implementation.
23
+
24
+
defFGP(data,values,c,q,error):
25
+
26
+
n=len(data)
27
+
x_i= [iforiindata]
28
+
f_i= [iforiinvalues]
29
+
start_time=time.time()
30
+
31
+
#set up intital values
32
+
lambdas=np.zeros(n)
33
+
alpha=0.5*(np.max(f_i)+np.min(f_i))
34
+
r=f_i-np.ones(n)*alpha
35
+
36
+
#randomly shuffling the order of the datapoints to avoid combinations that result in slow convergence.
37
+
omeg=list(range(1,n+1))
38
+
random.shuffle(omeg)
39
+
data= []
40
+
41
+
#setting up the interpolation matrix
42
+
phi=np.ones((n,n))
43
+
fori, pointinenumerate(x_i):
44
+
forj, centerinenumerate(x_i):
45
+
phi[i,j] =rf.MQ(point-center,c)
46
+
47
+
#step3 returns the 'lsets' - approximations for the q nearest neighbours for each point (apart from 1)
48
+
forminrange(1, n):
49
+
newomeg, lset, lvalue=rf.step3(omeg,phi,q,m, n)
50
+
omeg=newomeg
51
+
data.append([lvalue,lset,rf.step4(lset,x_i,c)])
52
+
data=sorted(data, key=lambdax:x[0])
53
+
54
+
#setup complete, we now look to find the coeffificents for the interpolant to within the prescribed error.
0 commit comments