PHY Introduction to Python Programming, week 5

Size: px
Start display at page:

Download "PHY Introduction to Python Programming, week 5"

Transcription

1 PHY Introduction to Python Programming, week 5 The lecture materials, worksheets, and assignments can all be found here: ( Lecture materials Note: today at the end of this lecture the Teaching Evaluation forms will be handed out. Please complete the forms, and I will ask one of you to bring them to the M&P office where you also handed in your Assignments. Note: the computer labs sessions are mandatory also in weeks where there is no new assignment. Attendance sheets will be provided for the computer labs which need to be signed by each student either on a Thursday session or a Friday session. How to actually find the best fit in nontrivial situations In the last week we have looked at the concept of the chi-squared statistic as a measure for the goodness of fit. Smaller chi-squared values indicate a better fit. In the computer labs, we have also looked at an example of an exoplanet transit, and particularly the transit-timing variation. We tried to find the time shift of an observed exoplanet transit compared to an expected transit start time. Today we will use the same example to learn about algorithms that try to find the best fit in a fairly efficient manner. A reminder, we're looking at this problem here: In [2]: import numpy as np import matplotlib.pyplot as plt # the next line is only for ipython notebooks: %matplotlib inline from IPython.display import Image print 'Image credit: K. Poppenhaeger' Image(filename='TTV_KP.png', width=800) Image credit: K. Poppenhaeger Out[2]: We will use a simplified version where there is no gradual decline and rise at the beginning and end of the transit, but just a sudden drop from one instant to the next. That means this is what our expected transit looks like:

2 In [106]: t = np.arange(0, 30) # expected transit model transit_expected = np.ones(len(t)) # setting the bottom of the transit to 0.9 transit_expected[5:10] = 0.9 plt.figure() plt.plot(t, transit_expected, '-') plt.axis([0, 30, 0.8, 1.10]) Out[106]: [0, 30, 0.8, 1.1] And say we have some observational data, with the transit occurring at some time stamp, but not necessarily where we expect it: In [107]: y = np.ones(len(t)) # setting the bottom of the transit to 0.9 y[15:20] = 0.9 # add some random noise to the data: np.random.seed(123456) y = y + np.random.normal(0, 0.005, len(t)) # define some error bars for the data: e = np.random.normal(0, 0.001, len(t)) plt.figure() plt.plot(t, transit_expected) plt.errorbar(t, y, e, fmt = 'r.') plt.axis([0, 30, 0.8, 1.10]) Out[107]: [0, 30, 0.8, 1.1]

3 We can now test all possible start times for a transit and calculate how well the model fits the data, using the chi-square statistic. Quick reminder: This is how to calculate the chi-squared statistic: y i x i ) 2 χ 2 ( f( ) = Σ σi 2 And this is how to calculate the "reduced chi-squared", which is basically chi-squared divided by the number of data points. (Precisely, it's the number of "degrees of freedom" which is the number of data points minus the number of parameters we are trying to fit. We are trying to fit one parameter, namely the transit start time, so in our case it's "number of data points minus one".) χ 2 reduced 1 N 1 = Σ ( f( ) y i x i ) 2 σ 2 i The models that fit the data well will have a smaller value for chi-squared (and reduced chi-squared), the ones that don't fit well will have a larger one. In [108]: # function for the shifted transit model: def transit_model(t_start): # number of data points in our specific example: N = 30 # duration of transit, measured in time steps, for our example: duration = 5 # make model with no transit in it: model = np.ones(n) # insert transit at corret location in the model array, # depending on the start time: model[t_start:t_start+duration] = 0.9 return model # function to calculate chi-squared: def calc_chisquared(data, errors, model): # in Python we don't need to do this element by element, # but we can just use the full arrays! chisq = ((data - model)**2/errors**2).sum() return chisq # all possible start times in our time window: 0 to 80. start = np.arange(0, 25) chisq = np.zeros(len(start)) for i in np.arange(0, len(start)): model = transit_model(start[i]) chisq[i] = calc_chisquared(y, e, model) I'm plotting a few models with different start times together with the data; you can see by eye that the blue model is a pretty bad fit, the red (dashed) one is a very good fit, and the green (dotted) one is an okay-ish fit. The second plot shows that reduced chi-squared of those three models as a function of their transit start times. We can see (as expected) that the red model has the smallest reduced chi-squared.

4 In [109]: my_transit_starttimes = np.array([5, 15, 17]) model_1 = transit_model(my_transit_starttimes[0]) model_2 = transit_model(my_transit_starttimes[1]) model_3 = transit_model(my_transit_starttimes[2]) # plot of data and 3 models plt.figure() plt.plot(t, model_1, 'b-') plt.plot(t, model_2, 'r--', lw=2) plt.plot(t, model_3, 'g:', lw=2) plt.errorbar(t, y, e, fmt = 'k.') plt.ylabel('observed flux level y') plt.xlabel('time stamp') plt.axis([0, 30, 0.8, 1.10]) # plot of the reduced chi-squared of the 3 models plt.figure() plt.plot(my_transit_starttimes[0], calc_chisquared(y, e, model_1)/(len(y)-1), 'bo') plt.plot(my_transit_starttimes[1], calc_chisquared(y, e, model_2)/(len(y)-1), 'ro') plt.plot(my_transit_starttimes[2], calc_chisquared(y, e, model_3)/(len(y)-1), 'go') # plot of all reduced chi-squared values for all possible start times (calcul ated farther above) plt.plot(start, chisq/(len(y)-1), 'k:') plt.axis([0, 30, -10, 200]) plt.xlabel('transit start time') plt.ylabel('$\chi^2_{reduced}$') Out[109]: <matplotlib.text.text at 0x7f025d8c3250>

5 Now this calculation is fairly easy, because we only calculate the reduced chi-squared for a small number of start times (25 in this example). But if we have a very large data set, or we want to find the best-fitting parameter to a large accuracy, it will take a very long time for an algorithm to just test all possibilities by brute force. For many real-world problems, a brute-force approach isn't even going to find the best result, because the quantity we want to fit may not be changing step-wise. (Imagine for our example that the actual transit starts somewhere between two time stamps - all of a sudden we have a continuous parameter space that we need to seach for the best fit.) The way to deal with this is using algorithms that are somewhat clever in actually finding the best fit. One such example is the Simplex Fit. Simplex fits First of all, what is a simplex? A simplex is a geometric entity which has one more corner than the space it is defined in has dimensions. What does this mean? Basically, a simplex is a triangle. All the fancy language is just there to describe the appropriate generalizations for cases where we are not dealing with a 2-dimensional plane (in which triangles live). So, in 2-D, a simplex has 3 corners and is therefore a triangle. In 3-D, a simplex has 4 corners and is a tetrahedron. In 1-D, a simplex has 2 corners and is therefore a line segment. In 0-D, a simplex has 1 corner and is therefore a dot. What do we use a simplex for when we try to fit a function to data? We can use it to "go downwards" to the minimum of the chi-squared statistic. Let's say we have some transit start time that describes the data best, and if we test a lot of models with different transit start times against the data, we see (as above) that we will find the best-fitting model at the start time where the chi-squared is the lowest. Let's say our chi-squared versus transit start time looks like this:

6 In [139]: t = np.arange(1, 1000, 0.1) # I made up some polynomial function here just to get a nice shape for my exa mple chi-squared plot. def my_chi_func(t): return t + 0.1*(t-600)**2 chi2 = my_chi_func(t) plt.figure() plt.plot(t, chi2) Out[139]: [<matplotlib.lines.line2d at 0x7f025c5a3050>] We want to write an algorithm that starts calculating the chi-squared value at some initial point, i.e. some random guess for the transit start time, and then progressively walks downwards into the minimum of this chi-squared plot. When the algorithm finds the bottom of this, we want it to stop and give us the result it found. This will be our best-fitting transit start time. Now the trick is: to make this plot, I had to calculate all those values that make up the plot, i.e. I did exactly the thing we want to avoid: having to calculate the chi-squared for many models. We want our algorithm to calculate a few points, like the red dots in the plot below, and then make a good guess in which direction it should go with its next guess, without the algorithm knowing what the chi-squared function, plotted as the grey dashed line, actually looks like:

7 In [142]: t_guess_1 = 100 t_guess_2 = 160 t_guess_3 = 280 plt.figure() plt.plot(t_guess_1, my_chi_func(t_guess_1), 'ro') plt.plot(t_guess_2, my_chi_func(t_guess_2), 'ro') plt.plot(t_guess_3, my_chi_func(t_guess_3), 'ro') plt.plot(t, chi2, '--', color='grey') Out[142]: [<matplotlib.lines.line2d at 0x7f025c370e50>] The method how to do this with simplices is this: In our example, the chi-squared function is a one-dimensional curve. This is because we are only fitting one parameter in our problem (the trasnit start time). (If we had two parameters to fit, the chi-squared function would be a two-dimenional plane, like a topographic map.) Because of the one-dimensional chi-squared function, we use a simplex in 1-D, which is a line segment. We will make a simplex (a line) out of the two best two red data points, and try to find a better option for the third data point to make a new simplex and make it "walk" into the minimum. A possible algorithm goes like this (this is the so-called Nelder-Mead simplex algorithm): Step 1) Randomly choose 3 values t1, t2, t3 for the model (i.e. 3 transit start times) and calculate their chi-squared values. Step 2) Sort the points in ascending order of chi-squared value, so that t1 has the lowest chi-squared, and t3 has the largest. Step 3) Calculate the "centroid" between the two best points (i.e. the middle between t1 and t2) and call it tc. Step 4) Use the point t3 for "walking": we reflect the worst point (t3) to the other side of tc, call this point t4. Calculate the chi-squared for t4. χ 2 χ 2 χ 2 χ 2 Step 5) Compare (t4) to (t1), (t2), and (t3). This comparison determines the next step. Depending on which 3 points we chose in the beginning, the following options can occur:

8 A) If t4 is better than t1, but worse than t2: i.e. χ 2 (t1) < χ 2 (t4) < χ 2 (t2) < χ 2 (t3). In that case throw away t3 and keep t4. Make new simplex out of t1 and t4, t2 is the new walking point. Start over at Step 2. (Rename points accordingly). In [143]: print 'Image credit: K. Poppenhaeger' Image(filename='simplexA.JPG', width=800) Image credit: K. Poppenhaeger Out[143]: B) If t4 is better than all the other 3 points: i.e. χ 2 (t4) < χ 2 (t1) < χ 2 (t2) < χ 2 (t3). In that case we're obviously going in the correct direction with our new point t4, so we might as well try to go into that direction a bit farther. We make another point t5, which is twice as far from the centroid point tc and see if that's even better than t4. Keep whichever one is better and discard t3. Make new simplex out of whichever point we kept and t1, t2 is the new walking point. Start over at Step 2 (rename points accordingly).

9 In [144]: print 'Image credit: K. Poppenhaeger' Image(filename='simplexB.JPG', width=800) Image credit: K. Poppenhaeger Out[144]: C) If t4 is worse than t1 and t2, but better than t3: i.e. χ 2 (t1) < χ 2 (t2) < χ 2 (t4) < χ 2 (t3). In that case the minimum is probably somewhere between t3 and t4. We try to find a better point t5 by going only half the distance between tc and t4. If t5 is better than t2: keep t5, discard t4 and t3, make new simplex out of t5 and t1, t2 is the new walking point. Start over at Step 2 (rename points accordingly). If t5 is still worse than t3: go to option D.

10 In [145]: print 'Image credit: K. Poppenhaeger' Image(filename='simplexC.JPG', width=800) Image credit: K. Poppenhaeger Out[145]: D) If t4 is worse than t1, t2, and t3 (or if we're coming from option C and t5 is still worse than t1, t2, and t3): i.e. χ 2 (t1) < χ 2 (t2) < χ 2 (t3) < χ 2 (t4/5). In that case we're pretty close to having found the best fit! Because the best fit is probably contained somewhere between t1 and t2. So we get all points closer by 50% to our best guess so far (which is t1) and start over. Specifically, we keep t1, move t2 and t3 closer to t1 by 50%, make a new simplex out of t1 and the new t2, and the new t3 is the new walking point. Start over at Step 2 (rename points accordingly).

11 In [146]: print 'Image credit: K. Poppenhaeger' Image(filename='simplexD.JPG', width=800) Image credit: K. Poppenhaeger Out[146]: Stopping condition: A typical way to tell the simplex algorithm when to stop is to give it the accuracy level to which we want our answer. So say we want to find the best fit for the transit start time with an accuracy of 0.01 time units, then as soon as we have a simplex where the difference between t1 and t2 is smaller than 0.01 time units, and that simplex goes to option D, we must be within less than 0.01 units of the correct answer. This is when the algorithm would stop. Worksheet materials You may have guessed it: this week's worksheet problem is writing a function that performs a simplex fit. We will use this as our chi-squared function and just pretend that it accurately gives us the goodnees of our fit of some function to some data (without worrying about the specifics of what the data and the model actually are): In [151]: def my_chi_func(t): return t + 0.1*(t-600)**2 You can just copy and paste that into your own python editor. Now, this chi-squared function has a minimum somewhere, and we want to find it. The brute-force way would be to calculate the value of that function for a lot of data points t, and plot it. We'll do that now just to see what we're dealing with here:

12 In [154]: t = np.arange(0, 1000, 0.01) print 'how many elements does this array have?', len(t) y = my_chi_func(t) # so y has elements that we are calculating here! plt.figure() plt.plot(t, y) how many elements does this array have? Out[154]: [<matplotlib.lines.line2d at 0x7f025c740d90>] Okay, so we see (as we are humans with real brains and pattern recognition and such) that there is a minimum at t=600. Now we want to make an algorithm that can find that minimum without having to calculate the value of the chi-squared function times like we did above for the plot. Because programming a real simplex fitter is a bit complicated, I will give you some guidance and you will try to fill in the different cases for the test points until the function works! This is the outline of the function: Note: for copy-paste to work properly, you should open the html version of these notes, not the pdf ones (pdf does weird things to the indentations when you try to copy-paste).

13 In [159]: def my_simplex_step(t1, T2, T3): # user supplies three random choices for T v alues # calculate chi-squared for the three guesses: chi1 = my_chi_func(t1) chi2 = my_chi_func(t2) chi3 = my_chi_func(t3) # now for the sorting: # put them together in an array: all_chi = np.array([chi1, chi2, chi3]) # also put T guesses in an array: all_t = np.array([t1, T2, T3]) # find where chi-squared is smallest; that T point will be called t1. # we do this with a boolean mask: smallest = all_chi == all_chi.min() # this is an array with three True/Fa lse values, and it is true at the position of the smalles chi-squared t1 = all_t[smallest] largest = all_chi == all_chi.max() t3 = all_t[largest] middle = (~smallest) & (~largest) # "~" means NOT; i.e. this means NOT s mallest AND NOT largest t2 = all_t[middle] # now we have to find the fourth point. # first calculate the centroid point (tc) which is in the middle between t1 and t2: # (your code here) # then we calculate the reflected point t4: # (your code here) # Now we have to make a comparison where the chi-squared for t4 falls in comparision to t1, t2, and t3. # It should go something like this: chi4 = my_chi_func(t4) # case A: if (chi4 > chi1) & (chi4 <= chi2): print "I'm calculating case A." # (your code here) # case B: elif chi4 <= chi1: print "I'm calculating case B." # (your code here) # case C: elif (chi4 > chi2) & (chi4 <= chi3): print "I'm calculating case C." # (your code here) else: print "I'm calculating case D." # (your code here) # now the points need to be re-named, and you have to return the new t1, t2, t3. return (t1, t2, t3) This is the function for a single step of the simplex. Once this works to your satisfaction, write a second function that makes many simplex steps until the stopping condition is fulfilled. Here's an outline:

14 In [160]: def my_simplex_manysteps(t1, T2, T3, stopping_accuracy): # user supplies thre e random choices for T values and the stopping accuracy # first step of the simplex walk: (t1, t2, t3) = my_simplex_step(t1, T2, T3) # calculate what the size of the t1-t2 simplex is (i.e. the distance betw een the two points): # size_of_simplex = (your code here) # now check if that size is smaller than the stopping accuracy; if not, m ake another simplex step. # at the end, you will want to print something like your best result, whi ch will be the t1 you get in your final simplex step. print 'Best result:', t1 return t1 In [161]: my_simplex_manysteps(100., 200., 250., 10.) I'm calculating case B. Best result: [ 250.] Out[161]: array([ 250.]) Just see how far you get with this, it's quite a fun exercise to build you own simplex fitter. I hope you liked the PHY1024 module! Happy summer holidays to all of you. Cheers, Dr. Katja Poppenhaeger

MITOCW watch?v=zm5mw5nkzjg

MITOCW watch?v=zm5mw5nkzjg MITOCW watch?v=zm5mw5nkzjg The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

10.4 Linear interpolation method Newton s method

10.4 Linear interpolation method Newton s method 10.4 Linear interpolation method The next best thing one can do is the linear interpolation method, also known as the double false position method. This method works similarly to the bisection method by

More information

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Lecture - 05 Classification with Perceptron Model So, welcome to today

More information

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed. Preface Here are my online notes for my Algebra course that I teach here at Lamar University, although I have to admit that it s been years since I last taught this course. At this point in my career I

More information

Lecture 4 Median and Selection

Lecture 4 Median and Selection Lecture 4 Median and Selection Announcements! HW1 due Friday. HW2 posted Friday. I m going to try to either take a short break around 11:20. If you need to leave at 11:20, please wait for that break so

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

More on Curve Fitting

More on Curve Fitting PHY 310 DataAnalysis 5 More on Curve Fitting In [1]: # All the standard "import" stuff import scipy as sp from scipy.optimize import curve_fit from scipy.linalg import lstsq import matplotlib.pyplot as

More information

LECTURE 22. Numerical and Scientific Computing Part 2

LECTURE 22. Numerical and Scientific Computing Part 2 LECTURE 22 Numerical and Scientific Computing Part 2 MATPLOTLIB We re going to continue our discussion of scientific computing with matplotlib. Matplotlib is an incredibly powerful (and beautiful!) 2-D

More information

Excel. Spreadsheet functions

Excel. Spreadsheet functions Excel Spreadsheet functions Objectives Week 1 By the end of this session you will be able to :- Move around workbooks and worksheets Insert and delete rows and columns Calculate with the Auto Sum function

More information

COMP 364: Computer Tools for Life Sciences

COMP 364: Computer Tools for Life Sciences COMP 364: Computer Tools for Life Sciences Using libraries: NumPy & Data visualization with MatPlotLib Christopher J.F. Cameron and Carlos G. Oliver 1/27 Key course information Midterm I how was it? too

More information

(Ca...

(Ca... 1 of 8 9/7/18, 1:59 PM Getting started with 228 computational exercises Many physics problems lend themselves to solution methods that are best implemented (or essentially can only be implemented) with

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Administrivia. Next Monday is Thanksgiving holiday. Tuesday and Wednesday the lab will be open for make-up labs. Lecture as usual on Thursday.

Administrivia. Next Monday is Thanksgiving holiday. Tuesday and Wednesday the lab will be open for make-up labs. Lecture as usual on Thursday. Administrivia Next Monday is Thanksgiving holiday. Tuesday and Wednesday the lab will be open for make-up labs. Lecture as usual on Thursday. Lab notebooks will be due the week after Thanksgiving, when

More information

Lecture 15: High Dimensional Data Analysis, Numpy Overview

Lecture 15: High Dimensional Data Analysis, Numpy Overview Lecture 15: High Dimensional Data Analysis, Numpy Overview Chris Tralie, Duke University 3/3/2016 Announcements Mini Assignment 3 Out Tomorrow, due next Friday 3/11 11:55PM Rank Top 3 Final Project Choices

More information

lundi 7 janvier 2002 Blender: tutorial: Building a Castle Page: 1

lundi 7 janvier 2002 Blender: tutorial: Building a Castle Page: 1 lundi 7 janvier 2002 Blender: tutorial: Building a Castle Page: 1 www.blender.nl this document is online at http://www.blender.nl/showitem.php?id=4 Building a Castle 2000 07 19 Bart Veldhuizen id4 Introduction

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling Welcome to the lectures on computer graphics. We have

More information

Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides

Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides Hi everyone. Starting this week I'm going to make a couple tweaks to how section is run. The first thing is that I'm going to go over all the slides for both problems first, and let you guys code them

More information

(Refer Slide Time: 00:02:02)

(Refer Slide Time: 00:02:02) Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 20 Clipping: Lines and Polygons Hello and welcome everybody to the lecture

More information

(Refer Slide Time: 1:27)

(Refer Slide Time: 1:27) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

More information

Today. CISC101 Reminders & Notes. Searching in Python - Cont. Searching in Python. From last time

Today. CISC101 Reminders & Notes. Searching in Python - Cont. Searching in Python. From last time CISC101 Reminders & Notes Test 3 this week in tutorial USATs at the beginning of next lecture Please attend and fill out an evaluation School of Computing First Year Information Session Thursday, March

More information

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. According to the 161 schedule, heaps were last week, hashing

More information

Computer and Programming: Lab 1

Computer and Programming: Lab 1 01204111 Computer and Programming: Lab 1 Name ID Section Goals To get familiar with Wing IDE and learn common mistakes with programming in Python To practice using Python interactively through Python Shell

More information

Intro To Excel Spreadsheet for use in Introductory Sciences

Intro To Excel Spreadsheet for use in Introductory Sciences INTRO TO EXCEL SPREADSHEET (World Population) Objectives: Become familiar with the Excel spreadsheet environment. (Parts 1-5) Learn to create and save a worksheet. (Part 1) Perform simple calculations,

More information

Semester 2, 2018: Lab 1

Semester 2, 2018: Lab 1 Semester 2, 2018: Lab 1 S2 2018 Lab 1 This lab has two parts. Part A is intended to help you familiarise yourself with the computing environment found on the CSIT lab computers which you will be using

More information

MITOCW watch?v=se4p7ivcune

MITOCW watch?v=se4p7ivcune MITOCW watch?v=se4p7ivcune The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

Python for Scientists

Python for Scientists High level programming language with an emphasis on easy to read and easy to write code Includes an extensive standard library We use version 3 History: Exists since 1991 Python 3: December 2008 General

More information

Tutorial Four: Linear Regression

Tutorial Four: Linear Regression Tutorial Four: Linear Regression Imad Pasha Chris Agostino February 25, 2015 1 Introduction When looking at the results of experiments, it is critically important to be able to fit curves to scattered

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

MATPLOTLIB. Python for computational science November 2012 CINECA.

MATPLOTLIB. Python for computational science November 2012 CINECA. MATPLOTLIB Python for computational science 19 21 November 2012 CINECA m.cestari@cineca.it Introduction (1) plotting the data gives us visual feedback in the working process Typical workflow: write a python

More information

An introduction to plotting data

An introduction to plotting data An introduction to plotting data Eric D. Black California Institute of Technology February 25, 2014 1 Introduction Plotting data is one of the essential skills every scientist must have. We use it on a

More information

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014)

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) modified from Berkeley Python Bootcamp 2013 https://github.com/profjsb/python-bootcamp and Python for Signal Processing http://link.springer.com/book/10.1007%2f978-3-319-01342-8

More information

MITOCW ocw f99-lec07_300k

MITOCW ocw f99-lec07_300k MITOCW ocw-18.06-f99-lec07_300k OK, here's linear algebra lecture seven. I've been talking about vector spaces and specially the null space of a matrix and the column space of a matrix. What's in those

More information

Introduction to Python and NumPy I

Introduction to Python and NumPy I Introduction to Python and NumPy I This tutorial is continued in part two: Introduction to Python and NumPy II Table of contents Overview Launching Canopy Getting started in Python Getting help Python

More information

Credit: The lecture slides are created based on previous lecture slides by Dan Zingaro.

Credit: The lecture slides are created based on previous lecture slides by Dan Zingaro. CSC148 2018 Here 1 Credit: The lecture slides are created based on previous lecture slides by Dan Zingaro. 2 Larry Zhang Office: DH-3042 Email: ylzhang@cs.toronto.edu 3 The teaching team Dan Zingaro: LEC0103

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

AP Computer Science Unit 3. Programs

AP Computer Science Unit 3. Programs AP Computer Science Unit 3. Programs For most of these programs I m asking that you to limit what you print to the screen. This will help me in quickly running some tests on your code once you submit them

More information

Plotting with an introduction to functions

Plotting with an introduction to functions Plotting with CERN@school: an introduction to functions Twitter: @nicoleshearer93 N. Shearer a, T. Whyntie b, c a Durham University, b Langton Star Centre, c Queen Mary University of London Coding with

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 09 Problem Decomposition by Recursion - II We will

More information

Lecture 4. The Substitution Method and Median and Selection

Lecture 4. The Substitution Method and Median and Selection Lecture 4 The Substitution Method and Median and Selection Announcements! HW1 due Friday. (And HW2 also posted Friday). Last Time: The Master Theorem Suppose T n =a T & ' +O n*. Then Three parameters:

More information

(Refer Slide Time: 00:50)

(Refer Slide Time: 00:50) Programming, Data Structures and Algorithms Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology Madras Module - 03 Lecture 30 Searching Unordered linear

More information

Today. Golden section, discussion of error Newton s method. Newton s method, steepest descent, conjugate gradient

Today. Golden section, discussion of error Newton s method. Newton s method, steepest descent, conjugate gradient Optimization Last time Root finding: definition, motivation Algorithms: Bisection, false position, secant, Newton-Raphson Convergence & tradeoffs Example applications of Newton s method Root finding in

More information

Lab 4. Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon.

Lab 4. Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon. Calc II Page 1 Lab 4 Wednesday, February 19, 2014 5:01 PM Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon. Use

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 07 Lecture - 38 Divide and Conquer: Closest Pair of Points We now look at another divide and conquer algorithm,

More information

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python. Raspberry Pi Learning Resources Turtle Snowflakes Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python. How to draw with Python Turtle 1. To begin, you will

More information

Lecture. Algorithm Design and Recursion. Richard E Sarkis CSC 161: The Art of Programming

Lecture. Algorithm Design and Recursion. Richard E Sarkis CSC 161: The Art of Programming Lecture Algorithm Design and Recursion Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Objectives To understand the basic techniques for analyzing the efficiency of algorithms To know

More information

Homework 11 - Debugging

Homework 11 - Debugging 1 of 7 5/28/2018, 1:21 PM Homework 11 - Debugging Instructions: Fix the errors in the following problems. Some of the problems are with the code syntax, causing an error message. Other errors are logical

More information

Computer Lab 1: Introduction to Python

Computer Lab 1: Introduction to Python Computer Lab 1: Introduction to Python 1 I. Introduction Python is a programming language that is fairly easy to use. We will use Python for a few computer labs, beginning with this 9irst introduction.

More information

Motion I. Goals and Introduction

Motion I. Goals and Introduction Motion I Goals and Introduction As you have probably already seen in lecture or homework, it is important to develop a strong understanding of how to model an object s motion for success in this course.

More information

CS 051 Homework Laboratory #2

CS 051 Homework Laboratory #2 CS 051 Homework Laboratory #2 Dirty Laundry Objective: To gain experience using conditionals. The Scenario. One thing many students have to figure out for the first time when they come to college is how

More information

Barchard Introduction to SPSS Marks

Barchard Introduction to SPSS Marks Barchard Introduction to SPSS 22.0 3 Marks Purpose The purpose of this assignment is to introduce you to SPSS, the most commonly used statistical package in the social sciences. You will create a new data

More information

A Walk Through the MSA Software Spectrum Analyzer Mode 12/12/09

A Walk Through the MSA Software Spectrum Analyzer Mode 12/12/09 A Walk Through the MSA Software Spectrum Analyzer Mode 12/12/09 This document is intended to familiarize you with the basic features of the MSA and its software, operating as a Spectrum Analyzer, without

More information

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0 HW0 v3 October 2, 2018 1 CSE 252A Computer Vision I Fall 2018 - Assignment 0 1.0.1 Instructor: David Kriegman 1.0.2 Assignment Published On: Tuesday, October 2, 2018 1.0.3 Due On: Tuesday, October 9, 2018

More information

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB (DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB TROY P. KLING Contents 1. Importing Libraries 1 2. Introduction to numpy 2 3. Introduction to matplotlib 5 4. Image Processing 8 5. The Mandelbrot Set

More information

Microsoft Access 2007 Tutorial. Creating a Database using Access 2007

Microsoft Access 2007 Tutorial. Creating a Database using Access 2007 Creating a Database using Access 2007 Created: 12 December 2006 Starting Access 2007 Double click on the Access 2007 icon on the Windows desktop (see right), or click-on the Start button in the lower left

More information

CS1 Lecture 22 Mar. 6, 2019

CS1 Lecture 22 Mar. 6, 2019 CS1 Lecture 22 Mar. 6, 2019 HW 5 due Friday Questions? In discussion exams next week Last time Ch 12. Zip, lambda, etc Default/keyword function parameters Ch 19 conditional expresssions, list comprehensions

More information

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel.

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel. Some quick tips for getting started with Maple: An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel. [Even before we start, take note of the distinction between Tet mode and

More information

(Refer Slide Time: 00:02:00)

(Refer Slide Time: 00:02:00) Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 18 Polyfill - Scan Conversion of a Polygon Today we will discuss the concepts

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Lecture 8 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To make a donation

More information

1

1 Zeros&asymptotes Example 1 In an early version of this activity I began with a sequence of simple examples (parabolas and cubics) working gradually up to the main idea. But now I think the best strategy

More information

Patterning Math Lab 4a

Patterning Math Lab 4a Patterning Math Lab 4a This lab is an exploration of transformations of functions, a topic covered in your Precalculus textbook in Section 1.5. As you do the exercises in this lab you will be closely reading

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

Chapter 7. Polygons, Circles, Stars and Stuff

Chapter 7. Polygons, Circles, Stars and Stuff Chapter 7. Polygons, Circles, Stars and Stuff Now it s time for the magic! Magic? asked Morf. What do you mean, magic? You ve never talked about Logo magic before. We ve talked about shapes, and how you

More information

Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur

Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur Object-Oriented Analysis and Design Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology-Kharagpur Lecture 06 Object-Oriented Analysis and Design Welcome

More information

Linked Lists. What is a Linked List?

Linked Lists. What is a Linked List? Linked Lists Along with arrays, linked lists form the basis for pretty much every other data stucture out there. This makes learning and understand linked lists very important. They are also usually the

More information

Velocity: A Bat s Eye View of Velocity

Velocity: A Bat s Eye View of Velocity Name School Date Purpose Velocity: A Bat s Eye View of Velocity There are a number of ways of representing motion that we ll find useful. Graphing position, velocity, and acceleration vs. time is often

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

How to Improve Your Campaign Conversion Rates

How to Improve Your  Campaign Conversion Rates How to Improve Your Email Campaign Conversion Rates Chris Williams Author of 7 Figure Business Models How to Exponentially Increase Conversion Rates I'm going to teach you my system for optimizing an email

More information

11.1 Facility Location

11.1 Facility Location CS787: Advanced Algorithms Scribe: Amanda Burton, Leah Kluegel Lecturer: Shuchi Chawla Topic: Facility Location ctd., Linear Programming Date: October 8, 2007 Today we conclude the discussion of local

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #44 Multidimensional Array and pointers In this video, we will look at the relation between Multi-dimensional

More information

Sketching Data

Sketching Data Sketching Data 101010001010 Carson Smuts - GSAPP 2013 This document outlines the core principles behind Parametric and Algorithmic computation. What has become evident is that users tend to learn as much

More information

No more questions will be added

No more questions will be added CSC 2545, Spring 2017 Kernel Methods and Support Vector Machines Assignment 2 Due at the start of class, at 2:10pm, Thurs March 23. No late assignments will be accepted. The material you hand in should

More information

Binary Search Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250

Binary Search Trees. Carlos Moreno uwaterloo.ca EIT https://ece.uwaterloo.ca/~cmoreno/ece250 Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Standard reminder to set phones to silent/vibrate mode, please! Previously, on ECE-250... We discussed trees (the

More information

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture 28 Chinese Postman Problem In this lecture we study the Chinese postman

More information

MS Office 2016 Excel Pivot Tables - notes

MS Office 2016 Excel Pivot Tables - notes Introduction Why You Should Use a Pivot Table: Organize your data by aggregating the rows into interesting and useful views. Calculate and sum data quickly. Great for finding typos. Create a Pivot Table

More information

Derek Bridge School of Computer Science and Information Technology University College Cork

Derek Bridge School of Computer Science and Information Technology University College Cork CS4619: Artificial Intelligence II Overfitting and Underfitting Derek Bridge School of Computer Science and Information Technology University College Cork Initialization In [1]: %load_ext autoreload %autoreload

More information

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

More information

(Refer Slide Time: 1:40)

(Refer Slide Time: 1:40) Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering, Indian Institute of Technology, Delhi Lecture - 3 Instruction Set Architecture - 1 Today I will start discussion

More information

Barchard Introduction to SPSS Marks

Barchard Introduction to SPSS Marks Barchard Introduction to SPSS 21.0 3 Marks Purpose The purpose of this assignment is to introduce you to SPSS, the most commonly used statistical package in the social sciences. You will create a new data

More information

The Python interpreter

The Python interpreter The Python interpreter Daniel Winklehner, Remi Lehe US Particle Accelerator School (USPAS) Summer Session Self-Consistent Simulations of Beam and Plasma Systems S. M. Lund, J.-L. Vay, D. Bruhwiler, R.

More information

Descriptive Statistics and Graphing

Descriptive Statistics and Graphing Anatomy and Physiology Page 1 of 9 Measures of Central Tendency Descriptive Statistics and Graphing Measures of central tendency are used to find typical numbers in a data set. There are different ways

More information

Optimization and least squares. Prof. Noah Snavely CS1114

Optimization and least squares. Prof. Noah Snavely CS1114 Optimization and least squares Prof. Noah Snavely CS1114 http://cs1114.cs.cornell.edu Administrivia A5 Part 1 due tomorrow by 5pm (please sign up for a demo slot) Part 2 will be due in two weeks (4/17)

More information

#To import the whole library under a different name, so you can type "diff_name.f unc_name" import numpy as np import matplotlib.

#To import the whole library under a different name, so you can type diff_name.f unc_name import numpy as np import matplotlib. In [1]: #Here I import the relevant function libraries #This can be done in many ways #To import an entire library (e.g. scipy) so that functions accessed by typing "l ib_name.func_name" import matplotlib

More information

One way ANOVA when the data are not normally distributed (The Kruskal-Wallis test).

One way ANOVA when the data are not normally distributed (The Kruskal-Wallis test). One way ANOVA when the data are not normally distributed (The Kruskal-Wallis test). Suppose you have a one way design, and want to do an ANOVA, but discover that your data are seriously not normal? Just

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

COSC 311: ALGORITHMS HW1: SORTING

COSC 311: ALGORITHMS HW1: SORTING COSC 311: ALGORITHMS HW1: SORTIG Solutions 1) Theoretical predictions. Solution: On randomly ordered data, we expect the following ordering: Heapsort = Mergesort = Quicksort (deterministic or randomized)

More information

Box It Up (A Graphical Look)

Box It Up (A Graphical Look) . Name Date A c t i v i t y 1 0 Box It Up (A Graphical Look) The Problem Ms. Hawkins, the physical sciences teacher at Hinthe Middle School, needs several open-topped boxes for storing laboratory materials.

More information

Scheduler User Guide. Version 6

Scheduler User Guide. Version 6 Scheduler User Guide Version 6 Scheduler Program and User Guide 2003 Emergency Medicine Informatics, LLC. All rights reserved. 2 Introduction...7 The Scheduling Process...7 Shift Description...8 On Call

More information

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships Instructor: Craig Duckett Lecture 04: Thursday, April 5, 2018 Relationships 1 Assignment 1 is due NEXT LECTURE 5, Tuesday, April 10 th in StudentTracker by MIDNIGHT MID-TERM EXAM is LECTURE 10, Tuesday,

More information

An Introduction to Markov Chain Monte Carlo

An Introduction to Markov Chain Monte Carlo An Introduction to Markov Chain Monte Carlo Markov Chain Monte Carlo (MCMC) refers to a suite of processes for simulating a posterior distribution based on a random (ie. monte carlo) process. In other

More information

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting

Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting Lesson 3 Transcript: Part 1 of 2 - Tools & Scripting Slide 1: Cover Welcome to lesson 3 of the db2 on Campus lecture series. Today we're going to talk about tools and scripting, and this is part 1 of 2

More information

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are 1 NAVIGATING UNIX Most scientific computing is done on a Unix based system, whether a Linux distribution such as Ubuntu, or OSX on a Mac. The terminal is the application that you will use to talk to the

More information

ENGR 40M Project 3c: Switch debouncing

ENGR 40M Project 3c: Switch debouncing ENGR 40M Project 3c: Switch debouncing For due dates, see the overview handout 1 Introduction This week, you will build on the previous two labs and program the Arduino to respond to an input from the

More information

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

More information

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. Guide to and Hi everybody! In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. This guide focuses on two of those symbols: and. These symbols represent concepts

More information

Tutorial: Bryce Instancing Without the Instancing Lab

Tutorial: Bryce Instancing Without the Instancing Lab http://www.daz3d.com/forums/discussion/67986/tutorial-bryce-instancing-without-the-instancing-lab Fencepost52, 23. December 2015. Note: Use the zoom option in your PDF viewer to enlarge the pictures if

More information

This is not the chapter you re looking for [handwave]

This is not the chapter you re looking for [handwave] Chapter 4 This is not the chapter you re looking for [handwave] The plan of this course was to have 4 parts, and the fourth part would be half on analyzing random graphs, and looking at different models,

More information

2.2 - Layouts. Bforartists Reference Manual - Copyright - This page is Public Domain

2.2 - Layouts. Bforartists Reference Manual - Copyright - This page is Public Domain 2.2 - Layouts Introduction...2 Switching Layouts...2 Standard Layouts...3 3D View full...3 Animation...3 Compositing...3 Default...4 Motion Tracking...4 Scripting...4 UV Editing...5 Video Editing...5 Game

More information

MITOCW watch?v=r6-lqbquci0

MITOCW watch?v=r6-lqbquci0 MITOCW watch?v=r6-lqbquci0 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

MITOCW watch?v=hverxup4cfg

MITOCW watch?v=hverxup4cfg MITOCW watch?v=hverxup4cfg PROFESSOR: We've briefly looked at graph isomorphism in the context of digraphs. And it comes up in even more fundamental way really for simple graphs where the definition is

More information