DIMENSIONALITY REDUCTION AND MANIFOLD ESTIMATION Mlden Victor Wickerhauser PMF/Matematika -- University of Zagreb Winter, 2022 Example Computer Programs (for Ocrave/Matlab) 2. Regression: %% Interpolation in 1-D % Interpolation set n=10; x=1:n; % 0,1,2,...,n y=sin(x); % sparse samples of a smooth function. % Plot the (default) piecewise linear interpolation plot(x,y); % plot 1: "connect the dots" by default % Polynomial regression with Vandermonde matrix: p=vander(x)\y'; % coefficients of the interpolating polynomial figure; z=linspace(0,n,200); plot(z,polyval(p,z)); % plot 2 % Alternatively, use the built-in Octave function: p=polyfit(x,y,n); figure; plot(z,polyval(p,z)); % plot 3: polynomial of degree n % Spline interpolation: pp=spline(x,y); figure; plot(z,ppval(pp,z)); % plot 4: piecewise cubic spline % Piecewise linear interpolation usable for computation: pl=interp1(x,y,"linear","pp"); figure; plot(z,ppval(pl,z)); % plot 5: piecewise linear polynomial %% Interpolation in 2-D % Square lattice of points in the plane: t=-9:3:9; [xx,yy]=meshgrid(t,t); zz=xx.^2+yy.^2; % Piecewise linear graph plots figure; surf(xx,yy,zz); figure; mesh(xx,yy,zz); % Piecewise linear level curves through many linearly interpolated levels figure; contour(xx,yy,zz); % Sample more often to get smaller errors from smooth: t=-9:0.5:9; [xx,yy]=meshgrid(t,t); zz=xx.^2+yy.^2; figure; surf(xx,yy,zz); figure; mesh(xx,yy,zz); figure; contour(xx,yy,zz); %% Convex hulls and triangulations % 2-simplex in the plane x=[0,0,1]; y=[0,1,0]; % triangle (0,0), (0,1), (1,0) k=convhull(x,y); plot(x(k),y(k)); % Random points in [0,1]x[0,1] xy=rand(17,2); k=convhull(xy); figure; plot(xy(k,1),xy(k,2)); % 3-simplex in R^3 x=[0,0,0,1]; y=[0,0,1,0]; z=[0,1,0,0]; k=convhull([x',y',z']) % 4 faces of the tetrahedron, 1 per row figure; trimesh(k,x,y,z); % plot as a wireframe, or mesh, in 3D figure; trisurf(k,x,y,z); % plot using colored surfaces in 3D % Random points in R^4 N=20; xyzw=rand(N,4); [h,vol]=convhulln(xyzw); h % listing of points in each 3-simplex face vol % volume of the convex hull % project the hull into R^3 along the 4 coordinates axes: figure; trimesh(h,xyzw(:,1),xyzw(:,2),xyzw(:,3)) % eliminate axis 4 figure; trimesh(h,xyzw(:,1),xyzw(:,2),xyzw(:,4)) % eliminate axis 3 figure; trimesh(h,xyzw(:,1),xyzw(:,3),xyzw(:,4)) % eliminate axis 2 figure; trimesh(h,xyzw(:,2),xyzw(:,3),xyzw(:,4)) % eliminate axis 1 % Plot a Delaunay triangulation 2D x=rand(1,20); y=rand(1,20); % 20 random points in [0,1]x[0,1] i=delaunay(x,y); % indices in {(x,y)} of the vertices of Delaunay triangles figure; triplot(i,x,y); % plot the triangles % Delaunay triangulation of a paraboloid in 3D from parameter space x=2*rand(1,20)-1; y=2*rand(1,20)-1; % 20 random points in parameter space [-1,1]x[-1,1] i=delaunay(x,y); % indices of the Delaunay triangles figure; triplot(i,x,y); % plot the triangles in the parameter space z=x.^2+y.^2; % lift onto the paraboloid using the parametrization. figure; trimesh(i,x,y,z); % display the triangulated manifold in 3D as a mesh figure; trisurf(i,x,y,z); % display the triangulated manifold in 3D as surfaces % Delaunay tesselation in 3D x=rand(1,10); y=rand(1,10); z=rand(1,10) % 10 random points in [0,1]x[0,1]x[0,1] j=delaunay(x,y,z); figure; tetramesh(j,x,y,z); % plot the component 3-simplexes as solids of one color