11{
2- "metadata" : {},
3- "nbformat" : 3 ,
4- "nbformat_minor" : 0 ,
5- "worksheets" : [
2+ "cells" : [
63 {
7- "cells" : [
8- {
9- "cell_type" : " markdown" ,
10- "metadata" : {},
11- "source" : [
12- " Using radial basis functions for smoothing/interpolation\n " ,
13- " ========================================================\n " ,
14- " \n " ,
15- " Radial basis functions can be used for smoothing/interpolating scattered\n " ,
16- " data in n-dimensions, but should be used with caution for extrapolation\n " ,
17- " outside of the observed data range.\n " ,
18- " \n " ,
19- " 1d example\n " ,
20- " ----------\n " ,
21- " \n " ,
22- " This example compares the usage of the Rbf and UnivariateSpline classes\n " ,
23- " from the scipy.interpolate module."
24- ]
25- },
26- {
27- "cell_type" : " code" ,
28- "collapsed" : false ,
29- "input" : [
30- " import numpy as np\n " ,
31- " from scipy.interpolate import Rbf, InterpolatedUnivariateSpline\n " ,
32- " \n " ,
33- " import matplotlib\n " ,
34- " matplotlib.use('Agg')\n " ,
35- " import matplotlib.pyplot as plt\n " ,
36- " \n " ,
37- " # setup data\n " ,
38- " x = np.linspace(0, 10, 9)\n " ,
39- " y = np.sin(x)\n " ,
40- " xi = np.linspace(0, 10, 101)\n " ,
41- " \n " ,
42- " # use fitpack2 method\n " ,
43- " ius = InterpolatedUnivariateSpline(x, y)\n " ,
44- " yi = ius(xi)\n " ,
45- " \n " ,
46- " plt.subplot(2, 1, 1)\n " ,
47- " plt.plot(x, y, 'bo')\n " ,
48- " plt.plot(xi, yi, 'g')\n " ,
49- " plt.plot(xi, np.sin(xi), 'r')\n " ,
50- " plt.title('Interpolation using univariate spline')\n " ,
51- " \n " ,
52- " # use RBF method\n " ,
53- " rbf = Rbf(x, y)\n " ,
54- " fi = rbf(xi)\n " ,
55- " \n " ,
56- " plt.subplot(2, 1, 2)\n " ,
57- " plt.plot(x, y, 'bo')\n " ,
58- " plt.plot(xi, yi, 'g')\n " ,
59- " plt.plot(xi, np.sin(xi), 'r')\n " ,
60- " plt.title('Interpolation using RBF - multiquadrics')\n " ,
61- " plt.savefig('rbf1d.png')"
62- ],
63- "language" : " python" ,
64- "metadata" : {},
65- "outputs" : []
66- },
67- {
68- "cell_type" : " markdown" ,
69- "metadata" : {},
70- "source" : [
71- " \n " ,
72- " \n " ,
73- " 2d example\n " ,
74- " ==========\n " ,
75- " \n " ,
76- " This example shows how to interpolate scattered 2d data."
77- ]
78- },
79- {
80- "cell_type" : " code" ,
81- "collapsed" : false ,
82- "input" : [
83- " import numpy as np\n " ,
84- " from scipy.interpolate import Rbf\n " ,
85- " \n " ,
86- " import matplotlib\n " ,
87- " matplotlib.use('Agg')\n " ,
88- " import matplotlib.pyplot as plt\n " ,
89- " from matplotlib import cm\n " ,
90- " \n " ,
91- " # 2-d tests - setup scattered data\n " ,
92- " x = np.random.rand(100)*4.0-2.0\n " ,
93- " y = np.random.rand(100)*4.0-2.0\n " ,
94- " z = x*np.exp(-x**2-y**2)\n " ,
95- " ti = np.linspace(-2.0, 2.0, 100)\n " ,
96- " XI, YI = np.meshgrid(ti, ti)\n " ,
97- " \n " ,
98- " # use RBF\n " ,
99- " rbf = Rbf(x, y, z, epsilon=2)\n " ,
100- " ZI = rbf(XI, YI)\n " ,
101- " \n " ,
102- " # plot the result\n " ,
103- " n = plt.normalize(-2., 2.)\n " ,
104- " plt.subplot(1, 1, 1)\n " ,
105- " plt.pcolor(XI, YI, ZI, cmap=cm.jet)\n " ,
106- " plt.scatter(x, y, 100, z, cmap=cm.jet)\n " ,
107- " plt.title('RBF interpolation - multiquadrics')\n " ,
108- " plt.xlim(-2, 2)\n " ,
109- " plt.ylim(-2, 2)\n " ,
110- " plt.colorbar()\n " ,
111- " plt.savefig('rbf2d.png')"
112- ],
113- "language" : " python" ,
114- "metadata" : {},
115- "outputs" : []
116- }
117- ],
118- "metadata" : {}
4+ "cell_type" : " markdown" ,
5+ "metadata" : {},
6+ "source" : [
7+ " Using radial basis functions for smoothing/interpolation\n " ,
8+ " ========================================================\n " ,
9+ " \n " ,
10+ " Radial basis functions can be used for smoothing/interpolating scattered\n " ,
11+ " data in n-dimensions, but should be used with caution for extrapolation\n " ,
12+ " outside of the observed data range.\n " ,
13+ " \n " ,
14+ " 1d example\n " ,
15+ " ----------\n " ,
16+ " \n " ,
17+ " This example compares the usage of the Rbf and UnivariateSpline classes\n " ,
18+ " from the scipy.interpolate module."
19+ ]
20+ },
21+ {
22+ "cell_type" : " code" ,
23+ "execution_count" : null ,
24+ "metadata" : {},
25+ "outputs" : [],
26+ "source" : [
27+ " import numpy as np\n " ,
28+ " from scipy.interpolate import Rbf, InterpolatedUnivariateSpline\n " ,
29+ " \n " ,
30+ " import matplotlib\n " ,
31+ " matplotlib.use('Agg')\n " ,
32+ " import matplotlib.pyplot as plt\n " ,
33+ " \n " ,
34+ " # setup data\n " ,
35+ " x = np.linspace(0, 10, 9)\n " ,
36+ " y = np.sin(x)\n " ,
37+ " xi = np.linspace(0, 10, 101)\n " ,
38+ " \n " ,
39+ " # use fitpack2 method\n " ,
40+ " ius = InterpolatedUnivariateSpline(x, y)\n " ,
41+ " yi = ius(xi)\n " ,
42+ " \n " ,
43+ " plt.subplot(2, 1, 1)\n " ,
44+ " plt.plot(x, y, 'bo')\n " ,
45+ " plt.plot(xi, yi, 'g')\n " ,
46+ " plt.plot(xi, np.sin(xi), 'r')\n " ,
47+ " plt.title('Interpolation using univariate spline')\n " ,
48+ " \n " ,
49+ " # use RBF method\n " ,
50+ " rbf = Rbf(x, y)\n " ,
51+ " fi = rbf(xi)\n " ,
52+ " \n " ,
53+ " plt.subplot(2, 1, 2)\n " ,
54+ " plt.plot(x, y, 'bo')\n " ,
55+ " plt.plot(xi, fi, 'g')\n " ,
56+ " plt.plot(xi, np.sin(xi), 'r')\n " ,
57+ " plt.title('Interpolation using RBF - multiquadrics')\n " ,
58+ " plt.tight_layout()\n " ,
59+ " plt.savefig('rbf1d.png')"
60+ ]
61+ },
62+ {
63+ "cell_type" : " markdown" ,
64+ "metadata" : {},
65+ "source" : [
66+ " \n " ,
67+ " \n " ,
68+ " 2d example\n " ,
69+ " ==========\n " ,
70+ " \n " ,
71+ " This example shows how to interpolate scattered 2d data."
72+ ]
73+ },
74+ {
75+ "cell_type" : " code" ,
76+ "execution_count" : null ,
77+ "metadata" : {},
78+ "outputs" : [],
79+ "source" : [
80+ " import numpy as np\n " ,
81+ " from scipy.interpolate import Rbf\n " ,
82+ " \n " ,
83+ " import matplotlib\n " ,
84+ " matplotlib.use('Agg')\n " ,
85+ " import matplotlib.pyplot as plt\n " ,
86+ " from matplotlib import cm\n " ,
87+ " \n " ,
88+ " # 2-d tests - setup scattered data\n " ,
89+ " x = np.random.rand(100)*4.0-2.0\n " ,
90+ " y = np.random.rand(100)*4.0-2.0\n " ,
91+ " z = x*np.exp(-x**2-y**2)\n " ,
92+ " ti = np.linspace(-2.0, 2.0, 100)\n " ,
93+ " XI, YI = np.meshgrid(ti, ti)\n " ,
94+ " \n " ,
95+ " # use RBF\n " ,
96+ " rbf = Rbf(x, y, z, epsilon=2)\n " ,
97+ " ZI = rbf(XI, YI)\n " ,
98+ " \n " ,
99+ " # plot the result\n " ,
100+ " n = plt.normalize(-2., 2.)\n " ,
101+ " plt.subplot(1, 1, 1)\n " ,
102+ " plt.pcolor(XI, YI, ZI, cmap=cm.jet)\n " ,
103+ " plt.scatter(x, y, 100, z, cmap=cm.jet)\n " ,
104+ " plt.title('RBF interpolation - multiquadrics')\n " ,
105+ " plt.xlim(-2, 2)\n " ,
106+ " plt.ylim(-2, 2)\n " ,
107+ " plt.colorbar()\n " ,
108+ " plt.savefig('rbf2d.png')"
109+ ]
110+ }
111+ ],
112+ "metadata" : {
113+ "kernelspec" : {
114+ "display_name" : " Python 3" ,
115+ "language" : " python" ,
116+ "name" : " python3"
117+ },
118+ "language_info" : {
119+ "codemirror_mode" : {
120+ "name" : " ipython" ,
121+ "version" : 3
122+ },
123+ "file_extension" : " .py" ,
124+ "mimetype" : " text/x-python" ,
125+ "name" : " python" ,
126+ "nbconvert_exporter" : " python" ,
127+ "pygments_lexer" : " ipython3" ,
128+ "version" : " 3.8.2"
119129 }
120- ]
121- }
130+ },
131+ "nbformat" : 4 ,
132+ "nbformat_minor" : 1
133+ }
0 commit comments