The use of Python as a powerful computational tool is expanding with great strides. Python is a language which is easy to use, and the libraries of tools provides it with efficient versatility. As the tools continue to expand, users can create insightful models and simulations. While the tools offer an easy method to create a pipeline, such constructions are not guaranteed to provide correct results. A lot of things can go wrong when building a simulation - deviously so. Users need to understand more than just how to build a process pipeline.
Modeling and Simulation in Python introduces fundamental computational modeling techniques that are used in a variety of science and engineering disciplines. It emphasizes algorithmic thinking skills using different computational environments, and includes a number of interesting examples, including Shakespeare, movie databases, virus spread, and Chess.
Key Features:
Several theories and applications are provided, each with working Python scripts.
All Python functions written for this book are archived on GitHub.
Readers do not have to be Python experts, but a working knowledge of the language is required. Students who want to know more about the foundations of modeling and simulation will find this an educational and foundational resource.
Frequently asked questions
Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go. Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Modeling and Simulation in Python by Jason M. Kinser in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.
EMERGING COMPUTATIONAL prowess is creating new levels of knowledge and analysis. To be effective, these new models and simulations must have ties to realities, thus providing value to commercial, medical, and defensive applications. For example, massive programs are used to simulate vehicle collisions with enough detail to determine the action of each bolt. However, if those bolts are not realistic (perhaps modeled as plastic instead of metal), then the simulation is merely an academic exercise with little value to the automotive industry.
Such programs need years to build and test. In this example, collecting the data, which requires the disassembling of an entire vehicle, can consume months of work. While such simulations would be fun to employ, they are well beyond the scope of this text. Rather, these chapters will focus on simpler, self-contained models and simulations. It does include a variety of applications which have significant differences, in order to span some of the width of this field. Examples in this text must necessarily be simple, in order to complete the demonstrations within a reasonable volume of pages.
The simplest concept prevalent in many simulations is that of a stochastic process. Such simulations rely on randomness within predefined boundaries. Thus, the first few chapters review random number concepts and provide some applications.
The Monte Carlo process (Chapter 4) builds on this theory, providing demonstrations of smaller systems. Following it is a review of Schelling's model which, in fact, organizes data through a random process.
Chapter 6 advances the use of stochastic processes to build Hidden Markov Models (HMMs). Several following chapters use the HMM for a variety of applications, ending in a light-hearted finale with the ability to create new Shakespearean text.
Chapter 10 shifts into a different aspect of modeling. Often events, or data collected from an event, are connected, and these models of analyzing such connections are considered.
Models often are based on mathematical descriptions. Chapter 11 reviews a normalization process applied to gene expression arrays, and it converts this theory into an application.
The tone of the text changes in Chapter 12 as it ventures into modeling mathematical and physical phenomena. This chapter begins the journey with effective methods of solving simultaneous linear equations. Chapter 13 models linear and accelerated motion. This leads into Chapter 14 which models oscillatory motion. This chapter will also present issues in the model which creates errors. While this chapter explains the cause and provides a couple of fixes, the real solution comes in the next chapter.
Building on previous chapters, Chapter 15 considers coupled equations, modeling systems with multiple variables dependent on each other. Perhaps this chapter is the most important to converting theory into realistic applications.
With most of the theory in place, the final chapters consider several applications. These include solving puzzles, modeling the spread of a virus, and creating a program that can play chess.
The goal of this text is to introduce foundations of simulation and modeling. Several theories and applications are provided, each with working Python scripts. In all cases, much more complicated applications do exist, but as the goal of the book is to introduce concepts and applications, these complicated applications are not pursued.
All applications are presented with Python scripts. The Python language is chosen because it is freely available, powerful, and quite popular. The text assumes that the reader has a good foundation in Python and the numpy module. Explanations of numpy functions will be provided when they are employed, but the foundation concepts of numpy are assumed. Readers do not have to be Python experts, but a working knowledge of the language is required.
Finally, a few typesetting conventions are employed to maintain clarity:
Python module names are in italics.
Python function names are in boldface.
Python variables are in equally-spaced, teletype font.
Mathematical variables are in italics.
Mathematical matrices are in boldface.
The journey begins with a review of random numbers.
CHAPTER2Random Values
DOI: 10.1201/9781003226581-2
COMPUTERS are calculating machines, and no matter how fancy an algorithm becomes, the real work is performed in manipulating bytes which represent numbers or are associated with text in a specifically prescribed manner.
From this is born the paradox of random numbers. The concept of a random number is easy in that it is a number arbitrary value within a given range. Yet, the computer, which is purely a calculating machine, must be able to generate an arbitrary random number.
Random numbers are important to simulations as they allow for injudicious decisions to be made during the process. This could be as simple as creating a simulation to play a card game requiring the deck of cards to be shuffled before play begins. Or this simulation could be enormously complicated in which random values can be used to drive a host of interacting phenomena.
This chapter reviews some aspects of random numbers and Python commands to generate these numbers. Work from this chapter will be used in several subsequent chapters.
2.1 Defining Random
A computer script to generate a random number requires some parameters to be defined. First is the range, defining the lowest and highest allowed values. Second is the distribution, defining the probabilities within that range of generating a number. Of these, the easiest is a range from 0 to 1 with an equal probability distribution. The latter means that the probability of generating a number in the middle of the range is the same as generating a number at the ends of the range. The system has the same chance of returning a 0.5 as it does a 0.9.
One popular formula for generating a random number is
(2.1)
where P1 and P2 are parameters, N defines the range, and mod is the modulo operator. The value of xn is a number which is usually the previous random number or obtained from other source. Park and Miller [1] suggested , , and .
This equation is realized in Code 2.1. Each value of x1 generates a new value of x2. The output values are divided by N to confine to a range of 0 to 1. If the sequence of numbers is random, then there would not be any relationships between consecutive values. None seems apparent upon first glance.
Code 2.1Employing a random number generator function.
The initial value of x1 is the seed, and each seed generates the same sequence of values. However, two seeds quite close to each other in v...