Upload your assignment here:

This is the problem based on what we talked about in class on Friday a bit. There is a complicated wave form that is best fit by adding multiple functions together. In this case, the functions would be linear + sine wave.

The goal is to produce the best fit to the data via producing a solution that has the lowest value of chi squared. Since it is unlikely that a constant period or phase for the sine wave will fit the entire data, you will likely have to make one or more a function of the time step, to produce a best fit. Again, this is why you program instead of using a black box programmed by someone else.

This exercise gives you practice in

  • coding up equations and adding them together
  • evaluting model vs data via the chi square techinque
  • practice with blind parameter searches to achieve the lowest value of chi square in an iterative manner.


Procedure:

  1. Download the two column Excel File - column 1 is time step, column 2 is data value at that time step. There are 1002 time steps.

  2. Smooth the data using any procedure that you want - you need to balance your smooth width with reduced noise vs loss of feature resolution. Your smoothed data set should look something like this:



  3. Write a function fitter: The simplest one is a sine wave + linear equation and sum the two together. Obviously you will need more than one linear equation because of the slope change. Alternatively you might be able to fit a higher order curve to whatever you think the baseline is, but the only way to fit the harmonics is with a sin wave.

  4. You will want to write code which will immediately pass through your parameter changes (line slopes, periods, amplitude, etc) and draw the function through the data so you can iterate manually towards some approximate solutioin

  5. You will need to calculate the residuals (difference between the model and the data) at each time stap to determine chi^2.



    fo = data; fe = model values; don't worry about normalization for this statistic, the above form is good enough to determine a local minimum (best fit)

  6. With your approximate fit now write a blind random search algorithm, as explained in class, using your now best guesses for parameters min and max, and then choose your random step size to add to the min parameter per iteration. You will want to output your chi^2 values per iteration so you can see if your converging or not.

    It is probably a good idea of keeping track of all bad solutions (those which produce a higher value of chi^2) to help with the iteration.

  7. When you have a best fit, predict the value for x=1200; we will compare these values in class on Friday and also in class, we will show you how to execute mpi run on aciss to do this kind of thing much faster (i.e. millions of iterations). Therefore bring your laptop to class on Friday

  8. Materials to include in your write up:


    • A graph of your smoothed data
    • A graph of your data with your initial model plotted on it (step 4)
    • A graph of your data with your final model on it (step 6)
    • Your predicted value for timestep = 1200 and an estimate of the uncertainty of that value
    • The code that you wrote for the blind random parameter search.


  • This is due by 10 pm on Thursday May 28