Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming for Engineers in Python

Similar presentations


Presentation on theme: "Programming for Engineers in Python"— Presentation transcript:

1 Programming for Engineers in Python
Lecture 3: Simulation Autumn

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: Technical issues:
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

12 Code (Cont’d)

13 Code (Cont’d)

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

15 Intuition Super Natural Powers

16 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

17 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

18 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

19

20

21

22 Next Time Use Bonferroni

23 Summary Be careful with your statistics… Simulation

24 Summary (Implementation)
Plan before coding Using Modules Import Constants

25 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)

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

27 Dictionaries (Cont.)

28 Dictionaries (Cont.)


Download ppt "Programming for Engineers in Python"

Similar presentations


Ads by Google