Physics 114: Lecture 19 Least Squares Fit to 2D Data Dale E. Gary NJIT Physics Department.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Get physics under control
Lecture 5.
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Transformations Getting normal or using the linear model.
November 12, 2013Computer Vision Lecture 12: Texture 1Signature Another popular method of representing shape is called the signature. In order to compute.
Lecture 23 Exemplary Inverse Problems including Earthquake Location.
4.5 Graphs of Sine and Cosine Functions
Physics 114: Lecture 16 Linear and Non-Linear Fitting Dale E. Gary NJIT Physics Department.
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Physics 114: Lecture 11 Error Analysis
C HAPTER 3: E XAMINING R ELATIONSHIPS. S ECTION 3.3: L EAST -S QUARES R EGRESSION Correlation measures the strength and direction of the linear relationship.
כמה מהתעשייה? מבנה הקורס השתנה Computer vision.
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
Physics 114: Lecture 17 Least Squares Fit to Polynomial
October 8, 2013Computer Vision Lecture 11: The Hough Transform 1 Fitting Curve Models to Edges Most contours can be well described by combining several.
Physics 114: Lecture 15 Probability Tests & Linear Fitting Dale E. Gary NJIT Physics Department.
Empirical Model Building Ib: Objectives: By the end of this class you should be able to: Determine the coefficients for any of the basic two parameter.
CPE 619 Simple Linear Regression Models Aleksandar Milenković The LaCASA Laboratory Electrical and Computer Engineering Department The University of Alabama.
Simple Linear Regression Models
Physics 114: Lecture 10 PDFs Part Deux Dale E. Gary NJIT Physics Department.
Scientific Computing Linear Least Squares. Interpolation vs Approximation Recall: Given a set of (x,y) data points, Interpolation is the process of finding.
Physics 114: Exam 2 Review Lectures 11-16
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 4 : Polynomial Edward Cheung Room W311g 2008.
Edges. Edge detection schemes can be grouped in three classes: –Gradient operators: Robert, Sobel, Prewitt, and Laplacian (3x3 and 5x5 masks) –Surface.
Signals CY2G2/SE2A2 Information Theory and Signals Aims: To discuss further concepts in information theory and to introduce signal theory. Outcomes:
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
6/4/2016© 2009 Raymond P. Jefferis III Lect Geographic Information Processing Attribute Plotting Extracting data features Calculating derivatives.
The General. What happens to the graph of a sine function if we put a coefficient on the x. y = sin 2x y = sin x It makes the graph "cycle" twice as fast.
Scientific Computing Introduction to Matlab Programming.
Number Systems Revision of conversations What is a register Addition Complementation.
Periodic driving forces
October 7, 2014Computer Vision Lecture 9: Edge Detection II 1 Laplacian Filters Idea: Smooth the image, Smooth the image, compute the second derivative.
Physics 114: Lecture 18 Least Squares Fit to Arbitrary Functions Dale E. Gary NJIT Physics Department.
Kylie Gorman WEEK 1-2 REVIEW. CONVERTING AN IMAGE FROM RGB TO HSV AND DISPLAY CHANNELS.
Physics 114: Lecture 12 Error Analysis, Part II Dale E. Gary NJIT Physics Department.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Physics 114: Lecture 8 Measuring Noise in Real Data Dale E. Gary NJIT Physics Department.
Physics 114: Lecture 20 2D Data Analysis Dale E. Gary NJIT Physics Department.
October 1, 2013Computer Vision Lecture 9: From Edges to Contours 1 Canny Edge Detector However, usually there will still be noise in the array E[i, j],
Intro to Statistics for the Behavioral Sciences PSYC 1900 Lecture 7: Regression.
Digital Image Processing Lecture 17: Segmentation: Canny Edge Detector & Hough Transform Prof. Charlene Tsai.
Machine Vision Edge Detection Techniques ENT 273 Lecture 6 Hema C.R.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A different cc/nc oscillation analysis Peter Litchfield  The Idea:  Translate near detector events to the far detector event-by-event, incorporating.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
September 26, 2013Computer Vision Lecture 8: Edge Detection II 1Gradient In the one-dimensional case, a step edge corresponds to a local peak in the first.
Richard Kass/F02P416 Lecture 6 1 Lecture 6 Chi Square Distribution (  2 ) and Least Squares Fitting Chi Square Distribution (  2 ) (See Taylor Ch 8,
Filters– Chapter 6. Filter Difference between a Filter and a Point Operation is that a Filter utilizes a neighborhood of pixels from the input image to.
Section 8 Numerical Analysis CSCI E-24 José Luis Ramírez Herrán October 20, 2015.
April 21, 2016Introduction to Artificial Intelligence Lecture 22: Computer Vision II 1 Canny Edge Detector The Canny edge detector is a good approximation.
Physics 114: Lecture 16 Least Squares Fit to Arbitrary Functions
Physics 114: Lecture 13 Probability Tests & Linear Fitting
Physics 114: Lecture 18 Least Squares Fit to 2D Data
Physics 114: Lecture 14 Linear Fitting
Physics 114: Exam 2 Review Weeks 7-9
Physics 114: Lecture 15 Least Squares Fit to Polynomial
OPSE 301: Lab13 Data Analysis – Fitting Data to Arbitrary Functions
Physics 114: Exam 2 Review Material from Weeks 7-11
Edge Detection The purpose of Edge Detection is to find jumps in the brightness function (of an image) and mark them.
Computer Vision Lecture 9: Edge Detection II
Net 222: Communications and networks fundamentals (Practical Part)
Least-Squares Regression
John Federici NJIT Physics Department
Physics 114: Lecture 14-a Linear Fitting Using Matlab
6.7 Practical Problems with Curve Fitting simple conceptual problems
Matlab Basics Tutorial
Probabilistic Surrogate Models
Presentation transcript:

Physics 114: Lecture 19 Least Squares Fit to 2D Data Dale E. Gary NJIT Physics Department

Apr 19, 2010 Nonlinear Least Squares Fitting  We saw that for a function y(x) the chi-square is which can be used to fit a curve to data points y i.  In just the same way, we can easily extend this idea to fitting a function z(x,y), that is, a surface, to a 2D data set of measurements z i (x,y).  You know that it takes three parameters to fit a Gaussian curve  To extend this to a 2D Gaussian is straightforward. It is:  Note that this has 5 parameters, but the most general way to describe a 2D Gaussian actually has 6 parameters, which you will do for homework.

Apr 19, 2010 Plotting a 2D Gaussian in MatLAB  Let’s introduce some useful MatLAB commands for creating a 2D Gaussian.  One can use a brute force method such as z = zeros(101,101); a = 2.5; bx = 2.3; by = -1.2; cx = 1.5; cy = 0.8; i = 0; for x = -5:0.1:5 i = i + 1; j = 0; for y = -5:0.1:5 j = j + 1; z(i,j) = a*exp(-((x-bx)/cx)^2 – ((y-by)/cy)^2); end imagesc(-5:0.1:5,-5:0.1:5,z)  Or, we can plot it as a surface to provide x and y coordinates surf(-5:0.1:5,-5:0.1:5,z)

Apr 19, 2010 Better Way of Creating 2D Functions  That way of using for loops is a very slow, so here is another way of doing it for “round” Gaussians: x = -5:0.1:5; y = -5:0.1:5; siz = size(x); siz = siz(2); a = 2.5; bx = 2.3; by = -1.2; c = 0.8; dist = zeros(siz,siz); for i=1:siz for j=1:siz dist(i,j) = x(i)^2 + y(j)^2; % Create “distance” array once end % use the next two statements multiple times for different Gaussians sdist = circshift(dist,round([bx/0.1,by/0.1])); % Shifted “distance” array z = a*exp(-sdist/c); imagesc(x,y,z);

Apr 19, 2010 Best Way of Creating 2D Functions  The best way, however, is to use the meshgrid() MatLAB function: [x, y] = meshgrid(-5:.1:5, -5:.1:5); a = 2.5; bx = 2.3; by = -1.2; cx = 1.5; cy = 0.8; z = a*exp( - (((x-bx)/cx).^2 + ((y-by)/cy).^2) ; surf(x,y,z);  This is completely general, and allows vector calculations which are very fast.  Here is another example, the sinc() function: z = a*sinc(sqrt(((x-bx)/cx).^2 + ((y-by)/cy).^2));  You can see that the meshgrid() function is very powerful as a shortcut for 2D function calculation.  To add noise, just add sig*randn(size(z)), where sig is the standard deviation of the noise.

Apr 19, 2010 Searching Parameter Space in 2D  Just as we did in the 1D case, searching parameter space is just a trial and error exercise. % Initial values around which to search a0 = max(max(z)); [ix iy] = find(z == a0); bx0 = x(ix,iy); by0 = y(ix,iy); cx0 = 1; cy0 = 1; astep = 0.05; bstep = 0.05; cstep = 0.05; chisqmin = 1e20; for a = a0-5*astep:astep:a0+5*astep for bx = bx0-5*bstep:bstep:bx0+5*bstep for by = by0-5*bstep:bstep:by0+5*bstep for cx = cx0-5*cstep:cstep:cx0+5*cstep for cy = cy0-5*cstep:cstep:cy0+5*cstep ztest = a*exp(-(((x-bx)/cx).^2 + ((y-by)/cy).^2)); chisq = sum(sum(((ztest-z)/sig).^2)); if (chisq < chisqmin); chisqmin = chisq; params = [a,bx,by,cx,cy]; end end params =

Apr 19, 2010 The Result Looks Good, but…  To calculate the result of the fit, just type ztest = params(1)*exp(-(((x-params(2))/params(4)).^2 + ((y-params(3))/params(5)).^2)); imagesc(x(1,:),y(:,1),ztest)  This gives a reasonable result, but compare the fit parameters with the (known) params: a = 2.1; bx = 2.3; by = -1.2; cx = 1.3; cy = 0.8; params =  The value of cx is especially far off, because our search window was limited to , so it could not reach 1.3.  Look at the residuals: imagesc(x(1,:),y(:,1),ztest-z)  Can you see a pattern in the noise?  To bring out the pattern better, let’s introduce convolution.

1D Convolution and Smoothing  Let’s create a noisy sine wave: u = -5:.1:5; w = sin(u*pi)+0.5*randn(size(u)); plot(u,w)  We can now smooth the data by convolving it with a vector [1,1,1], which does a 3-point running sum. wsm = conv(w,[1,1,1]); whos wsm Name Size Bytes Class Attributes wsm 1x double  Notice wsm is now of length 103. That means we cannot plot(u,wsm), but we can plot(u,wsm(2:102)). Now we see another problem.  Try this: plot(u,w) hold on; plot(u,wsm(2:102)/3,’r’) Apr 19, 2010

2D Convolution  To do 2D smoothing, we will use a 2D kernel k = ones(3,3), and use the conv2() function. So to smooth the residuals of our fit, we can use zsm = conv2(ztest-z,k)/9.; imagesc(x,y,zsm(2:102,2:102))  Now we can see the effect of missing the value of cx by 0.05 due to our limited search range.  There are other uses for convolution, such as edge detection. For example, we can convolve with a kernel k = [1,1,1,1,1,1].  Or a kernel k = [1,1,1,1,1,1]’. Or even a kernel k = eye(6). Or k = rot90(eye(6)). Apr 19, 2010