Physics 114: Lecture 18 Least Squares Fit to Arbitrary Functions Dale E. Gary NJIT Physics Department.

Slides:



Advertisements
Similar presentations
Introduction to Data Assimilation NCEO Data-assimilation training days 5-7 July 2010 Peter Jan van Leeuwen Data Assimilation Research Center (DARC) University.
Advertisements

Physics 114: Lecture 19 Least Squares Fit to 2D Data Dale E. Gary NJIT Physics Department.
Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
Exponential Functions Logarithmic Functions
FTP Biostatistics II Model parameter estimations: Confronting models with measurements.
Physics 114: Lecture 16 Linear and Non-Linear Fitting Dale E. Gary NJIT Physics Department.
P M V Subbarao Professor Mechanical Engineering Department
Data mining and statistical learning - lecture 6
Classification and Prediction: Regression Via Gradient Descent Optimization Bamshad Mobasher DePaul University.
Section 2.3 Gauss-Jordan Method for General Systems of Equations
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Copyright © Cengage Learning. All rights reserved.
INTEGRALS Areas and Distances INTEGRALS In this section, we will learn that: We get the same special type of limit in trying to find the area under.
Chapter 4 Multiple Regression.
Copyright © Cengage Learning. All rights reserved. 5 Integrals.
Physics 114: Lecture 11 Error Analysis
Non-Linear Simultaneous Equations
Calibration & Curve Fitting
Physics 114: Lecture 17 Least Squares Fit to Polynomial
Physics 114: Lecture 15 Probability Tests & Linear Fitting Dale E. Gary NJIT Physics Department.
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Introduction to Error Analysis
Access Mathematics Linear Graphs & Best line fits (Least squares)
Physics 430: Lecture 14 Calculus of Variations Dale E. Gary NJIT Physics Department.
Chapter 15 Modeling of Data. Statistics of Data Mean (or average): Variance: Median: a value x j such that half of the data are bigger than it, and half.
Dr. Richard Young Optronic Laboratories, Inc..  Uncertainty budgets are a growing requirement of measurements.  Multiple measurements are generally.
Formal Computational Skills Week 1: Functions. Overview By the end you should: Be able to evaluate a function Know how to visualise a function Know what.
Analytical vs. Numerical Minimization Each experimental data point, l, has an error, ε l, associated with it ‣ Difference between the experimentally measured.
Numerical Methods Applications of Loops: The power of MATLAB Mathematics + Coding 1.
INTEGRALS Areas and Distances INTEGRALS In this section, we will learn that: We get the same special type of limit in trying to find the area under.
Physics 114: Exam 2 Review Lectures 11-16
Quality of Curve Fitting P M V Subbarao Professor Mechanical Engineering Department Suitability of A Model to a Data Set…..
Physics 430: Lecture 19 Kepler Orbits Dale E. Gary NJIT Physics Department.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 31.
Integrals  In Chapter 2, we used the tangent and velocity problems to introduce the derivative—the central idea in differential calculus.  In much the.
Copyright © Cengage Learning. All rights reserved. 4 Integrals.
ISCG8025 Machine Learning for Intelligent Data and Information Processing Week 3 Practical Notes Regularisation *Courtesy of Associate Professor Andrew.
CS344: Introduction to Artificial Intelligence (associated lab: CS386) Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 31: Feedforward N/W; sigmoid.
Physics 430: Lecture 25 Coupled Oscillations
Numerical Methods for Engineering MECN 3500
Lecture 4: Statistics Review II Date: 9/5/02  Hypothesis tests: power  Estimation: likelihood, moment estimation, least square  Statistical properties.
PROBABILITY AND STATISTICS FOR ENGINEERING Hossein Sameti Department of Computer Engineering Sharif University of Technology Principles of Parameter Estimation.
LECTURE 25 THURSDAY, 19 NOVEMBER STA291 Fall
Physics 114: Lecture 14 Mean of Means Dale E. Gary NJIT Physics Department.
GG 450 Feb 27, 2008 Resistivity 2. Resistivity: Quantitative Interpretation - Flat interface Recall the angles that the current will take as it hits an.
1 6. Mean, Variance, Moments and Characteristic Functions For a r.v X, its p.d.f represents complete information about it, and for any Borel set B on the.
PROBABILITY AND STATISTICS FOR ENGINEERING Hossein Sameti Department of Computer Engineering Sharif University of Technology Mean, Variance, Moments and.
AUGUST 2. MATH 104 Calculus I Review of previous material…. …methods and applications of integration, differential equations ………..
SEM Basics 2 Byrne Chapter 2 Kline pg 7-15, 50-51, ,
Review of fundamental 1 Data mining in 1D: curve fitting by LLS Approximation-generalization tradeoff First homework assignment.
NON-LINEAR REGRESSION Introduction Section 0 Lecture 1 Slide 1 Lecture 6 Slide 1 INTRODUCTION TO Modern Physics PHYX 2710 Fall 2004 Intermediate 3870 Fall.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
1 6. Mean, Variance, Moments and Characteristic Functions For a r.v X, its p.d.f represents complete information about it, and for any Borel set B on the.
Copyright © Cengage Learning. All rights reserved. 4 Integrals.
Copyright © Cengage Learning. All rights reserved.
Physics 114: Lecture 16 Least Squares Fit to Arbitrary Functions
Copyright © Cengage Learning. All rights reserved.
Physics 114: Lecture 13 Probability Tests & Linear Fitting
Physics 114: Lecture 18 Least Squares Fit to 2D Data
Physics 312: Lecture 2 Calculus of Variations
Physics 114: Exam 2 Review Weeks 7-9
OPSE 301: Lab13 Data Analysis – Fitting Data to Arbitrary Functions
Physics 114: Exam 2 Review Material from Weeks 7-11
Physics 114: Lecture 14 Linear Fitting
Modelling data and curve fitting
6.2 Grid Search of Chi-Square Space
6.7 Practical Problems with Curve Fitting simple conceptual problems
6.5 Taylor Series Linearization
6.1 Introduction to Chi-Square Space
6.3 Gradient Search of Chi-Square Space
Presentation transcript:

Physics 114: Lecture 18 Least Squares Fit to Arbitrary Functions Dale E. Gary NJIT Physics Department

Apr 12, 2010 Nonlinear Least Squares Fitting  The general means to fit curves, surfaces, or higher dimensions to data relies on minimizing chi-square, but there is no closed-form method to calculate the coefficients. As usual, for a function y(x), say, the chi-square is  The techniques we developed in Chapters 6 and 7 only work when the parameters in the function y(x) are linear, i.e. obey  When this is not the case, i.e. when y(x) depends on products or powers in parameters), then the minimization of chi-square results in coupled equations that in general cannot be solved. We may sometimes be able to linearize it, as we saw last time, but generally we need to proceed by trial and error.

Apr 12, 2010 Searching Parameter Space  The basic approach could not be simpler, philosophically. The idea is to simply calculate a trial value of the function for a given set of values of parameters, calculate the chi-square, and repeat for a large number of parameters until you find the minimum chi-square.  As a concrete example, consider a Gaussian function with parameters a, b and c : fit to a set of data y i = , , , , , , , with equal errors  i =  = 0.2.  Try a set of parameters a = 1, b = 1, c = 1. With these parameters, the function y(x) gives y(x) = , , , , , ,  The reduced chi-square is then  A plot of the curves y i and y(x) are shown at right.

Apr 12, 2010 Searching Parameter Space (cont’d)  Now we simply try other sets of parameters and continue to calculate chi- square, attempting to find a minimum chi-square such that the reduced chi-square is about 1.  The plot shows the result of trying other values of a from 1 to 3, stepping by 0.5, while keeping b = 1 and c = 1.  The reduced chi-square for this set of five curves is  Looks like a = 2.5, b = 1, c = 1 is the best so far.  Now we change one of the other parameters, by say, setting b = 1.2, and varying a again, with c = 1.  The plot is shown at right, and the chi-square for this new set of curves is  Looks like a = 2.5, b = 1.2, c = 1 is the best so far.

Apr 12, 2010 Searching Parameter Space (cont’d)  If we repeat this 3 more times, increasing b by 0.2 each time, we end up with the following 25 values of reduced chi-square: c=1  Now let’s try c=1.2, and repeat the whole thing again: c=1.2 b=1.0 b=1.2 b=1.4 b=1.6 b=1.8 a= a= a= a= a= b=1.0 b=1.2 b=1.4 b=1.6 b=1.8 a= a= a= a= a=

Apr 12, 2010 Searching Parameter Space (cont’d)  After additional trial c values, we find a best fit of a = 2.0, b = 1.2, c = 1.4. Here is the final fit with these values.  But note that once we have the parameters, we can plot a much smoother Gaussian through the points by evaluating it at more x values.  Note that we could be even more precise by stepping with smaller steps.

Complete Program for c=1.4  yi = [ ];  x = -3:3;  chi2 = zeros(10,10);  c = 1.4;  i = 0;  for a = 0.75:0.25:3  i = i+1;  j = 0;  for b = 0.9:0.1:1.8  j = j+1;  chi2(i,j) = sum(((yi-a*exp(-((x-b)/c).^2))/0.1).^2)/4;  end Apr 12, 2010

Searching Parameter Space (cont’d)  Here is the reduced chi-square shown for smaller steps, covering the same range of a and b, but now as a 10 x 10 plot, and shown as an image.  The minimum chi-square is in a dip on a surface in “parameter space”.  2 = 1.29

Apr 12, 2010 Grid Search Method  The example we just looked at involved 3 parameters, and hence the parameter space is 3-dimensional (one dimension each of a, b and c ). We could easily try to fit more complex functions that would have many more parameters.  For example, for homework you will fit a triple Gaussian! Each has 3 parameters, so there are a total of 9. The search space for a solution (the parameter space) is now 9-dimensional! Obviously, the fitting approach we just did will work, but will it be very tedious. Let’s look at some ways to be more clever and speed up the process.  First, notice that we spent a lot of time calculating chi-square for parameters that got worse and worse, near the edges of the grid. We could select starting parameters, calculate chi-square, and step one parameter until it chi-square starts increasing. If it is the first step, reverse and go the other direction. This is like traveling downhill in one parameter. Keep going until you find the minimum, then start on another parameter.

Apr 12, 2010 Grid Search Method  You can refine this method to find the minimum more precisely. Once you get close, you can make the step size smaller, and essentially zoom in to finer precision.  Finally, you can improve even more by doing a gradient search, essentially going downhill in multiple parameters at once.

Apr 12, 2010 Lack of Convergence—Local Minima  For complex fitting functions, it is very easy to find a minimum that is not the true minimum, but only a local minimum. It is analogous to finding yourself in a dip on the top of a mountain, when there is a deep valley nearby.  If your initial parameter guess is near such a dip, the chi-square will be minimized in that local minimum, but the reduced chi-square will be nowhere near 1.  One way to guard against that is to be clever about your starting position. Recall our initial curve and initial trial of a = b = c = 1.  Looking at the blue curve to be fitted, our initial guess for b and c are pretty good, but a clearly should be greater, near a = 2.  Generally, it is usually good enough to choose bounds on the parameters.

Apr 12, 2010 Bounds on the Parameters  For our example of fitting a Gaussian, clearly the height and width should always be positive. Many autofitting routines, including the MatLAB routine fit(), allow one to set the lower and upper bounds on parameters.  Let’s use the MatLAB routine for a more complicated general fitting of a Gaussian on top of a baseline. You will do something similar for homework.  Create the data: x = -5:0.1:5; y = 32.1*exp(-((x-0.23)/0.87).^2)+5.4; dev = 1.5*randn(1,101) plot(x,y+dev,'.')  Create a “fittype” and call fit(): f = fittype('gauss2'); gfit = fit(x',(y+dev)',f)  Alternatively, set lower bound first options = fitoptions('gauss2') options.Lower = [0 -Inf 0 0 -Inf 0]; For fit types, use cflibhelp