Presentation is loading. Please wait.

Presentation is loading. Please wait.

12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-820A, Chris Hill, Room 54-1511,

Similar presentations


Presentation on theme: "12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-820A, Chris Hill, Room 54-1511,"— Presentation transcript:

1 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-820A, tah@mit.edu Chris Hill, Room 54-1511, cnh@gulf.mit.edu Web page http://www-gpsg.mit.edu/~tah/12.010http://www-gpsg.mit.edu/~tah/12.010

2 12/07/201012.010 Lec 232 Today’s Lecture Final project: Order of presentations Guidelines for presentations Comparison of Question 3 from the solutions Graphics formats Statistics and random numbers (maybe) Reminder: Class evaluations can now be done on-line.

3 Class project Groups GroupTopic Shaena Berlin, Anna MerrifieldPredicting Run-up on the North Shore of O’ahu Martina Coccia, Sedar SahinExpansion of Universe Susan FlowersSudoku solver (Mathematica) Charles HallamSudoku solver Kimberly HuppertSlope Stability analysis Kirrah Jones, Ciara SivelsNeuton Diffusion Lauren JozwiakFlexure models Benjamin NieldCheckers Game Curran OiTracking High-Energy Electrons Stephanie Sallum, Harriet LauHangman 12/07/201012.010 Lec 233

4 12/07/201012.010 Lec 234 Class Project Aim of the project is to put together everything you have learned in this course: –Algorithm design –User interface –Numerical methods –Graphics output

5 12/07/201012.010 Lec 235 Ground rules Some of you will be working in groups. The role of each person in the group should be explained in the project description. There is a written and code components to the projects (see web page of requirements). You can solve the problem in any language that you want to use For those that choose Fortran, C or C++, they can choose their a graphics program to display results.

6 12/07/201012.010 Lec 236 Problem statement Each group should develop a problem statement that defines the problem they are trying to solve. Some projects are driven by differential and other types of equations. The nature of these equations, especially important aspects of their derivation and limitations should be discussed in the written text. Other projects are more logical and game theory driven. The logical flow and algorithms should be discussed in written text. The written text should ~2000 words (a few pages of single spaced text).

7 Presentations Each group will have 7-10 minutes for the presentation and demonstration (single person groups have 7 minutes, two person groups have 10-minutes). Some part of the presentation time should be allocated for questions. In general, 1-slide every 2 minutes is a good presentation pace: So single person presentations should have 4-5 slides at most. There is an ~2000 word written description to go with the presentation and detailed information can be included here. If you are using your own computer, make sure you have the correct video adapter (Mac user’s mainly but also some small PC laptops). If you want to present on my mac, let me know and send the presentation materials and codes beforehand. 12/07/201012.010 Lec 237

8 Evaluation of Question 3 results We have solutions to this problem in 4 languages and 5 different solutions: –Matlab ODE45 pushed to RelTol limit –FortranA single step size model –FortranB adaptive step size model –C adaptive step size based on FortranB code –Mathematica: Very large number of WorkingPrecision The following plots show the differences between the solutions and the mean of all except Mathematica 12/07/201012.010 Lec 238

9 Comparison Comparision of solutions CMP Matlab FortranA FortranB C Mathematica X 0.00074 0.00007 0.00001 0.00080 0.00304 Y 0.00136 0.00012 0.00002 0.00146 0.00751 Z 0.00049 0.00005 0.00001 0.00053 0.00702 Notice that Mathematica disagrees with the other solutions. This is very clear in the following plots. These plots are generated with the matlab comparison program on the web site. 12/07/201012.010 Lec 239

10 X component 12/07/201012.010 Lec 2310

11 Y component 12/07/201012.010 Lec 2311

12 Z component 12/07/201012.010 Lec 2312

13 Who is correct 4 of the 5 solutions match each other until the very end of the time interval where we know that maintaining accuracy is difficult. Is Mathematica wrong? Or are all the others wrong? Mathematica could be correct if its high accuracy initial conditions and constant generate different results (can be tested by changing values in Mathematica) However we noted that Mathematica tended to have accuracy at the last value: Setting the time duration to be 1 second rather than 20 seconds generates consistent values at 1-secs. 12/07/201012.010 Lec 2313

14 12/07/201012.010 Lec 2314 Graphics As we have seen some languages (Matlab and mathematica) already have graphics imbedded in them Languages such as Fortran, C and C++ do not explicitly contain graphics but graphics routines can be included in programs if a graphics library can be found. Often graphically output needs to be included in other documents (such as reports and web pages) Quality of the display depends very much on the type of graphics used. For graphics there are too many “standards”

15 12/07/201012.010 Lec 2315 Types of graphics files Graphics files fall into two basic types: –Vector graphics, made of lines and objects (e.g., fonts) that can scaled. The most common of these is Postscript (in its various forms) –Bitmapped graphics defined by pixels that have certain characteristics. The most common of these is GIF (Graphics Interchange Format). These types of formats are good for images especially with continuous tone changes. Bitmapped graphics can look very bad when re-scaled. Some formats are a composite of each type (e.g. Mac PICT format).

16 12/07/201012.010 Lec 2316 Basic Graphic formats Postscript: Comes in different versions (level 1, 2 and 3) and as encapsulated (EPS). EPS files may have a preview of image which is often displayed in WYSIWYG word processors. (The preview image may not always be displayable). Postscript is meant for printers and can maintain very high resolution Not all printers can print all levels of postscript and not all printers understand all parts of postscript. Postscript is a graphics programming language.

17 12/07/201012.010 Lec 2317 Other vector formats Often “drawing” program (opposed to “painting” programs) us a vector graphics format that is unique to the program (e.g, Macdraw). Advantages: –Small file sizes –Scalable –Good for may scientific graphics plots such as line drawings

18 12/07/201012.010 Lec 2318 Pixel formats GIF is the most common but enforcement of the patent on the compression algorithm used has raised concerned Network Portable Graphics (PNG) is an alternative but a lot of older software will not handle this. JPEG (Joint Photographic Experts Group) also common and good for image data These format represent an image as pixels which have attributes such as color. When image is resized, the pixels need to be merged and mapped to the new location.

19 12/07/201012.010 Lec 2319 Examples: Output from Kaleidagraph in PICT format

20 12/07/201012.010 Lec 2320 Bitmap format Basic bit-mapped graphic

21 12/07/201012.010 Lec 2321 Rescaled versions PICT and bitmap

22 12/07/201012.010 Lec 2322 JPEG Version Medium Resolution

23 12/07/201012.010 Lec 2323 JPEG Maximum resolution

24 12/07/201012.010 Lec 2324 Scaled versions of JPEG Effects of scaling graphics

25 12/07/201012.010 Lec 2325 EPS Files (from Photoshop) 1.1 Mbytes (with current power point displays well. In old power point, did not display well )

26 12/07/201012.010 Lec 2326 EPS Direct from Printing This figure will print with high resolution and with Mac PowerPoint >12.1.3 figure displays well.

27 12/07/201012.010 Lec 2327 File sizes For the different images we just looked at: Original KG figure32K (24K no data) PICT 8K Bitmap12K JPEG (medium)44K JPEG (maximum)68K EPS (photoshop)1.1M EPS (KG)40K (no fonts) EPS (KG+fonts)256K

28 12/07/201012.010 Lec 2328 Microsoft Graphics (Object based) 70 71 72 73 74 75 15.415.615.816.016.216.416.616.8 Sextant 10/00 2*Sun Elev (deg) GMT Hrs + M1*x +... M8*x 8 + M9*x 9 -858.71M0 113.17M1 -3.4318M2 0.99882R

29 12/07/201012.010 Lec 2329 Issue with graphics Increasingly documents need to be prepared electronically and generating acceptable graphics is one of the biggest problems still. For electronic presentation of images, best if the original graphics is generated at 72 dots-per-inch. If the graphics is not scaled then these can print OK as well. For printing, vector graphics are most often the best. Display quality: Try antialiasing (process to smooth out edges but some times makes graphics look fuzzy. For WYSWYG word processing, encapsulated postscript generates good prints but may not be rendered in electronic versions (such as web pages). Currently: Still a lot of testing to see what works best.

30 12/07/201012.010 Lec 2330 Graphics packages in programming There are graphics programs that can be purchased or are open source in which data can be supplied and graphics generated There are also graphics libraries that can used and incorporated into user developed software. Some packages come in both forms Example: Generic Mapping Tool (GMT) available from http://gmt.soest.hawaii.edu/ Includes program that can be scripted and routines that can be used in user developed software http://gmt.soest.hawaii.edu/ Caution with these programs is that calls and features can change with versions

31 12/07/201012.010 Lec 2331 Review of statistics Random errors in measurements are expressed with probability density functions that give the probability of values falling between x and x+dx. Integrating the probability density function gives the probability of value falling within a finite interval Given a large enough sample of the random variable, the density function can be deduced from a histogram of residuals.

32 12/07/201012.010 Lec 2332 Example of random variables

33 12/07/201012.010 Lec 2333 Histograms of random variables

34 12/07/201012.010 Lec 2334 Characterization Random Variables When the probability distribution is known, the following statistical descriptions are used for random variable x with density function f(x): Square root of variance is called standard deviation

35 12/07/201012.010 Lec 2335 Theorems for expectations For linear operations, the following theorems are used: –For a constant = c –Linear operator = c –Summation = + Covariance: The relationship between random variables f xy (x,y) is joint probability distribution:

36 12/07/201012.010 Lec 2336 Estimation on moments Expectation and variance are the first and second moments of a probability distribution As N goes to infinity these expressions approach their expectations. (Note the N-1 in form which uses mean)

37 12/07/201012.010 Lec 2337 Probability distributions While there are many probability distributions there are only a couple that are common used:

38 12/07/201012.010 Lec 2338 Probability distributions The chi-squared distribution is the sum of the squares of r Gaussian random variables with expectation 0 and variance 1. With the probability density function known, the probability of events occurring can be determined. For Gaussian distribution in 1-D; P(|x|<1  ) = 0.68; P(|x|<2  ) = 0.955; P(|x|<3  ) = 0.9974. Conceptually, people thing of standard deviations in terms of probability of events occurring (ie. 68% of values should be within 1-sigma).

39 12/07/201012.010 Lec 2339 Central Limit Theorem Why is Gaussian distribution so common? “The distribution of the sum of a large number of independent, identically distributed random variables is approximately Gaussian” When the random errors in measurements are made up of many small contributing random errors, their sum will be Gaussian. Any linear operation on Gaussian distribution will generate another Gaussian. Not the case for other distributions which are derived by convolving the two density functions.

40 12/07/201012.010 Lec 2340 Random Number Generators Linear Congruential Generators (LCG) – x(n) = a * x(n-1) + b mod M Probably the most common type but can have problems with rapid repeating and missing values in sequences The choice of a b and M set the characteristics of the generator. Many values of a b and M can lead to not-so-random numbers. One test is to see how many dimensions of k-th dimensional space is filled. (Values often end up lying on planes in the space. Famous case from IBM filled only 11-planes in a k-th dimensional space. High-order bits in these random numbers can be more random than the low order bits.

41 12/07/201012.010 Lec 2341 Example coefficents Poor IBM case: a = 65539, b = 0 and m = 2^31. MATLAB values: a = 16807 and m = 2^31 - 1 = 2147483647. Knuth's Seminumerical Algorithms, 3rd Ed., pages 106--108: a = 1812433253 and m = 2^32 Second order algorithms: From Knuth: x_n = (a_1 x_{n-1} + a_2 x_{n-2}) mod m a_1 = 271828183, a_2 = 314159269, and m = 2^31 - 1.

42 12/07/201012.010 Lec 2342 Gaussian random numbers The most common method (Press et al.) Generated in pairs from two uniform random number x and y z1 = sqrt(-2ln(x)) cos(2*pi*y) z2 = sqrt(-2ln(x)) sin(2*pi*y) Other distributions can be generated directly (eg, gamma distribution), or they can be generated from the Gaussian values (chi^2 for example by squaring and summing Gaussian values) Adding 12-uniformly distributed values also generates close to a Gaussian (Central Limit Theorem)

43 12/07/201012.010 Lec 2343 Conclusion Examined random number generators: Tests should be carried out to test quality of generator or implement your (hopefully previously tested) generator Look for correlations in estimates and correct statistical properties (i.e., is uniform truly uniform) Test some algorithms with matlab: randtest.mrandtest.m

44 12/07/201012.010 Lec 2344 Summary of Today’s class Aim of the project is to put together everything you have learned in this course: –Algorithm design –User interface –Numerical methods –Graphics output Analysis of Question 3 Graphics formats and issues. Statistics and random numbers. Remember on-line class evalutions


Download ppt "12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-820A, Chris Hill, Room 54-1511,"

Similar presentations


Ads by Google