Contents
Modeling and Simulation in Python
First edition published 2022
by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
and by CRC Press
4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
CRC Press is an imprint of Taylor & Francis Group, LLC
2022 Jason M. Kinser
Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe.
Library of Congress CataloginginPublication Data
Names: Kinser, Jason M., 1962- author.
Title: Modeling and simulation in Python / Jason M. Kinser.
Description: First edition. | Boca Raton, FL : CRC Press, 2022. | Includes bibliographical references and index.
Identifiers: LCCN 2021059491 | ISBN 9781032116488 (hbk) | ISBN 9781032128702 (pbk) | ISBN 9781003226581 (ebk)
Subjects: LCSH: Computer simulation. | Python (Computer program language)
Classification: LCC QA76.9.C65 K56 2022 | DDC 003/.3--dc23/eng/20220124
LC record available at https://lccn.loc.gov/2021059491
ISBN: 978-1-032-11648-8 (hbk)
ISBN: 978-1-032-12870-2 (pbk)
ISBN: 978-1-003-22658-1 (ebk)
DOI: 10.1201/9781003226581
Typeset in Latin Moderrn font
by KnowledgeWorks Global Ltd.
Publisher's note: This book has been prepared from camera-ready copy provided by the authors.
Access the companion website: https://github.com/jmkinser/ModSim411
This book is dedicated to Betty and Budd.
Preface
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 provide 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. For example, why are certain steps selected to be used? What are the steps accomplishing? What are the limits of each step? How can the simulation fail to provide a correct answer?
Without these answers, a simulation may be merely a computer exercise and have no connection to reality.
This textbook presents foundations of modeling and simulation through theory, code, and applications. It begins with simple constructs and then reaches into some real-world applications. However, reality is more complicated than the scope of this text allows, so the models and simulations present only foundations applications.
Topics in this book are selected to delve into different facets of modeling. For example, some chapters deal with connectivity, some deal with kinematic motion, and some deal with rule-based applications. Unfortunately, the book cannot cover the breadth of topics in modeling and simulation.
I do hope that you find this book to be educational, foundational, and in some aspects a bit of fun.
Jason M. Kinser George Mason University Fairfax, VA, USA
Software
Several Python functions have been written for this book. Many of these are provided in the text. Some functions though are only partially presented, as repetitive code is not printed on the pages. One example is the Chess chapter in which a function has several lines dedicated to one player, and then it has nearly identical lines for the other player. The latter are omitted with comments about what has been omitted. A few functions in this book are quite simple to write and are not shown on the pages.
All Python functions written for this book are archived on GitHub. This directory contains both the Python scripts and data files created for the projects therein. Data retrieved from other sources are not included in the archive, but URLs are provided in the text as to the location of the data.
https://github.com/jmkinser/ModSim411
CHAPTER Introduction
DOI: 10.1201/9781003226581-1
E MERGING 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 () 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.
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.
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. reviews a normalization process applied to gene expression arrays, and it converts this theory into an application.
The tone of the text changes in 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, 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.