1 / 28

Programming for Engineers in Python

Programming for Engineers in Python. Lecture 3: Simulation. Autumn 2011-12. Lecture 2: Highlights. Compiler, interpreter Variables, types, operators. Using the Editor. Press F5. Today: Simulation. What are simulations good for? Examples Flight simulator Meteorology Production line.

flossiec
Download Presentation

Programming for Engineers in Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming for Engineers in Python Lecture 3: Simulation Autumn 2011-12

  2. Lecture 2: Highlights • Compiler, interpreter • Variables, types, operators

  3. Using the Editor Press F5

  4. Today: Simulation • What are simulations good for? • Examples • Flight simulator • Meteorology • Production line Typhoon Mawar 2005 computer simulation

  5. Power Lines and Rare Diseases • Researchers decide to investigate correlation between proximity to power lines and rare diseases • 100 diseases, occurrence rate for each is known in the general population • Sample 1000 people that live near power lines, record number of ill people for every disease • For each disease, check whether there is a significant difference (< 0.05) between the sampled and the general occurrence rate

  6. Power Lines and Rare Diseases • Research results showed that few diseases correlate with life near power lines • Researchers concluded that living near power lines are bad for you • We will use simulation to prove they were wrong in their analysis!

  7. Simulation • The plan: • Simulate 1000 people from “general” population • Count number of sick people for each disease • Find diseases were the number of actual sick people from the sampling is significantly higher than expected number of sick people • We know that there is no relation: if we find a disease with occurrence rate is significantly higher than the general population – the researchers conclusion might be wrong (why?) • Technical issues: • Define diseases • How to simulate sick people? • How to define significance?

  8. Work plan Randomly produce sampling set For all diseases initiate observed sick people to be 0 For every person that has disease y, increase the number of people observed with y by 1 If there is a significant increase in the observed number of ill people - report

  9. Code - Imports • Import statement: “take” some piece of code from somewhere else • How did I know about random/binom_test implementation in python?

  10. Code - Preparations • Why use constants? • Explain syntax

  11. Code (Cont’d)

  12. Code (Cont’d)

  13. Surprise! • There are a few diseases that are correlated to the sample • Although the sample simulated the “general” population • What is going on?!

  14. Intuition Super Natural Powers

  15. Intuition (Cont’d) • We are looking for a person with supernatural powers! • Given 25 “hidden” cards guess for each card its series (Spades, Hearts, Diamonds or Clubs) • Probability to get one card correctly 0.25 • Guessing 25 cards is definitely super natural! We are looking for people who maintain “some” super natural powers (pval < 0.05…) • We are looking among 100 people to find those with “some” super natural powers

  16. Intuition (Cont’d) • It is obvious that some of the 100 people will probably guess better than the average • When so many trials are given (100), there will be some “very lucky” guys that we will consider to have supernatural powers

  17. Intuition (Cont’d) • This is the same for the power lines example! • 1000 people near power lines, 25 cards • 100 diseases, 100 “supernatural” candidates • Expected probability per disease/candidate: “small” (power lines), 0.25 (supernatural powers) • Observed: number of sick people (power lines), number of correct guessed cards (supernatural powers) • Implementation of this simulation will be part of your next homework assignment

  18. Next Time Use Bonferroni

  19. Summary • Be careful with your statistics… • Simulation

  20. Summary (Implementation) • Plan before coding • Using Modules • Import • Constants

  21. Tuples • Fixed size • Immutable (similarly to Strings) • What are they good for (compared to list)? • Simpler (“light weight”) • Staff multiple things into a single container • Immutable (e.g., records in database)

  22. Dictionaries (Hash Tables) keys values • Key – Value mapping • Fast! • Usage: • Database • Dictionary • Phone book

  23. Dictionaries (Cont.)

  24. Dictionaries (Cont.)

More Related