Modeling and Simulation in Python
eBook - ePub

Modeling and Simulation in Python

Jason M. Kinser

Compartir libro
  1. 314 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Modeling and Simulation in Python

Jason M. Kinser

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Modeling and Simulation in Python un PDF/ePUB en línea?
Sí, puedes acceder a Modeling and Simulation in Python de Jason M. Kinser en formato PDF o ePUB, así como a otros libros populares de Computer Science y Programming Games. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2022
ISBN
9781000591125
Edición
1

CHAPTER 1Introduction

DOI: 10.1201/9781003226581-1
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.

CHAPTER 2Random 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
xn+1=(P1xn+P2) modN,(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 P1=16807, P2=0, and N=2311.
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.1 Employing 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...

Índice