CGRA 401 ASSIGNMENT 2: RADIAL BASIS FUNCTIONS Objective Radial basis functions (RBFs) are a modern generalized form of spline interpolation. In computer graphics they are used for implicit surfaces, representation of scanned data, deformations, skinning, various sorts of mappings, and so on. RBFs were popularized in machine learning, where they provided a predictable alternative to neural networks, and are a close cousin to Gaussian Processes. In this assignment you will familiarize yourself with the RBF technique by implementing one-dimensional RBF interpolation of some scattered data points. This assignment will also give experience solving a linear system on the computer. Important Dates The assignment is due 11 April at 11:50pm. Project Description The program should interpolate the following x,y data: x = n_.array([20.,40., 60., 80., 160., 170.]) y = n_.array([2.,7., 8., 9., 8.5, 10.]) The RBF should use a Gaussian kernel with variance 100 (i.e. 2*sigma^2 = 200). The result of the interpolation will look something like this: The radial basis function technique is described in the lectures and slides, and you can find other descriptions online. Since this is your first assignment, here is a brief summary of what is involved (also please refer to the lectures and slides): • • • Make a function that computes the distance between two points. Make a function that computes the RBF kernel. The argument to this function is a distance that is computed with the function you made in step one. Use the Gaussian kernel mentioned above. Form a 6x6 matrix using numpy array (or numpy matrix). 6 is the number of data points to interpolate. The i,j entry of this matrix should be the value of the kernel when applied to the distance (in x) between the ith and jth point. This matrix is the “A” matrix in the Ax=b linear system. • Make the “b”, which is a 6 by 1 vector. Fill it with the values to interpolate. In this assignment, these are the y values. • Now do w = np.linalg.solve(A,b), which solves the linear system to compute the weights. • With the weights, you can now compute the spline at any point. Make a “synthesis” function to do this. It should take a new (arbitrary) x value (call it x0) as its argument, and return the result of computing the formula sum from i=0 to n-1: w[i] * kernel(distance(x0, x[i])) i.e. the kernel is called with the distance between the new point x0 and the training location x[i]. • Make a new array with 200 points that will hold the curve. Loop for x=1 to 200, call the synthesis function with x, and put the result into the array. • Plot the array. Also plot the x,y pairs as points. If the resulting picture does not look like the one above, the problem may be in the kernel width. Try scaling the distance that is used in the kernel, i.e. adjusting the “sigma” value in the Gausian. The program may be written in any language, however Python with the numpy and matplotlib packages is a recommended environment. As a guideline, the Python program might be 100 lines of code or even less. You must implement the RBF yourself. It is not sufficient to use an existing RBF function, such as the one in scipy.interpolate.rbf. Submission You will hand in the program source file, and an image file (in .jpg or .png format) showing what the program produces when it is run. If running the program is not obvious, you should include a README file. If the program is written in C or C++ (or D) you should include a Makefile, and ensure that the program runs on Linux. All files must be submitted to the ECS submission system. Marking This assignment is worth 10% of the course. It will be marked out of 10 marks. You will receive 5 marks for a working radial basis function implementation, and an additional 2 marks if the picture above is approximately reproduced. One mark will be allocated based on the how the program is organised – is it easy to understand? The remaining 2 marks will be allocated based on how general it is: 1 mark for a program that works in several dimensions, and 1 mark for implementing a different kernel function (other than Gaussian). To show your multidimensional interpolation working, you can make an example with z=f(x,y), and then use one of imshow, matshow, or plot_surface to show the results. You can find examples on the web by searching for these functions.
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project