Fitting to a set of data Lecture on fitting
Linear regression Linear regression Residual is the amount difference between a real data point and a modeled data point Fitting a polynomial to data Could use minimization of the sum of residuals Cancellation errors Could bisect a set of points rather than fitting through them Could use minimization of the sum of the absolute value of the residuals Too much influence to outliers Could use minimization of the sum of the square of the residuals Works well Solves problems mention in the other two methods
Least square Least square form, take derivative n S= y i,measured y i,model 2 i=1 n S= y i a o a 1 x i 2 i=1 y model =mx i b=a 0 a 1 x i S a 0 = 2 y i a 0 a 1 x i =0 S a 1 = 2 y i a 0 a 1 x 1 x i =0 slope=a 1 = n x i y i x i y i n x i 2 x i 2 a o = y a 1 x
Polyfit (from Octave) Take some data x,y (error sy) Fit line using polyfit as so >>[a,b] = polyfit(x,y,1) >>plot(x,y,'*') >>Line = a(1)*x+a(2) >>Hold on >>plot(x,line,'-+g') - or more professionally - >>[p,s] = wpolyfit(x,y,sy,1) >>[yn,syn]=polyconf(p,x,s,'ci') >> plot(x,yn,'gd-')
Nonlinear regression Cannot solve like the least square method Use Gauss-Newton optimization method Think Levenberg-Marquardt which is an optimization method of this nature Think least square/minimization/idea/concept
Interpolation >>slope = (y(5)-y(4))/(x(5)-x(4)) >>intercept=y(4)-slope*x(4) >>newline=slope*x+intercept >>plot(x,y,'*') >> hold on >>plot(x(4:5),newline(4:5)) >>%% Clearly I can now get a point >>%% in the middle >>point=slope*3.4+intercept This is a simple way of interpolating clearly it could be argued that a fitted line would be more appropriate than a slope-intercept form. Splines are often used
Extrapolation >>slope = (y(5)-y(4))/(x(5)-x(4)) >>intercept=y(4)-slope*x(4) >> %% xx is x extended >>newline=slope*xx+intercept >>plot(x,y,'*') >> hold on >>plot(xx(10:12),newline2(10:12)) >>%% Clearly I can now get a point >>%% in the beyond the data >>point=slope*10.6+intercept This is a simple way of extrapolation clearly it could be argued that a fitted line would be more appropriate than a slope-intercept form. Splines are often used
Spline Fits splines (curves) through the data Fits data (usually noisy) through knots Good method Requires picking knot locations Fits through knots using best method Use a spline like in boats to fit through the points (or knots) Different curves can be generated depending on the type of spline used B-spline is popular B in B-spline stands for basis functions Curves of the B-spline have orders which progressively look like a line to a triangular hat to an actual curve Other splines include the cubic, Bezier, etc. T-spline is a terminated non-recursive rational B-spline This is why you see both t-spline and b-spline calculated in the same function
Spline B-spline basic functions (image from Berkeley)
Digital Filters In essence an electronic filter that is represented digitally Control systems (or system dynamics) Convert a signal to a digital signal Change the signal using a transfer function over the digital signal Implemented using a difference equation Like a Fast Fourier Transform (FFT) Used for smoothing Used for fitting While advantageous over electronic filtering due to the inherent drifts and noise, it can be very complex and lead to removal of real signal
Digital Filters There are a number of types of digital filters thought they all revolve around some form of transfer function IIR filters Infinite impulse response (delta functions) filters Dirac delta functions Mathematically ideal f x x a dx= f a Need to implement carefully around x=0 point as there is no clear definition of what that is...can do it though Typically defined carefully with a difference equation
Digital Filters There are a number of types of digital filters thought they all revolve around some form of transfer function FIR filters Finite impulse response filters Kronecker delta function δ i j =1 wheni= j δ i j =0 when i j i= Discrete analogy to Dirac delta function Implemented using difference equation Window function filter is most common f i δ i j = f j
Control Systems - filters Control systems (system dynamics) Difference equation (possible derived from a transform) equates the output to the input by a set of coefficients that filter the input Iterative process Where coefficients represent feed forward (a coefficients) and feed back (b coefficients) coefficients (recall EGR 1010 discussion of this) Equation below is for IIR, remove feedback and you have FIR i =l y n =α( i=0 j=m a i x i n b j y j) n j=1