2.2.7.A DataAndSimulationEverywhere



Activity 2.2.7 Data and Simulation EverywhereIntroductionMany real life situations are inherently random. A nice example is provided by the atoms that make up all matter: the movement of atoms bouncing off of each other is more random than predictable. Even a random model, however, will reliably produce a consistent set of results as long as the data set is large enough. Producing a large set of data by repeatedly running a simulation is called Monte Carlo simulation, named after a famous casino. The ball on the roulette wheel shown in the picture will land in a random spot during each spin, but the result of many spins is always the same: the ball lands equally frequently in the various slots in the roulette wheel. The consequences are that with a large enough number of spins, the casino always wins the players' money.In this activity, you use Monte Carlo simulation of Ezee—which is a dice game with random results in any single trial—to reach solid conclusions that are not random. MaterialsComputer with PythonProcedure Form pairs as directed by your teacher. Meet or greet each other to practice professional skills. In this activity you will be pair programming. Decide on one or more team norms about making decisions. Part I: Collecting, Visualizing, and Describing DataUse code from the previous activity. You should have a function game() that returns the number of rolls needed to win, as shown below.In []:Out[]:In []:Out[]:game()34game()12 Create a function monte_carlo(number_of_games) that accepts an integer number_of_games. The function should play Ezee repeatedly and return a list with one number for each game played. The numbers report how many trials were needed to win the game during that trial.def monte_carlo(number_of_games): '''number_of_games is an int. Plays that many games of Ezee. Returns a list of ints. Each int is the number of rolls needed to win one game of Ezee. ''' results = ???? # Initialize # Use a counted loop and aggregate the results.In []:Out[]:monte_carlo(5)[34, 12, 30, 42, 6] Run the experiment three times with 10 trials. Do you get the same results each time?To understand patterns in data, you visualize the data. To visualize the results, we will use the following two Python modules:ModuleContains functions and classes for:numpyFunctions and classes for math and statisticsmatplotlib.pyplotFunctions and classes for graphing and visualizing dataAdd the following code to your file. Place the import statements at the top of your file. The three new functions can be placed anywhere in the file.import matplotlib.pyplot as plt import numpy as npdef create_figure(outcomes): '''Create a histogram showing frequency of 1 to 70 rolls ''' fig, ax = plt.subplots(1, 1) frequencies, left_endpoints, patches = ax.hist(outcomes, bins = np.arange(0.5, 70.5, 1), color='cyan') ax.set_xlabel('Number of rolls') ax.set_ylabel('Frequency = number of games') ax.set_title('Distribution of game length for Ezee\n',fontsize=20) style_axes(ax) fig.set_facecolor('white') ax.text(50,0.9*max(frequencies), 'n='+str(len(outcomes)),family='Georgia') fig.show() return axdef style_axes(axes, font='Georgia', size=16): '''Set title, axes, ticks to 16 pt Georgia or other font/size ''' for item in ([axes.title, axes.xaxis.label, axes.yaxis.label] + axes.get_xticklabels() + axes.get_yticklabels()): item.set_family(font) item.set_fontsize(size)def experiment(trials): ''' Run the experiment and visualize the results ''' results = monte_carlo(trials) axes = create_figure(results) style_axes(axes) return resultsRun the experiment with 100 trials. You may need to select the matplotlib icon from the task bar as shown below. The histogram shows the frequency of each outcome. Describe the pattern you see in the data.In []:experiment(100)Run the experiment three times with 1000 trials. Compare and contrast the results of the three experiments. What do the results have in common? How are the results different from one another?To identify the median and quartiles of a list of numbers, we put the numbers in order. The sort() method of a list sorts a list in place; the resulting sorted list is stored using the same variable name rather than returned as a new value. Use sort() to sort the list.In []:In []:In []:results = experiment(1000)results.sort()resultsRecord the value 500th element of the sorted list as shown below. Is this the median, the mean, or the mode? Explain how you know.In []:results[499]Value: Which element of the sorted list represents the first and third quartiles of the distribution? Evaluate that element and record the result.Q1 = results[ __ ] --> 25% of games won in _____ rolls or fewerQ3 = results[ __ ] --> 75% of games won in _____ rolls or fewerCreate a box and whisker plot describing the number of rolls needed to win Ezee.Describe the center, spread, and shape of the distribution of the number of rolls needed to win Ezee.Part II: Modeling and Simulation A simulation is the execution of a model. Models have built-in assumptions that are embedded in the code.By modifying the code, an assumption can be given a variable value and parameterized in the model so that the value can be changed. Experimenters can pick a result (e.g., the median) calculated from the simulation and see how the result is affected by changes to the parameter. Some details in real phenomena cause random variation. Monte Carlo simulation can still produce consistent, repeatable results to describe the distribution of outcomes.A model is an abstraction that leaves out some of the details of the real phenomenon. By abstracting away these details, the model depends on a built-in assumption that these particular details don't matter. Built-in assumptions. What details are built into the Ezee model?Parameters. To parameterize an assumption of a model, you change the value of the assumption. Our Ezee model assumed 6-sided dice. How would you go about changing the number of sides on each die in the Ezee model?Details lost in abstraction. What details about real dice were abstracted away? Do these details make the outcomes of Ezee games different in real dice than in our model?Understand, predict, and communicate. Models and simulations allow us to understand natural phenomena from ecology and physics to human behavior. Simulations can also help us predict the future, though our predictions are often wrong. Simulations can also help people communicate with each other about phenomena. Simulations of Earth's climate are a hot topic of current scientific study because many scientists believe Earth is getting hotter as a result of carbon dioxide added to the atmosphere by humans. Inspect the visualizations at assumptions. All models of the Earth's climate have built-in assumptions. All climate models, for example, assume that the energy of sunlight entering the Earth's atmosphere doesn't disappear. Models assume the energy is either reflected or absorbed by the Earth system and converted to chemical energy (through photosynthesis) or converted to heat energy, perhaps to be radiated again as infrared light, the "color" with which warm things glow. This assumption is a physical law known as the Conservation of Energy. Describe the Law of Conservation of Energy.Parameters. In the visualizations you inspected, the y-axis displays the result of a calculation made by a simulation. The simulation models use many parameters, including the atmospheric concentration of carbon dioxide. The values for these parameters are provided to the model as an input, based on measurements of Earth. In many of the visualizations you inspected, only one parameter was given a set of values that changed year to year within the simulation run. What were some of the parameters used in these climate models?Details lost in abstraction. Climate models use a mesh to describe the earth's oceans, surface, and atmosphere. A mesh is like a two-dimensional gird or three-dimensional set of square-like or cube-like cells. The models use a single value for each parameter for each cell. Current models use cells that are about 10 miles across. The real Earth has variations within 10 miles in land use, temperature, etc. How might scientists investigate the effects of omitting these details from their simulations?Models can be checked against themselves by parameterizing the details. The details are left out because of the models take longer with a finer mesh. A model can be created with a tighter mesh. The simulation will take longer, but a portion of a scientist's results can be compared against the results of the same model with a finer mesh.Big Data, modeling and simulation, and careers. Modeling and simulation is a subfield of computer science dedicated to using the power of computers to examine, explain, or predict real phenomena in all fields. Data and simulation go well together. Data from real measurements allow us to make better simulations, and simulations produce virtual data that can be analyzed. These data help us build better models by telling us which details are important to include and which details can be abstracted away because they don't affect the results. Data also tell us what values are reasonable for parameters used in the model.With your partner, pick one of the following groups of career fields and research one or more examples of how simulation is being used to help people in careers or research within that group. Prepare a two- to four-minute presentation detailing work in simulation in a field from one of the following groups.Clothing design, art, and fashionArchitecture, construction, and civil engineering Medicine and neuroscienceFlight and transportationManufacturing and 3D printingMovies, animation, graphic video games, and virtual realitiesMarketing, sales, stock trading, and economic developmentEnvironment, climate, ecology, and conservationAgriculture and energy productionYour presentation must include:An introduction explaining how simulation is used in your chosen fieldA description of at least one specific simulation in that field, including a graphic that illustrates a result of simulationAn overview of at least one career associated directly with producing or using simulations in the chosen fieldIdentification of some measurements that can inform the simulationsConclusion QuestionsDescribe how simulation can be used to make predictions for a phenomenon even if the phenomenon is affected by random variation.How has simulation been used to create services and products that you use? ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download