100% found this document useful (6 votes)
282 views

Hands On Simulation Modeling With Python Develop Simulation Models to Get Accurate Results and Enhance Decision Making Processes 1st Edition by Giuseppe Ciaburro 1838985093 9781838985097 - Read the ebook now with the complete version and no limits

The document promotes ebook downloads from ebookball.com, featuring various titles focused on simulation modeling, data analysis, and computational techniques. It highlights specific books such as 'Hands-On Simulation Modeling with Python' and 'Business Economics and Finance with MATLAB.' Users can access these resources in multiple formats for convenient reading on any device.

Uploaded by

losakorchel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
282 views

Hands On Simulation Modeling With Python Develop Simulation Models to Get Accurate Results and Enhance Decision Making Processes 1st Edition by Giuseppe Ciaburro 1838985093 9781838985097 - Read the ebook now with the complete version and no limits

The document promotes ebook downloads from ebookball.com, featuring various titles focused on simulation modeling, data analysis, and computational techniques. It highlights specific books such as 'Hands-On Simulation Modeling with Python' and 'Business Economics and Finance with MATLAB.' Users can access these resources in multiple formats for convenient reading on any device.

Uploaded by

losakorchel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Quick and Easy Ebook Downloads – Start Now at ebookball.

com for Instant Access

Hands On Simulation Modeling With Python Develop


Simulation Models to Get Accurate Results and
Enhance Decision Making Processes 1st Edition by
Giuseppe Ciaburro 1838985093 9781838985097

https://ebookball.com/product/hands-on-simulation-modeling-
with-python-develop-simulation-models-to-get-accurate-
results-and-enhance-decision-making-processes-1st-edition-
by-giuseppe-ciaburro-1838985093-9781838985097-15116/

OR CLICK BUTTON

DOWLOAD NOW

Instantly Access and Download Textbook at https://ebookball.com


Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Business Economics and Finance with MATLAB GIS and


Simulation Models 1st Edition by Patrick L Anderson ISBN
0471719297 9781584883487
https://ebookball.com/product/business-economics-and-finance-with-
matlab-gis-and-simulation-models-1st-edition-by-patrick-l-anderson-
isbn-0471719297-9781584883487-13842/

ebookball.com

Introduction to Computational Cardiology Mathematical


Modeling and Computer Simulation 1st Edition by Boris Ja
Kogan ISBN 0387766863 9780387766867
https://ebookball.com/product/introduction-to-computational-
cardiology-mathematical-modeling-and-computer-simulation-1st-edition-
by-boris-ja-kogan-isbn-0387766863-9780387766867-14578/

ebookball.com

Excel Data Analysis modeling and simulation 1st Edition by


Hector Guerrero ISBN 3642108342 9783642108341

https://ebookball.com/product/excel-data-analysis-modeling-and-
simulation-1st-edition-by-hector-guerrero-
isbn-3642108342-9783642108341-15884/

ebookball.com

Computational Modeling and Simulation of Intellect 1st


Edition by Boris Igelnik ISBN 1609605527 9781609605520

https://ebookball.com/product/computational-modeling-and-simulation-
of-intellect-1st-edition-by-boris-igelnik-
isbn-1609605527-9781609605520-9100/

ebookball.com
Excel Data Analysis Modeling and Simulation 1st Edition by
Hector Guerrero ISBN 3642108350 9783642108358

https://ebookball.com/product/excel-data-analysis-modeling-and-
simulation-1st-edition-by-hector-guerrero-
isbn-3642108350-9783642108358-9454/

ebookball.com

Modeling and Simulation of Dynamic Systems 1st edition by


Robert Woods, Kent Lawrence 0133373797 9780133373790

https://ebookball.com/product/modeling-and-simulation-of-dynamic-
systems-1st-edition-by-robert-woods-kent-
lawrence-0133373797-9780133373790-18476/

ebookball.com

Theory of Modeling and Simulation 3rd Edition by Bernard


Zeigler, Alexandre Muzy, Ernesto Kofman 0128133708
9780128133705
https://ebookball.com/product/theory-of-modeling-and-simulation-3rd-
edition-by-bernard-zeigler-alexandre-muzy-ernesto-
kofman-0128133708-9780128133705-15110/

ebookball.com

Theory of Modeling and Simulation 3rd edition by Bernard


Zeigler, Tag Gon Kim, Herbert Praehofer 9780128134078
0128134070
https://ebookball.com/product/theory-of-modeling-and-simulation-3rd-
edition-by-bernard-zeigler-tag-gon-kim-herbert-
praehofer-9780128134078-0128134070-15182/

ebookball.com

Modeling and Simulation in Science Engineering and


Technology 1st edition by Giovanna Guidoboni, Alon Harris,
Riccardo Sacco 3030258858 978-3030258856
https://ebookball.com/product/modeling-and-simulation-in-science-
engineering-and-technology-1st-edition-by-giovanna-guidoboni-alon-
harris-riccardo-sacco-3030258858-978-3030258856-20506/

ebookball.com
Hands-On
Simulation Modeling
with Python

Develop simulation models to get accurate results and enhance


decision-making processes

Giuseppe Ciaburro

BIRMINGHAM—MUMBAI
Hands-On Simulation Modeling with Python
Copyright © 2020 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers
and distributors, will be held liable for any damages caused or alleged to have been caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Sunith Shetty


Acquisition Editor: Devika Battike
Senior Editor: David Sugarman
Content Development Editor: Joseph Sunil
Technical Editor: Sonam Pandey
Copy Editor: Safis Editing
Project Coordinator: Aishwarya Mohan
Proofreader: Safis Editing
Indexer: Manju Arasan
Production Designer: Joshua Misquitta

First published: July 2020


Production reference: 1160720

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-83898-509-7
www.packt.com
Packt.com
Subscribe to our online digital library for full access to over 7,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.

Why subscribe?
• Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
• Improve your learning with Skill Plans built especially for you
• Get a free eBook or video every month
• Fully searchable for easy access to vital information
• Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at packt.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for
a range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.
Contributors
About the author
Giuseppe Ciaburro holds a PhD in environmental technical physics, along with two
master’s degrees. His research was focused on machine learning applications in the study
of urban sound environments. He works at the Built Environment Control Laboratory
at the Università degli Studi della Campania Luigi Vanvitelli, Italy. He has over 18 years’
professional experience in programming (Python, R, and MATLAB), first in the field
of combustion, and then in acoustics and noise control. He has several publications to
his credit.
About the reviewers
Greg Walters has been involved with computers and computer programming since
1972. He is well versed in Visual Basic, Visual Basic.NET, Python, and SQL, and is an
accomplished user of MySQL, SQLite, Microsoft SQL Server, Oracle, C++, Delphi,
Modula-2, Pascal, C, 80x86 Assembler, COBOL, and Fortran. He is a programming
trainer and has trained numerous individuals in many pieces of computer software,
including MySQL, Open Database Connectivity, Quattro Pro, Corel Draw!, Paradox,
Microsoft Word, Excel, DOS, Windows 3.11, Windows for Workgroups, Windows 95,
Windows NT, Windows 2000, Windows XP, and Linux. He is currently retired and, in his
spare time, is a musician and loves to cook. He is also open to working as a freelancer on
various projects.

Yoon Hyup Hwang is a seasoned data scientist in the marketing and finance industries
and is the author of two applied machine learning books. He has almost a decade of
experience building numerous machine learning models and data science products.
He holds an M.S.E. in Computer and Information Technology from the University of
Pennsylvania and a B.A. in Economics from the University of Chicago. He enjoys training
various martial arts, snowboarding, and roasting coffee. He currently lives in the Greater
New York Area with his artist wife, Sunyoung, and a playful dog, Dali (named after
Salvador Dali).

Packt is searching for authors like you


If you’re interested in becoming an author for Packt, please visit authors.
packtpub.com and apply today. We have worked with thousands of developers and
tech professionals, just like you, to help them share their insight with the global tech
community. You can make a general application, apply for a specific hot topic that we are
recruiting an author for, or submit your own idea.
Table of Contents

Preface

Section 1:
Getting Started with Numerical Simulation
1
Introducing Simulation Models
Introducing simulation models  4 Problem analysis 11
Decision-making workflow 5 Data collection 11
Comparing modeling and simulation 6 Setting up the simulation model 11
Pros and cons of simulation modeling 6 Simulation software selection 13
Simulation modeling terminology 7 Verification of the software solution 14
Validation of the simulation model 15
Classifying simulation models 9 Simulation and analysis of results 16
Comparing static and dynamic models 9
Comparing deterministic and Dynamical systems modeling 16
stochastic models 9 Managing workshop machinery 17
Comparing continuous and discrete Simple harmonic oscillator 18
models10 Predator-prey model 20

Approaching a simulation- Summary22


based problem 10

2
Understanding Randomness and Random Numbers
Technical requirements  24 Examples of stochastic processes 26
Stochastic processes 24 The Bernoulli process 26
Random walk 27
Types of stochastic process 25
The Poisson process 29 Exploring generic methods for
random distributions 51
Random number simulation 30
The inverse transform sampling method 51
Probability distribution 31
The acceptance-rejection method 52
Properties of random numbers 32
Random number generation
The pseudorandom number using Python 53
generator33
Introducing the random module 54
The pros and cons of a random
The random.random() function 54
number generator 33
The random.seed() function 55
Random number generation algorithms 34
The random.uniform() function 56
Linear congruential generator 34
The random.randint() function 56
Random numbers with uniform
The random.choice() function 57
distribution37
The random.sample() function 58
Lagged Fibonacci generator 39
Generating real-valued distributions 58
Testing uniform distribution 42
Summary 59
The chi-squared test 42
Uniformity test 45

3
Probability and Data Generation Processes
Technical requirements  62 Exploring probability
Explaining probability concepts  62 distributions69
Types of events 62 Probability density function 70
Calculating probability 63 Mean and variance 71
Probability definition with an example 63 Uniform distribution 72
Binomial distribution 76
Understanding Bayes’ theorem 66 Normal distribution 79
Compound probability 66
Bayes’ theorem 68 Summary83

Section 2:
Simulation Modeling Algorithms and
Techniques
4
Exploring Monte Carlo Simulations
Technical requirements  88 simulation101
Introducing Monte Carlo Generating probability distributions 101
simulation88 Numerical optimization 102
Monte Carlo components 89 Project management 103
First Monte Carlo application 89
Performing numerical
Monte Carlo applications  90
integration using
Applying the Monte Carlo method for
Monte Carlo 104
Pi estimation 91
Defining the problem 104
Understanding the central limit Numerical solution 106
theorem96 Min-max detection 108
Law of large numbers 96 Monte Carlo method 109
Central limit theorem  97 Visual representation 111

Applying Monte Carlo Summary113

5
Simulation-Based Markov Decision Processes
Technical requirements  116 The Bellman equation
Overview of Markov processes 116 explained138
The agent-environment interface 117 Dynamic programming concepts  139
Exploring MDPs 119 Principle of optimality 139
Understanding the discounted The Bellman equation 140
cumulative reward  122
Multi-agent simulation 140
Comparing exploration and
exploitation concepts 123 Summary142

Introducing Markov chains 124


Transition matrix 125
Transition diagram 126

Markov chain applications 127


Introducing random walks 127
Simulating a one-dimensional random
walk129
Simulating a weather forecast 132
6
Resampling Methods
Technical requirements  144 Demystifying bootstrapping  156
Introducing resampling Introducing bootstrapping 156
methods  144 Bootstrap definition problem 157
Sampling concepts overview 145 Bootstrap resampling using Python 158
Reasoning about sampling  146 Comparing Jackknife and bootstrap 161
Pros and cons of sampling 146
Explaining permutation tests 162
Probability sampling 147
How sampling works 147
Approaching cross-validation
techniques163
Exploring the Jackknife The validation set approach 163
technique148 Leave-one-out cross validation 164
Defining the Jackknife method 148 K-fold cross validation 165
Estimating the coefficient of variation  150 Cross-validation using Python 165
Applying Jackknife resampling using
Python 151 Summary168

7
Using Simulation to Improve and Optimize Systems
Technical requirements  170 Approaching Newton-Raphson for
numerical optimization 184
Introducing numerical
optimization techniques 170 Applying the Newton-Raphson
technique  185
Defining an optimization problem 171
Explaining local optimality  173 Deepening our knowledge of
Defining the descent methods 174 stochastic gradient descent 189
Approaching the gradient descent Discovering the multivariate
algorithm174 optimization methods in Python191
Understanding the learning rate 177
The Nelder–Mead method 191
Explaining the trial and error method 178
Powell's conjugate direction algorithm 195
Implementing gradient descent in
Summarizing other optimization
Python178
methodologies197
Facing the Newton-Raphson Summary198
method183
Using the Newton-Raphson algorithm
for root-finding  183
Section 3:
Real-World Applications
8
Using Simulation Models for Financial Engineering
Technical requirements  202 Handling the stock price trend as time
series213
Understanding the geometric
Brownian motion model  202 Introducing the Black-Scholes model 215
Applying Monte Carlo simulation 216
Defining a standard Brownian motion 203
Addressing the Wiener process as Studying risk models for
random walk 204 portfolio management 220
Implementing a standard Brownian
Using variance as a risk measure 221
motion 205
Introducing the value-at-risk metric 221
Using Monte Carlo methods for Estimating the VaR for some NASDAQ
stock price prediction 207 assets223
Exploring the Amazon stock price trend 208 Summary232

9
Simulating Physical Phenomena Using Neural Networks
Technical requirements  234 Splitting the data  256
Introducing the basics of neural Explaining multiple linear regression 258
networks  234 Understanding a multilayer perceptron
regressor model 260
Understanding biological neural
networks 235 Exploring deep neural networks264
Exploring ANNs 236
Getting familiar with convolutional
Understanding feedforward neural networks 264
neural networks 242 Examining recurrent neural networks 265
Analyzing LSTM networks 266
Exploring neural network training 243

Simulating airfoil self-noise Summary267


using ANNs 244
Importing data using pandas 246
Scaling the data using sklearn 249
Viewing the data using matplotlib 252
10
Modeling and Simulation for Project Management
Technical requirements  270 Addressing management problems
using MDPtoolbox 278
Introducing project
management270 Changing the probability of fire 282

Understanding what-if analysis 271 Scheduling project time using


Monte Carlo simulation 284
Managing a tiny forest problem272
Defining the scheduling grid 285
Summarizing the Markov decision
Estimating the task's time 286
process272
Developing an algorithm for project
Exploring the optimization process 273
scheduling287
Introducing MDPtoolbox 275
Exploring triangular distribution 288
Defining the tiny forest management
example 275 Summary294

11
What's Next?
Summarizing simulation Modeling in healthcare 304
modeling concepts  295 Modeling in financial applications 305
Generating random numbers 296 Modeling physical phenomenon 306
Applying Monte Carlo methods 298 Modeling public transportation 307
Addressing the Markov decision process299 Modeling human behavior 308
Analyzing resampling methods 300
Next steps for simulation
Exploring numerical optimization
modeling309
techniques302
Increasing the computational power 309
Using artificial neural networks for
simulation303 Machine learning-based models  311
Automated generation of simulation
Applying simulation model to models312
real life 304
Summary313
Other Books You May Enjoy
Leave a review - let other
readers know what you think 317
Preface
Simulation modeling helps you to create digital prototypes of physical models to analyze
how they work and predict their performance in the real world. With this comprehensive
guide, you’ll learn about various computational statistical simulations using Python.
Starting with the fundamentals of simulation modeling, you’ll learn about concepts
such as randomness and explore data generating processes, resampling methods,
and bootstrapping techniques. You’ll then cover key algorithms such as Monte Carlo
simulations and the Markov Decision Process, which are used to develop numerical
simulation models, and discover how they can be used to solve real-world problems.
As you make progress, you’ll develop simulation models to help you get accurate results
and enhance decision-making processes. Using optimization techniques, you’ll learn to
modify the performance of a model to improve results and make optimal use of resources.
The book will guide you through creating a digital prototype using practical use cases
for financial engineering, prototyping project management to improve planning, and
simulating physical phenomena using neural networks.
By the end of this book, you’ll be able to construct and deploy simulation models of your
own to solve real-world challenges.

Who this book is for


Hands-On Simulation Modeling with Python is for simulation developers and engineers,
model designers, and anyone already familiar with the basic computational methods
that are used to study the behavior of systems. This book will help you explore advanced
simulation techniques such as Monte Carlo methods, statistical simulations, and
much more using Python. Working knowledge of the Python programming language
is required.

What this book covers


Chapter 1, Introduction, analyzes the basics of numerical simulation and highlights the
difference between modeling and simulation and the strengths of simulation models such
as defects. The different types of models are analyzed, and we study practical modeling
cases to understand how to elaborate a model starting from the initial considerations.
viii Preface

Chapter 2, Understanding Randomness and Random Numbers, defines stochastic processes


and explains the importance of using them to address numerous real-world problems.
The main methods for generating random numbers with practical examples in Python
code, and the generation of uniform and generic distributions, are both explored. It also
explains how to perform a uniformity test using the chi-square method.
Chapter 3, Probability and the Data Generating Process, shows how to distinguish between
the different definitions of probabilities and how they can be integrated to obtain useful
information in the simulation of real phenomena.
Chapter 4, Monte Carlo Simulations, explores techniques based on Monte Carlo methods
for process simulation. We will first learn the basic concepts, and then we will see how to
apply them to practical cases.
Chapter 5, Simulation-Based Markov Decision Process, shows how to deal with decision-
making processes with Markov chains. We will analyze the concepts underlying
Markovian processes and then analyze some practical applications to learn how to choose
the right actions for the transition between different states of the system.
Chapter 6, Resampling Methods, shows how to apply resampling methods to approximate
some characteristics of the distribution of a sample in order to validate a statistical model.
We will analyze the basics of the most common resampling methods and learn how to use
them by solving some practical problems.
Chapter 7, Use of Simulation to Improve and Optimize Systems, shows how to use the
main optimization techniques to improve the performance of our simulation models.
We will see how to use the gradient descent technique, the Newton-Raphson method,
and stochastic gradient descent. We will also see how to apply these techniques with
practical examples.
Chapter 8, Simulation Models for Financial Engineering, shows practical cases of using
simulation methods in a financial context. We will learn how to use Monte Carlo methods
to predict stock prices and how to assess the risk associated with a portfolio of shares.
Chapter 9, Simulating Physical Phenomena with Neural Networks, shows how to develop
models based on artificial neural networks to simulate physical phenomena. We will start
by exploring the basic concepts of neural networks, and we will examine their architecture
and its main elements. We will see how to train a network to update its weights.
Preface ix

Chapter 10, Modeling and Simulation for Project Management, deals with practical cases
of project management using the tools we learned how to use in the previous chapters.
We will see how to evaluate in advance the results of the actions undertaken in the
management of a forest using Markov processes, and then move on to evaluating the time
required for the execution of a project using the Monte Carlo simulation.
Chapter 11, What’s Next?, provides a better understanding of the problems associated with
building and deploying simulation models and additional resources and technologies to
learn how to hone your machine learning skills.

To get the most out of this book


Working knowledge of Python programming language is required.

If you are using the digital version of this book, we advise you to type the code yourself
or access the code via the GitHub repository (link available in the next section). Doing
so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files


You can download the example code files for this book from your account at www.
packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/
support and register to have the files emailed directly to you.
You can download the code files by following these steps:

1. Log in or register at www.packt.com.


2. Select the Support tab.
3. Click on Code Downloads.
4. Enter the name of the book in the Search box and follow the onscreen instructions.
x Preface

Once the file is downloaded, please make sure that you unzip or extract the folder using
the latest version of:

• WinRAR/7-Zip for Windows


• Zipeg/iZip/UnRarX for Mac
• 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/
PacktPublishing/Hands-On-Simulation-Modeling-with-Python. In case
there’s an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at
https://github.com/PacktPublishing/. Check them out!

Download the color images


We also provide a PDF file that has color images of the screenshots/diagrams used in this
book. You can download it here: http://www.packtpub.com/sites/default/
files/downloads/9781838985097_ColorImages.pdf.

Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names,
filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles.
Here is an example: “Mount the downloaded WebStorm-10*.dmg disk image file as
another disk in your system.”
A block of code is set as follows:

import random
import statistics
import matplotlib.pyplot as plt

When we wish to draw your attention to a particular part of a code block, the relevant
lines or items are set in bold:

import random
import statistics
import matplotlib.pyplot as plt
Preface xi

Any command-line input or output is written as follows:

$ python jakknife_estimator.py

Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
“Select System info from the Administration panel.”

Tips or important notes


Appear like this.

Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book
title in the subject of your message and email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit www.packtpub.com/support/errata, selecting your
book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet,
we would be grateful if you would provide us with the location address or website name.
Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit authors.
packtpub.com.

Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about
our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.
Section 1:
Getting Started
with Numerical
Simulation

In this section, the basic concepts of simulation modeling are addressed. This section
helps you to understand the fundamental concepts and elements of numerical simulation.
This section contains the following chapters:
Chapter 1, Introducing Simulation Models
Chapter 2, Understanding Randomness and Random Numbers
Chapter 3, Probability and Data Generating Processes
1
Introducing
Simulation Models
A simulation model is a tool capable of processing information and data and predicting
the responses of a real system to certain inputs, thus becoming an effective support for
analysis, performance evaluation, and decision-making processes. The term simulation
refers to reproducing the behavior of a system. In general, we speak of simulation both in
the case in which a concrete model is used and in the case in which an abstract model is
used that reproduces reality using a computer. An example of a concrete model is a scale
model of an airplane that is then placed in a wind tunnel to carry out simulated tests to
estimate suitable performance measures.
Although, over the years, physicists have developed theoretical laws that we can use to
obtain information on the performance of dynamic systems, often, the application of these
laws to a real case takes too long. In these cases, it is convenient to construct a numerical
simulation model that allows us to simulate the behavior of the system under certain
conditions. This elaborated model will allow us to test the functionality of the system in a
simple and immediate way, saving considerable resources in terms of time and money.
4 Introducing Simulation Models

In this chapter, we're going to cover the following main topics:

• Introducing simulation models


• Classifying simulation models
• Approaching a simulation-based problem
• Dynamical systems modeling

Important Note
In this chapter, an introduction to simulation techniques will be discussed.
In order to deal with the topics at hand, it is necessary that you have a basic
knowledge of algebra and mathematical modeling.

Introducing simulation models


Simulation uses abstract models built to replicate the characteristics of a system. The
operation of a system is simulated using probability distributions to randomly generate
system events, and statistical observations are obtained from the simulated system. It plays
a very important role, especially in the design of a stochastic system and in the definition
of its operating procedures.
By not working directly on the real system, many scenarios can be simulated simply by
changing the input parameters, thus limiting the costs that would occur if this solution
were not used and, ultimately, reducing the time it would take. In this way, it is possible to
quickly try alternative policies and design choices and model systems of great complexity
by studying their behavior and evolution over time.

Important Note
Simulation is used when working on real systems is not convenient due to
high costs, technical impossibility, and the non-existence of a real system.
Simulation allows you to predict what happens to the real system if certain
inputs are used. Changing these input parameters simulates different scenarios
that allow us to identify the most convenient one from various points of view.
Introducing simulation models 5

Decision-making workflow
In a decision-making process, the starting point is identifying the problematic context
that requires a change and therefore a decision. The context that's identified is then
analyzed in order to highlight what needs to be studied for the decisions that need to be
made; that is, those elements that seem the most relevant are chosen, the relationships
that connect them are highlighted, and the objectives to be achieved are defined. At this
point, a formal model is constructed, which allows us to simulate the identified system in
order to understand its behavior and to arrive at identifying the decisions to be made. The
following diagram describes the workflow that allows us to make a decision, starting from
observing the problematic context:

Figure 1.1 – Decision-making workflow


This represents a way of spreading knowledge and involves various actors. Constructing a
model is a two-way process:

• Definition of conceptual models


• Continuous interaction between the model and reality by comparison

In addition, learning also has a participatory characteristic: it proceeds through the


involvement of different actors. The models also allow you to analyze and propose
organized actions so that you can modify the current situation and produce the
desired solution.
6 Introducing Simulation Models

Comparing modeling and simulation


To start, we will clarify the differences between modeling and simulation. A model is
a representation of a physical system, while simulation is the process of seeing how a
model-based system would work under certain conditions.
Modeling is a design methodology that is based on producing a model that implements
a system and represents its functionality. In this way, it is possible to predict the behavior
of a system and the effects of the variations or modifications that are made on it. Even if
the model is a simplified representation of the system, it must still be close enough to the
functional nature of the real system, but without becoming too complex and difficult
to handle.

Important Note
Simulation is the process that puts the model into operation and allows you
to evaluate its behavior under certain conditions. Simulation is a fundamental
tool for modeling because, without necessarily resorting to physical
prototyping, the developer can verify the functionality of the modeled system
with the project specifications.

Simulation allows us to study the system through a wide spectrum of conditions so that
we can understand how representative the model is of the system that it refers to.

Pros and cons of simulation modeling


Simulation is a tool that's widely used in a variety of fields, from operational research
to the application industry. This technique can be made successful by it overcoming the
difficulties that each complex procedure contains. The following are the pros and cons of
simulation modeling. Let's start with the concrete advantages that can be obtained from
the use of simulation models (pros):

• It reproduces the behavior of a system in reference to situations that cannot be


directly experienced.
• It represents real systems, even complex ones, while also considering the sources
of uncertainty.
• It requires limited resources in terms of data.
• It allows experimentation in limited time frames.
• The models that are obtained are easily demonstrable.
Introducing simulation models 7

As anticipated, since it is a technique capable of reproducing complex scenarios, it has


some limitations (cons):

• The simulation provides indications of the behavior of the system, but not
exact results.
• The analysis of the output of a simulation could be complex and it could be difficult
to identify which may be the best configuration.
• The implementation of a simulation model could be laborious and, moreover, it may
take long calculation times to carry out a significant simulation.
• The results that are returned by the simulation depend on the quality of the input
data: it cannot provide accurate results in the case of inaccurate input data.
• The complexity of the simulation model depends on the complexity of the system it
intends to reproduce.

Nevertheless, simulation models represent the best solution for the analysis of
complex scenarios.

Simulation modeling terminology


In this section, we will analyze the elements that make up a model and those that
characterize a simulation process. We will give a brief description of each so that you
understand their meaning and the role they play in the numerical simulation process.

System
The context of an investigation is represented through a system; that is, the set of elements
that interact with each other. The main problem linked to this element concerns the
system boundaries, that is, which elements of reality must be inserted in the system that
represents it and which are left out and the relationships that exist between them.

State variables
A system is described in each instant of time by a set of variables. These are called
state variables. For example, in the case of a weather system, the temperature is a state
variable. In discrete systems, the variables change instantly at precise moments of time
that are finite. In continuous systems, the variables vary in terms of continuity with
respect to time.
8 Introducing Simulation Models

Events
An event is defined as any instantaneous event that causes the value of at least one of
the status variables to change. The arrival of a blizzard for a weather system is an event,
as it causes the temperature to drop suddenly. There are both external events and
internal events.

Parameters
Parameters represent essential terms when building a model. They are adjusted during
the model simulation process to ensure that the results are brought into the necessary
convergence margins. They can be modified iteratively through sensitivity analysis or in
the model calibration phase.

Calibration
Calibration represents the process by which the parameters of the model are adjusted in
order to adapt the results to the data observed in the best possible way. When calibrating
the model, we try to obtain the best possible accuracy. A good calibration requires
eliminating, or minimizing, errors in data collection and choosing a theoretical model
that is the best possible description of reality. The choice of model parameters is decisive
and must be done in such a way as to minimize the deviation of its results when applied
to historical data.

Accuracy
Accuracy is the degree of correspondence of the simulation result that can be inferred
from a series of calculated values with the actual data, that is, the difference between
the average modeled value and the true or reference value. Accuracy, when calculated,
provides a quantitative estimate of the quality expected from a forecast. Several indicators
are available to measure accuracy. The most used are mean absolute error (MAE), mean
absolute percentage error (MAPE), and mean squared error (MSE).

Sensitivity
The sensitivity of a model indicates the degree to which the model's outputs are affected
by changes in the selected input parameters. A sensitivity analysis identifies the sensitive
parameters for the output of the model. It allows us to determine which parameters
require further investigation so that we have a more realistic evaluation of the model's
output values. Furthermore, it allows us to identify which parameters are not significant
for the generation of a certain output and therefore can possibly be eliminated from
the model. Finally, it tells us which parameters should be considered in a possible and
subsequent analysis of the uncertainty of the output values provided by the model.
Classifying simulation models 9

Validation
This is the process that verifies the accuracy of the proposed model. The model must be
validated to be used as a tool to support decisions. It aims to verify whether the model
that's being analyzed corresponds conceptually to our intentions. The validation of a
model is based on the various techniques of multivariate analysis, which, from time to
time, study the variability and interdependence of attributes within a class of objects.

Classifying simulation models


Simulation models can be classified according to different criteria. The first distinction is
between static and dynamic systems. So, let's see what differentiates them.

Comparing static and dynamic models


Static models are the representation of a system in an instant of time, or representative
models of a system in which the time variable plays no role. An example of a static
simulation is a Monte Carlo model.
Dynamic models, on the other hand, describe the evolution of the system over time. In
the simplest case, the state of the system at time t is described by a function x (t). For
example, in population dynamics, x (t) represents the population present at time t. The
equation that regulates the system is dynamic: it describes the instantaneous variation of
the population or the variation in fixed time intervals.

Comparing deterministic and stochastic models


A model is deterministic when its evolution, over time, is uniquely determined by its
initial conditions and characteristics. These models do not consider random elements
and lend themselves to be solved with exact methods that are derived from mathematical
analysis. In deterministic models, the output is well determined once the input data and
the relationships that make up the model have been specified, despite the time required
for data processing being particularly long. For these systems, the transformation rules
univocally determine the change of state of the system. Examples of deterministic systems
can be observed in some production and automation systems.
Stochastic models, on the other hand, can be evolved by inserting random elements
into the evolution. These are obtained by extracting them from statistical distributions.
Among the operational characteristics of these models, there is not just one relationship
that fits all. There's also probability density functions, which means there is no one-to-one
correspondence between the data and system history.
10 Introducing Simulation Models

A final distinction is based on how the system evolves over time: this is why we
distinguish between continuous and discrete simulation models.

Comparing continuous and discrete models


Continuous models represent systems in which the state of the variables changes
continuously as a function of time. For example, a car moving on a road represents a
continuous system since the variables that identify it, such as position and speed, can
change continuously with respect to time.
In discrete models, the system is described by an overlapping sequence of physical
operations, interspersed with inactivity pauses. These operations begin and end in well-
defined instances (events). The system undergoes a change of state when each event
occurs, remaining in the same state throughout the interval between the two subsequent
events. This type of operation is easy to treat with the simulation approach.

Important Note
The stochastic or deterministic, or continuous or discrete, nature of a model
is not its absolute property and depends on the observer's vision of the system
itself. This is determined by the objectives and the method of study, as well as
by the experience of the observer.

Now that we've analyzed the different types of models in detail, we will learn how to
develop a numerical simulation model.

Approaching a simulation-based problem


To tackle a numerical simulation process that returns accurate results, it is crucial to
rigorously follow a series of procedures that partly precede and partly follow the actual
modeling of the system. We can separate the simulation process workflow into the
following individual steps:

1. Problem analysis
2. Data collection
3. Setting up the simulation model
4. Simulation software selection
Approaching a simulation-based problem 11

5. Verification of the software solution


6. Validation of the simulation model
7. Simulation and analysis of results

To fully understand the whole simulation process, it is essential to analyze the various
phases that characterize a study based on simulation in depth.

Problem analysis
In this initial step, the goal is to understand the problem by trying to identify the aims
of the study and the essential components, as well as the performance measures that
interest them. Simulation is not simply an optimization technique and therefore there
is no parameter that needs to be maximized or minimized. However, there is a series of
performance indices whose dependence on the input variables must be verified. If an
operational version of the system is already available, the work is simplified as it is enough
to observe this system to deduce its fundamental characteristics.

Data collection
This represents a crucial step in the whole process since the quality of the simulation
model depends on the quality of the input data. This step is closely related to the
previous one. In fact, once the objective of the study has been identified, data is collected
and subsequently processed. Processing the collected data is necessary to transform
it into a format that can be used by the model. The origin of the data can be different:
sometimes, the data is retrieved from company databases, but more often than not, direct
measurements in the field must be made through a series of sensors that, in recent years,
have become increasingly smart. These operations weigh down the entire study process,
thus lengthening their execution times.

Setting up the simulation model


This is the crucial step of the whole simulation process; therefore, it is necessary to pay
close attention to it. To set up a simulation model, it is necessary to know the probability
distributions of the variables of interest. In fact, to generate various representative
scenarios of how a system works, it is essential that a simulation generates random
observations from these distributions.
12 Introducing Simulation Models

For example, when managing stocks, the distribution of the product being requested and
the distribution of time between an order and the receipt of the goods is necessary. On
the other hand, when managing production systems with machines that can occasionally
fail, it will be necessary to know the distribution of time until a machine fails and the
distribution of repair times.
If the system is not already available, it is only possible to estimate these distributions by
deriving them, for example, from the observation of similar, already existing systems.
If, from the analysis of the data, it is seen that this form of distribution approximates a
standard type distribution, the standard theoretical distribution can be used by carrying
out a statistical test to verify whether the data can be well represented by that probability
distribution. If there are no similar systems from which observable data can be obtained,
other sources of information must be used: machine specifications, instruction manuals
for the machines, experimental studies, and so on.
As we've already mentioned, constructing a simulation model is a complex procedure.
Referring to simulating discrete events, constructing a model involves the following steps:

1. Defining the state variables


2. Identifying the values that can be taken by the state variables
3. Identifying the possible events that change the state of the system
4. Realizing a simulated time measurement, that is, a simulation clock, that records the
flow of simulated time
5. Implementing a method for randomly generating events
6. Identifying the state transitions generated by events

After following these steps, we will have the simulation model ready for use. At this
point, it will be necessary to implement this model in a dedicated software platform;
let's see how.
Approaching a simulation-based problem 13

Simulation software selection


The choice of the software platform that you will perform the numerical simulation with
is fundamental for the success of the project. In this regard, we have several solutions that
we can adopt. This choice will be made based on our knowledge of programming. Let's see
what solutions are available:

• Simulators: These are application-oriented packages for simulation. There


are numerous interactive software packages for simulation, such as MATLAB,
COMSOL Multiphysics, Ansys, SolidWorks, Simulink, Arena, AnyLogic, and
SimScale. These pieces of software represent excellent simulation platforms whose
performance differs based on the application solutions provided. These simulators
allow us to elaborate on a simulation environment using graphic menus without the
need to program. They are easy to use but many of them have excellent modeling
capabilities, even if you just use their standard features. Some of them provide
animations that show the simulation in action, which allows you to easily illustrate
the simulation to non-experts. The limitations presented by this software solution
are the high costs of the licenses, which can only be faced by large companies, and
the difficulty in modeling solutions that have not been foreseen by the standards.
• Simulation languages: A more versatile solution is offered by the different
simulation languages ​​available. There are solutions that facilitate the task of the
programmer who, with these languages, ​​can develop entire models or sub-models
with a few lines of code that would otherwise require much longer drafting times,
with a consequent increase in the probability of error. An example of a simulation
language ​​is the general-purpose simulation system (GPSS). This is a generic
programming language that was developed by IBM in 1965. In it, a simulation clock
advances in discrete steps, modeling a system as transactions enter the system and
are passed from one service to another. It is mainly used as a process flow-oriented
simulation language and is particularly suitable for application problems. Another
example of a simulation language ​​is SimScript, which was developed in 1963 as an
extension of Fortran. SimScript is an event-based scripting language, so different
parts of the script are triggered by different events.
14 Introducing Simulation Models

• GPSS: General-purpose programming languages are designed to be able to create


software in numerous areas of application. They are particularly suitable for
the development of system software such as drivers, kernels, and anything that
communicates directly with the hardware of a computer. Since these languages are ​​
not specifically dedicated to a simulation activity, they require the programmer
to work harder to implement all the mechanisms and data structures necessary
in a simulator. On the other hand, by offering all the potential of a high-level
programming language, they offer the programmer a more versatile programming
environment. In this way, you can develop a numerical simulation model perfectly
suited to the needs of the researcher. In this book, we will use this solution by
devoting ourselves to programming with Python. This software platform offers a
series of tools that have been created by researchers from all over the world that
make the elaboration of a numerical modeling system particularly easy. In addition,
the open source nature of the projects written in Python makes this solution
particularly inexpensive.

Now that we've made the choice of the software platform we're going to use and have
elaborated on the numerical model, we need to verify the software solution.

Verification of the software solution


In this phase, a check is carried out on the numerical code. This is known as debugging,
which consists of ensuring that the code correctly follows the desired logical flow, without
unexpected blocks or interruptions. The verification must be provided in real time during
the creation phase because correcting any concept or syntax errors becomes more difficult
as the complexity of the model increases.
Although verification is simple in theory, debugging large-scale simulation code is a
difficult task due to virtual competition. The correctness or otherwise of executions
depends on time, as well as on the large number of potential logical paths. When
developing a simulation model, you should divide the code into modules or subroutines
in order to facilitate debugging. It is also advisable to have more than one person review
the code, as a single programmer may not be a good critic. In addition, it can be helpful to
perform the simulation when considering a large variety of input parameters and checking
that the output is reasonable.
Approaching a simulation-based problem 15

Important Note
One of the best techniques that can be used to verify a discrete-event
simulation program is one based on tracking. The status of the system, the
content of the list of events, the simulated time, the status variables, and the
statistical counters are shown after the occurrence of each event and then
compared with handmade calculations to check the operation of the code.

A track often produces a large volume of output that needs to be checked event by event
for errors. Possible problems may arise, including the following:

• There may be information that hasn't been requested by the analyst.


• Other useful information may be missing, or a certain type of error may not be
detectable during a limited debugging run.

After the verification process, it is necessary to validate the simulation model.

Validation of the simulation model


In this step, it is necessary to check whether the model that has been created provides
valid results for the system in question. We must check whether the performance
measurements of the real system are well approximated by the measurements generated
by the simulation model. A simulation model of a complex system can only approximate
it. A simulation model is always developed for a set of objectives. A model that's valid for
one purpose may not be valid for another.

Important Note
Validation is a where the level of accuracy between the model and the system is
respected. It is necessary to establish whether the model adequately represents
the behavior of the system. The value of a model can only be defined in relation
to its use. Therefore, validation is a process that aims to determine whether a
simulation model accurately represents the system for the set objectives.

In this step, the ability of the model to reproduce the real functionality the system is
ascertained; that is, it is ensured that the calibrated parameters, relative to the calibration
scenario, can be used to correctly simulate other system situations. Once the validation
phase is over, the model can be considered transferable and therefore usable for the
simulation of any new control strategies and new intervention alternatives. As widely
discussed in the literature on this subject, it is important to validate the model parameters
that were previously calibrated on the basis of data other than that used to calibrate the
model, always with reference to the phenomenon specific to the scenario being analyzed.
16 Introducing Simulation Models

Simulation and analysis of results


A simulation is a process that evolves during its realization and where the initial results
help lead the simulation toward more complex configurations. Attention should be paid to
some details. For example, it is necessary to determine the transient length of the system
before reaching stationary conditions if you want performance measures of the system
at full capacity. It is also necessary to determine the duration of the simulation after the
system has reached equilibrium. In fact, it must always be kept in mind that a simulation
does not produce the exact values ​​of the performance measures of a system since each
simulation is a statistical experiment that generates statistical observations regarding
the performance of the system. These observations are then used to produce estimates
of performance measures. Increasing the duration of the simulation can increase the
accuracy of these estimates.
The simulation results return statistical estimates of a system's performance measures.
A fundamental point is that each measurement is accompanied by the confidence
interval, within which it can vary. These results could immediately highlight a better
system configuration than the others, but more often, more than one candidate
configuration will be identified. In this case, further investigations may be needed to
compare these configurations.

Dynamical systems modeling


In this section, we will analyze a real case of modeling a production process. In this
way, we will learn how to deal with the elements of the system and how to translate the
production instances into the elements of the model. A model is created to study the
behavior of a system over time. It consists of a set of assumptions about the behavior of
the system being expressed using mathematical logical-symbolic relationships. These
relationships are between the entities that make up the system. Recall that a model is
used to simulate changes in the system and predict the effects of these changes on the
real system. Simple models are resolved analytically, using mathematical methods, while
complex models are numerically simulated on the computer, where the data is treated as
the data of a real system.
Dynamical systems modeling 17

Managing workshop machinery


In this section, we will look at a simple example of how a discrete event simulation of
a dynamic system is created. A discrete event system is a dynamic system whose states
can assume logical or symbolic values, rather than numerical ones, and whose behavior
is characterized by the occurrence of instantaneous events within an irregular timing
sequence not necessarily known a priori. The behavior of these systems is described in
terms of states and events.
In a workshop, there are two machines, which we will call A1 and A2. At the beginning
of the day, five jobs need to be carried out: W1, W2, W3, W4, and W5. The following table
shows how long we need to work on the machines in minutes:

Figure 1.2 – Table showing work time on the machines


A zero indicates that a job does not require that machine. Jobs that require two machines
must pass through A1 and then through A2. Suppose that we decide to carry out the
jobs by assigning them to each machine so that when they become available, the first
executable job is started first, in the order from 1 to 5. If, at the same time, more jobs can
be executed on the same machine, we will execute the one with a minor index first.
The purpose of modeling is to determine the minimum time needed to complete all the
works. The events in which state changes can occur in the system are as follows:

1. A job becomes available for a machine.


2. A machine starts a job.
3. A machine ends a job.
18 Introducing Simulation Models

Based on these rules and the evaluation times indicated in the previous table, we can
insert the sequence of the jobs, along with the events scheduled according to the execution
times, into a table:

Figure 1.3 – Table of job sequences


This table shows the times of the events in sequence, indicating the start and end of the
work associated with the two machines available in the workshop. At the end of each job,
a new job is sent to each machine according to the rules set previously. In this way, the
deadlines for the work and the subsequent start of another job are clearly indicated. This
is just as easy as it is to identify the time interval in which each machine is used and when
it becomes available again. The table solution we have proposed represents a simple and
immediate way of simulating a simple dynamic discrete system.
The example we just discussed is a typical case of a dynamic system in which time
proceeds in steps, in a discrete way. However, many dynamic systems are best described
by assuming that time passes continuously. In the next section, we will analyze the case of
a continuous dynamic system.

Simple harmonic oscillator


Consider a mass m resting on a horizontal plane, without friction, and attached to a wall
by an ideal spring, of elastic constant k. Suppose that, when the horizontal coordinate x
is zero, the spring is at rest. The following diagram shows the scheme of a simple
harmonic oscillator:
Dynamical systems modeling 19

Figure 1.4 – The scheme of a harmonic oscillator


If the block of mass m is moved to the right with respect to its equilibrium position (x> 0),
the spring, being elongated, calls it to the left. Conversely, if the block is placed to the left
of its equilibrium position (x < 0), then the spring is compressed and pushes the block to
the right. In both cases, we can express the component along the x-axis of the force due to
the spring according to the following formula:
𝐹𝐹𝑥𝑥 = −𝑘𝑘 ∗ 𝑥𝑥

Here, we have the following:

• is the force.
• is the elastic constant.
• is the horizontal coordinate that indicate the position of the mass m.

From the second law of dynamics, we can derive the component of acceleration along x
as follows:
𝑘𝑘
𝑎𝑎𝑥𝑥 = − ∗ 𝑥𝑥
𝑚𝑚
Here, we have the following:

• is the acceleration.
• is the elastic constant.
• is the mass of the block.
• is the horizontal coordinate that indicate the position of the mass m.
20 Introducing Simulation Models

= =
If we indicate with the rate of change of the speed and with the speed,
we can obtain the evolution equations of the dynamic system, as follows:
𝑑𝑑𝑑𝑑
= 𝑣𝑣
{ 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑
= − 𝜔𝜔2 ∗ 𝑥𝑥
𝑑𝑑𝑑𝑑
Here, we have the following:
𝑘𝑘
• 𝜔𝜔2 = −
𝑚𝑚
For these equations, we must associate the initial conditions of the system, which we can
write in the following way:
𝑥𝑥(0) = 𝑥𝑥0
{
𝑣𝑣(0) = 𝑣𝑣0
The solutions to the previous differential equations are as follows:
𝑣𝑣0
𝑥𝑥(𝑡𝑡) = 𝑥𝑥0 cos(𝜔𝜔𝜔𝜔) + sin (𝜔𝜔𝜔𝜔)
{ 𝜔𝜔
𝑣𝑣(𝑡𝑡) = 𝑣𝑣0 cos(𝜔𝜔𝜔𝜔) − 𝑥𝑥0 𝜔𝜔 sin (𝜔𝜔𝜔𝜔)

In this way, we obtained the mathematical model of the analyzed system. In order to study
the evolution of the oscillation phenomenon of the mass block m over time, it is enough
to vary the time and calculate the position of the mass at that instant and its speed.
In decision-making processes characterized by high levels of complexity, the use of
analytical models is not possible. In these cases, it is necessary to resort to models that
differ from those of an analytical type for the use of the calculator as a tool not only for
calculation, such as in mathematical programming models, but also for representing the
elements that make up reality why studying the relationships between them.

Predator-prey model
In the field of simulations, simulating the functionality of production and logistic
processes is considerably important. These systems are, in fact, characterized by high
complexity, numerous interrelationships between the different processes that pass through
them, segment failures, unavailability, and the stochasticity of the system parameters.
Dynamical systems modeling 21

To understand how complex the analytical modeling of some phenomena is, let's analyze
a universally widespread biological model. This is the predator-prey model, which was
developed independently by the Italian researcher Vito Volterra and the American
biophysicist Alfred Lotka.
On an island, there are two populations of animals: prey and predators. The vegetation
of the island provides the prey with nourishment in quantities that we can consider as
unlimited, while the prey is the only food available for the predators. We can consider
the birth rate of the prey constant over time; this means that in the absence of predators,
the prey would grow by exponential law. Their mortality rate, on the other hand, depends
on the probability they have of falling prey to a predator and therefore on the number of
predators present per unit area.
As for the predators, the mortality rate is constant, while their growth rate depends on
the availability of food and therefore on the number of prey per unit area present on the
island. We want to study the trend of the size of the two populations over time, starting
from a known initial situation (number of prey and predators).
To carry out a simulation of this biological system, we can model it by means of the
following system of finite difference equations, where x(t) and y(t) are the number of prey
and predators at time t, respectively:
𝑑𝑑𝑑𝑑
= 𝛼𝛼 ∗ 𝑥𝑥(𝑡𝑡) − 𝛽𝛽 ∗ 𝑥𝑥(𝑡𝑡) ∗ 𝑦𝑦(𝑡𝑡)
{ 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑
= 𝛾𝛾 ∗ 𝑦𝑦(𝑡𝑡) − 𝛿𝛿 ∗ 𝑥𝑥(𝑡𝑡) ∗ 𝑦𝑦(𝑡𝑡)
𝑑𝑑𝑑𝑑
Here, we have the following:

• α, β, γ, δ are positive real parameters related to the interaction of the two species

• is the instantaneous growth rates of the prey.

• is the instantaneous growth rates of the predators.

The following hypotheses underlie in this model:

• In the absence of predators, the number of prey increases according to an


exponential law, that is, with a constant rate.
• Similarly, in the absence of prey, the number of predators decreases at a
constant rate.
This is a deterministic and continuous simulation model. In fact, the state of the system,
represented by the size of the two populations in each instance of time, is univocally
determined by the initial state and the parameters of the model. Furthermore, at least in
principle, the variables – that is, the size of the populations – vary continuously over time.
The differential system is in normal form and can be solved with respect to the derivatives
of maximum order but cannot be separated into variables. It is not possible to solve this
in an analytical form, but with numerical methods, it is solved immediately (the Runge-
Kutta method). The solution obviously depends on the values of the four constants and
the initial values.

Summary
In this chapter, we learned what is meant by simulation modeling. We understood
the difference between modeling and simulation, and we discovered the strengths of
simulation models, such as defects. To understand these concepts, we clarified the
meaning of the terms that appear most frequently when dealing with these topics.
We then analyzed the different types of models: static versus dynamic, deterministic
versus stochastic, and continuous versus discrete. We then explored the workflow
connected to a numerical simulation process and highlighted the crucial steps. Finally, we
studied some practical modeling cases to understand how to elaborate on a model starting
from the initial considerations.
In the next chapter, we will learn how to approach a stochastic process and understand
the random number simulation concepts. Then, we will explore the differences between
pseudo and non-uniform random numbers, as well as the methods we can use for random
distribution evaluation.
2
Understanding
Randomness and
Random Numbers
In many real-life situations, it is useful to flip a coin in order to decide what to do. Many
computers also use this procedure as part of their decision-making process. In fact, many
problems can be solved in a very effective and relatively simple way by using probabilistic
algorithms. In an algorithm of this type, decisions are made based on random
contributions that remember the dice roll with the help of a randomly chosen value.
The generation of random numbers has ancient roots, but only recently has the process
been sped up, allowing it to be used on a large scale in scientific research as well. These
generators are mainly used for computer simulations, statistical sampling techniques, or
in the field of cryptography.
In this chapter, we're going to cover the following topics:

• Stochastic processes
• Random number simulation
• The pseudorandom number generator
24 Understanding Randomness and Random Numbers

• Testing uniform distribution


• Exploring generic methods for random distributions
• Random number generation using Python

Technical requirements
In this chapter, we will introduce random number generation techniques. In order to
understand these topics, a basic knowledge of algebra and mathematical modeling is
needed.
To work with the Python code in this chapter, you need the following files (available on
GitHub at https://github.com/PacktPublishing/Hands-On-Simulation-
Modeling-with-Python):

• LinearCongruentialGenerator.py
• LearmouthLewisGenerator.py
• LaggedFibonacciAlgorithm.py
• UniformityTest.py
• Random.Generation.py

Stochastic processes
A stochastic process is a family of random variables that depends on a parameter, t. A
stochastic process is specified using the following notation:
{𝑋𝑋𝑡𝑡 , 𝑡𝑡 ∈ 𝑇𝑇}

Here, t is a parameter, and T is the set of possible values ​​of t.


Usually, time is indicated by t, so a stochastic process is a family of time-dependent
random variables. The variability range of t, that is, the set, T, can be a set of real numbers,
possibly coinciding with the entire time axis. But it can also be a discrete set of values.
The random variables, Xt, are defined on the set, X, called the space of states. This can be a
continuous set, in which case it is defined as a continuous stochastic process, or a discrete
set, in which case it is defined as a discrete stochastic process.
Consider the following elements:
𝑥𝑥0 , 𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 ∈ 𝑋𝑋
Stochastic processes 25

This means the values ​​that the random variables, Xt, can take are called system states and
represent the possible results of an experiment. The Xt variables are linked together by
dependency relationships. We can know a random variable if we know both the values
it can assume and the probability distribution. So, to understand a stochastic process,
it is necessary not only to know the values ​​that Xt can take but also the probability
distributions of the variables and the joint distributions between the values. Simpler
stochastic processes, in which the variability range of t is a discrete set of time values,
​​can also be considered.

Important note
In practice, there are numerous phenomena that are studied through the
theory of stochastic processes. A classic application in physics is the study of
the motion of a particle in each medium, the so-called Brownian motion.
This study is carried out statistically using a stochastic process. There are
processes where even by knowing the past and the present, the future cannot
be determined; whereas, in other processes, the future is determined by the
present without considering the past.

Types of stochastic process


Stochastic processes can be classified according to the following characteristics:

• Space of states
• Time index
• Type of stochastic dependence between random variables

The state space can be discrete or continuous. In the first case, the stochastic process
with discrete space is also called a chain, and space is often referred to as the set of
non-negative integers. In the second case, the set of values assumed by the random
variables is not finite or countable, and the stochastic process is in continuous space.
The time index can also be discrete or continuous. A discrete-time stochastic process is
also called a stochastic sequence and is denoted as follows:
{𝑋𝑋𝑛𝑛 | 𝑛𝑛 ∈ 𝑇𝑇}

Here, the set, T, is finite or countable.


26 Understanding Randomness and Random Numbers

In this case, the changes of state are observed only in certain instances: finite or countable.
If state changes occur at any instant in a finite or infinite set of real intervals, then there is
a continuous-time process, which is denoted as follows:
{𝑋𝑋(𝑡𝑡) | 𝑡𝑡 ∈ 𝑇𝑇}

The stochastic dependence between random variables, X(t), for different values of t
characterizes a stochastic process and sometimes simplifies its description. A stochastic
process is stationary in the strict sense that the distribution function is invariant with
respect to a shift on the time axis, T. A stochastic process is stationary in the broad sense
that the first two moments of the distribution are independent of the position on the
T axis.

Examples of stochastic processes


The mathematical treatment of stochastic processes seems complex, yet we find cases of
stochastic processes every day. For example, the number of patients admitted to a hospital
as a function of time, observed at noon each day, is a stochastic process in which the space
of states is discrete, being a finite subset of natural numbers, and time is discrete. Another
example of a stochastic process is the temperature measured in a room as a function of
time, observed at every instant, with continuous state space and continuous time. Let's
now look at a number of structured examples that are based on stochastic processes.

The Bernoulli process


The concept of a random variable allows us to formulate models that are useful for
the study of many random phenomena. An important early example of a probabilistic
model is the Bernoulli distribution, named in honor of the Swiss mathematician, James
Bernoulli (1654-1705), who made important contributions to the field of probability.
Some of these experiments consist of repeatedly performing a given test. For example,
we want to know the probability of getting a head when throwing a coin 1,000 times.
In each of these examples, we look for the probability of obtaining x successes in n trials.
If x indicates the successes, then n - x will be the failures.
A sequence of Bernoulli trials consists of a Bernoulli trial under the following hypotheses:

• There are only two possible mutually exclusive results for each trial, arbitrarily
called success and failure.
• The probability of success, p, is the same for each trial.
• All tests are independent.
Stochastic processes 27

Independence means that the result of a test is not influenced by the result of any other
test. For example, the event, the third test was successful, is independent of the event, the
first test was successful.
The toss of a coin is a Bernoulli trial: the heads event can be considered successful, and
the tails event can be considered unsuccessful. In this case, the probability of success is p
= 1/2. In rolling two dice, the event, the sum of the points is seven, and the complementary
event are both unsuccessful. In this case, it is a Bernoulli trial and the probability of
success is p = 1/6.

Important note
Two events are said to be complementary when the occurrence of the first
excludes the occurrence of the second but one of the two will certainly occur.

Let p denote the probability of success in a Bernoulli trial. The random variable, X, which
counts the number of successes in n trials is called the binomial random variable of the n
and p parameters. X can take integer values between 0 and n.

Random walk
The random walk is a discrete parameter stochastic process in which Xt, where X
represents a random variable, describes the position taken at time t by a moving point.
The term, random walk, refers to the mathematical formalization of statistics that describe
the displacement of an object that moves randomly. This kind of simulation is extremely
important for a physicist and has applications in statistical mechanics, fluid dynamics, and
quantum mechanics.
Random walks represent a mathematical model that is used universally to simulate a path
formalized by a succession of random steps. This model can assume a variable number
of degrees of freedom, depending on the system we want to describe. From a physical
point of view, the path traced over time will not necessarily simulate a real motion, but it
will represent the trend of the characteristics of the system over time. Random walks find
applications in chemistry, biology, and physics, but also in other fields such as economics,
sociology, and information technology.
28 Understanding Randomness and Random Numbers

Random one-dimensional walking is a model that is used to simulate the movement of


a particle moving along a straight line. There are only two potential movements on the
allowed path: either to the right (with a probability that is equal to p) or to the left (with
a probability that is equal to q) of the current position. Each step has a constant length
and is independent of the others, as shown in the following diagram:

Figure 2.1 – One-dimensional walking


The position of the point in each instant is identified by its abscissa, X(n). This position,
after n steps, will be characterized by a random term. Our aim is to calculate the
probability of passing from the starting point after n movements. Obviously, nothing
assures us that the point will return to the starting position. The variable, X(n), returns
the abscissa of the particle after n steps. It is a discrete random variable with a binomial
distribution.
At each instant, the particle steps right or left based on the value returned by a random
variable, Z(n). This variable can take only two values: +1 and -1. It assumes a + 1 value
with a probability of p > 0 and a value of -1 with a probability that is equal to q. The sum
of the two probabilities is p + q = 1. The position of the particle at instant n is given by the
following equation:
𝑋𝑋𝑛𝑛 = 𝑋𝑋𝑛𝑛−1 + 𝑍𝑍𝑛𝑛 ; 𝑛𝑛 = 1, 2, …

This shows the average number of returns to the origin of the particle, named p. The
probability of a single return is given by the following geometric series:
∞ ∞
1
𝜇𝜇 = ∑ 𝑛𝑛 𝑝𝑝𝑛𝑛 (1 − 𝑝𝑝) = ∑ 𝑛𝑛 𝑝𝑝𝑛𝑛 →∞
𝑛𝑛=0 𝑛𝑛=0
√𝑛𝑛 ∗ 𝜋𝜋

We assume that the probability of the particle returning to the origin tends to 1. This
means that despite the frequency of the returns decreasing with the increase in the
number of steps taken, they will always be in an infinite value of steps taken. So, we can
conclude that a particle with equal probability of left and right movement, left free to
walk casually to infinity with great probability, returns infinite times to the point from
which it started.
Stochastic processes 29

The Poisson process


There are phenomena in which certain events, with reference to a certain interval of time
or space, rarely happen. The number of events that occur in that interval varies from 0 to
n, and n cannot be determined a priori. For example, the number of cars passing through
an uncrowded street in a randomly chosen 5-minute time frame can be considered a rare
event. Similarly, the number of accidents at work that happen at a company in a week, or
the number of printing errors on a page of a book, is rare.
In the study of rare events, a reference to a specific interval of time or space is
fundamental. For the study of rare events, the Poisson probability distribution is used,
named in honor of the French mathematician, Simeon Denis Poisson (1781-1840), who
first obtained the distribution. The Poisson distribution is used as a model in cases where
the events or realizations of a process, distributed randomly in space or time, are counts,
that is, discrete variables.
The binomial distribution is based on a set of hypotheses that define the Bernoulli trials,
and the same happens for the Poisson distribution. The following conditions describe
the so-called Poisson process:

• The realizations of the events are independent, meaning that the occurrence of
an event in a time or space interval has no effect on the probability of the event
occurring a second time in the same, or another, interval.
• The probability of a single realization of the event in each interval is proportional to
the length of the interval.
• In any arbitrarily small part of the interval, the probability of the event occurring
more than once is negligible.

An important difference between the Poisson distribution and the binomial distribution
is the number of trials and successes. In a binomial distribution, the number, n, of trials
is finite and the number, x, of successes cannot exceed n; in a Poisson distribution, the
number of tests is essentially infinite and the number of successes can be infinitely large,
even if the probability of having x successes becomes very small as x increases.
30 Understanding Randomness and Random Numbers

Random number simulation


The availability of random numbers is a necessary requirement in many applications.
In some cases, the quality of the final application strictly depends on the possibility
of generating good quality random numbers. Think, for example, of applications such
as video games, cryptography, generating visuals or sound effects, telecommunications,
signal processing, optimizations, and simulations. In an algorithm of this type, decisions
are made based on the pull of a virtual currency, which is based on a randomly
chosen value.
There is no single or general definition of a random number since it often depends on the
context. The concept of random number itself is not absolute, as any number or sequence
of numbers can appear to be random to an observer, but not to another who knows the
law with which they are generated. Put simply, a random number is defined as a number
selected in a random process from a finite set of numbers. With this definition, we focus
on the concept of randomness in the process of selecting a sequence of numbers.
In many cases, the problem of generating random numbers concerns the random
generation of a sequence of 0 and 1, from which numbers in any format can be obtained:
integers, fixed points, floating points, or strings of arbitrary length. With the right
functions, it is possible to obtain good quality sequences that can also be used in scientific
applications, such as the Monte Carlo simulation. These techniques should be easy to
implement and be usable by any computer. In addition, like all software solutions, they
should be very versatile and quickly improved.

Important note
These techniques have a big problem that is inherent to the algorithmic nature
of the process: the final string can be predicted from the starting seed. This is
why we call this process pseudorandom.

Despite this, many problems of an algorithmic nature are solved very effectively and
relatively simply using probabilistic algorithms. The simplest example of a probabilistic
algorithm is perhaps the randomized quicksort. This is a probabilistic variant of the
homonymous sorting algorithm, where, by choosing the pivot element, the algorithm
manages to randomly guarantee optimal complexity in the average case, no matter
the distribution of the input. Cryptography is a field in which randomness plays
a fundamental role and deserves specific mention. In this context, randomness does
not lead to computational advantages, but it is essential to guarantee the security of
authentication protocols and encryption algorithms.
Random number simulation 31

Probability distribution
It is possible to characterize a random process from different points of view. One of
the most important characteristics is the probability distribution. The probability
distribution is a model that associates a probability with each observable modality
of a random variable.
The probability distribution can be either discrete or continuous, depending on whether
the variable is random, discrete, or continuous. It is discrete if the phenomenon is
observable with an integer number of modes. The throw of the dice is a discrete
statistical phenomenon because the number of observable modalities is equal to 6. The
random variable can take only six values ​​(1, 2, 3, 4, 5, and 6). Therefore, the probability
distribution of the phenomenon is discrete. The probability distribution is continuous
when the random variable assumes a continuous set of values; in this case, the statistical
phenomenon can be observed with an infinite or very high number of modalities. The
probability distribution of body temperature is continuous because it is a continuous
statistical phenomenon, that is, the values ​​of the random variable vary continuously.
Let's now look at different kinds of probability distributions.

Uniform distribution
In many cases, processes characterized by a uniform distribution are considered and
used. This means that each element is as likely as any of the others to be selected if an
infinite number of extractions is performed. If you represent the elements and their
respective probabilities of being extracted on a graph, you get a rectangular graph
as follows:

Figure 2.2 – The probabilities of the elements


Another Random Scribd Document
with Unrelated Content
“Is he a scholar?”
“I do not know.”
“Is he logical?”
“I cannot tell. He claimed that he went to school only a few
months.”
“How long did you debate with him?”
“Six days.”
“What?” said Doctor Stone in astonishment, “You debated with
him six days, and could not tell whether or not he is educated?”
“Well,” continued the university president, in a meditative mood, “I
will say that he is—forceful.”
Doctor Stone looked blank for a moment, and then ventured with
a smile, “May be he whipped you?”
“I don’t know,” was the guarded answer, “but I am inclined to
believe that my people thought he did.” Observing that Stone was
intensely interested, Treat inquired:
“Are you thinking of debating with him?”
Stone answered in the affirmative.
“Can’t you get out of it in some honorable way?”
Stone replied that he was not wanting “out of it.”
“But you may want out of it,” was Treat’s not very assuring reply.
“Why, is he not fair in debate? Is he not a gentleman?”
“Yes,” answered Treat, “so much so that all your people who know
him love to be with him and hear him talk.” And the conversation
drifted into other channels. But Doctor Stone, being from Missouri,
waited to be shown. And the debate was held according to schedule.
About this time Doctor Stone was enjoying no small degree of
notoriety. He had debated with a Methodist minister in southern
Illinois, and so completely mastered him that he acknowledged his
defeat in sack cloth and ashes, and joined the Christian Church.
Stone was taking advantage of his newly-acquired popularity in
waging a relentless war against the “sects,” as he termed them,
when some of the Pedo-Baptists secured Newgent to meet him in
debate. And the challenge was brought to the great, self-important
Doctor Stone.
“Newgent!” said this supposed Goliath with a contemptuous sneer.
“He can’t debate. He’s an Irish peddler who used to sell table-cloths
in my father’s neighborhood.” The committee informed him that they
were willing to risk their case with the Irish peddler. However,
Stone’s visit to Doctor Treat to get information concerning the
Irishman would indicate that his contempt was more feigned than
real.
The debate was held in a small town in southern Illinois, where
the doctor had been making havoc of the “sects.” The table-cloth
story became current, and much speculation was indulged in
concerning the supposed vender of household commodities. His
coming to the village was awaited with intense interest. When the
train on which he was scheduled to arrive pulled in at the station, a
curious and enthusiastic crowd was waiting to get a view of the man
who dared to dispute the wisdom of Doctor Stone. As he stepped
from the car, a gentleman who knew him said, pointing him out,
“There’s the table-cloth peddler.”
A hearty salute was given by the crowd. Newgent, having been
apprised of the story, was equal to the occasion. As soon as the
hubbub ceased, he addressed the crowd, turning the table-cloth
story against his opponent in the following speech:
“Gentlemen, if you have come here to buy table-cloths, you will be
disappointed. I have changed my occupation. I have been informed
that there is some fine stone in southern Illinois, so I have come
down here to set up my shop and spend a few days dressing Stone.”
The “Stone dressing” joke superseded the table-cloth story and
became a catch phrase throughout the debate.
It is likely that Stone often called to mind the friendly advice of
Doctor Treat, and regretted that he did not take it. He could cope
neither with the argument, the quick wit, nor the physical endurance
of his opponent. His voice failed completely, and the last two
addresses of Newgent were unanswered. The Stone-dressing
business proved eminently successful.
An amusing incident occurred in connection with a debate in
Kentucky with a Doctor Fairchilds, an eminent Baptist minister. A
story came to the ears of Doctor Fairchilds after he came on the
ground, to the effect that Newgent was a man of extraordinary
scholarship, that he was master of some thirteen languages, etc.
The doctor was visibly disconcerted by the story, and after hearing
Newgent’s first address, was fully persuaded that it was true,
especially the part relating to the thirteen languages. He was quite
nervous, and utterly broke down about the middle of the program,
leaving the supposed master of thirteen languages easily master of
the situation.
While on his official rounds as superintendent of the Tennessee
Mission Conference, he once chanced to invade a Lutheran
community, which set in motion a train of influences that terminated
in a debate with a representative of that body. This was about eight
miles from Greenville. He was visiting a United Brethren family that
had moved into the community, and in company with his host, called
at the district school, and made a talk to the pupils. Through the
influence of his host, the school house was secured for a preaching
service that evening. Other influences then began to be felt, and the
meeting was continued indefinitely, resulting in a sweeping revival,
the organization of a United Brethren church, and the building and
dedication of a church-house within two months from the close of
the revival.
This occasioned great concern among the Lutherans who lost
quite heavily as a result of the United Brethren invasion. To regain
their lost ground, they challenged Rev. Mr. Newgent to debate
certain doctrinal questions with a representative of their church.
Newgent was then in his element, in the debate, and answered that
he would be ready at any time to accommodate them.
The Lutheran champion was Dr. J. C. Miller, president of one of
their church schools. The much-mooted question as to what body
constituted the true church was the first taken up, Doctor Miller
posing as the representative of a church whose doctrines and usages
are identical with those taught and exemplified in the New
Testament.
This placed upon Miller the Herculean task of defending the
various tenets and practices peculiar to his church. Among other
specimens of Lutheran creed, Newgent read the following: “The
infant’s heart is corrupt, and it cannot be saved unless baptized by a
Lutheran minister with heavenly, gracious water.” When asked if his
church taught that, Doctor Miller admitted that it did.
Newgent showed this bit of dogma up in a bad light by the use of
an object lesson. Borrowing a baby from a mother in the audience,
he held it up before the crowd, stating that the “little rascal’s” heart
is corrupt and its only chance for salvation was by being baptized
according to the Lutheran formula. “Now,” he continued, “I want this
brother to demonstrate to this audience how a baby must be saved.
I want him to change this baby’s heart from a state of corruption to
a state of purity. I want to see how a baby is saved, for, according to
his theology, I have three babies in hell.”
The brother winced under this outburst of sarcasm. He refused to
baptize the child, which, had he done so under the circumstances,
would scarcely have made his doctrine appear less obnoxious. Other
peculiar Lutheran tenets appeared to the same disadvantage under
similar treatment, and the church’s hope of gaining its lost ground
completely vanished. The debate popularized the United Brethren
Church, giving it a strong hold in the community. Flag Branch, a
flourishing rural church, stands as a monument to Rev. Mr.
Newgent’s labors in that section.
Another contest worthy of special note was with a Baptist minister
at Blue Springs, Tennessee, in 1882. The mode of baptism was a live
question throughout that region. The battle line was drawn by the
Baptists and Pedo-Baptists. They finally agreed to have the question
discussed in a public debate, each side to furnish its champion.
Three churches were represented on the immersion side, and seven
on the other. The immersionists secured as their representative,
Doctor Ingram, a prominent Baptist divine of Virginia. Newgent was
selected by the anti-immersionists. The debate was to cover six
propositions and to continue six days, one subject being slated for
each day.
The Baptists were very desirous of including infant baptism in the
list of subjects to be discussed. This was a question that Newgent
had never debated, and in which he had very little interest. But to
accommodate the Baptists, he consented to defend the practice of
infant baptism. His opponent proposed the question, stating it as
follows: “Resolved, That infants are fit subjects for baptism.”
Newgent consented to affirm it.
It was slated for the second day. In his opening remarks, Newgent
said: “Mr. President, this is a peculiar question; but my brother wrote
it and insisted that I affirm it. It is peculiar from the fact that I am
not to prove that the child needs baptism, or that there is any
command for infant baptism, or that there ever was an infant
baptized. I am simply asked to prove that a child is a fit subject for
baptism.”
At these remarks a storm of protest arose from the immersionists.
They expected him to defend the vast array of teaching that the
various Pedo-Baptist bodies had put forward on the subject.
“Keep cool,” he said to the immersionist part of the crowd as they
were clamoring for a hearing and creating no little confusion.
“Doctor Ingram and I signed these papers, and we agreed to be
governed by the board of moderators. This question simply deals
with the child’s fitness for baptism. I appeal to the moderators.” The
moderators sustained his position.
He then asked his opponent whether or not the Baptist Church
would baptize a subject until he was converted and became as a
little child. His opponent stated that it would not. This gave him a
splendid foundation for his address, and, at the same time, removed
the last foundation stone from under his opponent, so far as infant
baptism was concerned. He made an earnest and eloquent address,
showing that the child is a type of the heavenly citizen, and as such
possesses special fitness for all the sacraments of God’s house.
While he was talking, his attention was called to Doctor Ingram.
The doctor, grip in hand, was making rapid strides toward the
railroad station. His moderator and some friends were accompanying
him, trying to persuade him to remain. But he could endure it no
longer.
The doctor’s retreat caused a great sensation, relished immensely
by the Pedo-Baptists, but a bitter dose to the immersionists. There
were yet four days of the program remaining. Newgent’s side
demanded, as they were paying him for his work, that he remain
and carry out his part of the program. This he did, but as the debate
had only one end to it during those four days, it spoiled the
excitement, though it served well the purpose of those who had
employed him.
Among his later debates was one held in 1898 at Mechanicsville,
Indiana. Dr. J. W. Haw, of the Christian Church, was his opponent on
this occasion. Doctor Haw had been holding revival meetings in that
part of Indiana, and being dogmatic in style and controversially
inclined, was unsparing in his denunciations of other denominations.
His aggressions and criticisms were disturbing the equilibrium of
some of the brethren whose churches were being used as a target
by this ecclesiastical Nimrod. They wrote to Newgent, then in
Tennessee, urging him to champion their side against Doctor Haw in
debate, offering him fifty dollars per day and expenses for his time.
He consented on condition that the propositions were fair and that
the reverend gentleman in question was a representative man in his
church.
He was referred to a two-column article in a current number of
the Christian Standard relating to Doctor Haw. The article was
extravagant in the use of adjectives describing the doctor’s ability
and achievements, stating that he was the leading debater in the
Christian Church, having had more such battles than any other man
in it at that time. This was quite satisfactory to Newgent, as at that
period he did not care to waste any shot or shell on small game.
In this, as in all other such contests, Newgent abundantly
sustained his position and satisfied the expectations of his
supporters. His experience, self-control, complete mastery of the
subjects in hand, humor, and physical endurance made him an
antagonist that even the greatest debater in a debating church could
illy cope with. The general verdict of even Doctor Haw’s own
sympathizers was that it was decidedly a one-sided affair.
Chapter Twelve.
Perrysville and Centerpoint—Industry Rewarded from
an Unsuspected Source—A “Slick” Wedding—
Fruitful Labors at Centerpoint—A One-Sided Union
Meeting—The Doctrine of the Resurrection Again
Demonstrated.

A year on the Perrysville charge in the Upper Wabash Conference,


followed by a year at Centerpoint, in his own conference, the Lower
Wabash, covering 1874 to 1876, closed Rev. Mr. Newgent’s work in
the pastorate for a season. It was from the latter charge that he
received his appointment from the Home, Frontier, and Foreign
Missionary Society as Superintendent of the Tennessee Mission
Conference. From thenceforth he was destined to serve the Church
in a larger capacity, though there is no work that he regards as more
exalted or more vital to the progress of the kingdom than that of the
pastor. And it is but just to say that there is no work in which he has
been happier or more in his element. The pastor, he regards, as the
pivotal man in the church militant, around whose personality must
revolve all the machinery of its organized life. Hence, in whatever
position he has been placed, he has ever been in fullest sympathy
with the men on the firing line, and has sought in every way to
encourage and magnify their work.
His going to Perrysville was in response to an urgent appeal from
his intimate friend, Dr. J. W. Nye, then a popular presiding elder in
the Upper Wabash Conference. His work here was fruitful and
congenial, and marked by some rich experiences, which he carries
with him as refreshing memories. One of these teaches a practical
moral lesson, namely, that honest industry has its reward in more
ways than one.
It need not be explained here that industry is a part of his religion.
He believes with Paul that it does not injure, or lower the dignity of a
minister to labor with his hands. In this, as in other respects, he
made himself an example to the flock. Odd moments are always
occupied in diversions of a practical character. The outward
appearance of the parsonage never failed to testify to his thrift and
good taste. A garden served as an outlet to his surplus physical
energies as well as a means of supplementing the usually modest
income. Under his skillful hand it invariably became a thing of beauty
and an object of just pride.
Some five miles from Perrysville lived a horny-handed son of the
soil, a man who made industry not only the chief element in his
religion, but the sum total of it. He was an infidel in his belief—or
disbelief—and regarded the church as an imposition, and preachers
as an indolent, worthless lot. Passing through the village one day, he
noticed Rev. Mr. Newgent’s garden. It was by far the finest he had
seen. His surprise can only be imagined when, upon inquiry, he
learned that the owner of it was one of those lazy preachers.
A few days later he drove up to the parsonage with a barrel of
flour, which he unloaded and unceremoniously rolled upon the
porch. This time the surprise was on the preacher, as a reputation
for benevolence was a thing of which, up to that time, the infidel
could not boast. He explained that ordinarily he had no use for
preachers, but as he had found one that was not lazy, he “wanted to
help him.” The donation was an expression of his regard for the
minister who showed a willingness, according to the infidel’s
conception of the term, to earn his bread in the sweat of his face.
Another incident, picked up at random, occurred one cold day
during the winter of his stay at Perrysville. A couple whose
appearance did not indicate a superabundance of worldly prosperity,
came to the parsonage to be married. They had come from the
adjoining county, the boundary between the two counties being the
Wabash River, on the bank of which Perrysville was located. The
river was frozen over. The couple traveled afoot, having crossed the
river on the ice. The preacher explained that they would have to
recross the river before the ceremony could be performed, as the
law required that marriages be solemnized in the county in which
the license was issued. So he conducted the matrimonial candidates
to the river.
When the preacher was satisfied that they had proceeded beyond
the half-way point on the river, he ordered the couple to halt and
join hands. By this time their presence had attracted the attention of
the young people who were out on the ice in large numbers enjoying
the fine winter sport of skating. As the wedding was a public
function, no restrictions being placed on attendance, the ceremony
was performed in the presence of an enthusiastic multitude.
The service completed, the groom, who was unacquainted with
ministerial usages, inquired as to the amount of the fee. To save him
the responsibility and further embarrassment of determining the sum
to be paid for the service, the preacher suggested that a dollar
would be sufficient, fearing lest he might set the price too high for
his purse. Even at that it was painfully evident that the young man’s
financial rating was overestimated. After nervously fumbling through
his pockets he was able to produce but fifty cents. In his dilemma he
found it necessary to call upon his bride for financial assistance.
Happily she was equal to the emergency, and supplied the deficit
from her own purse.
The Young Man’s Financial Rating Was Over-estimated.

“This is the fairest wedding I have ever seen,” said the preacher.
“It has always been my opinion that the lady ought to help pay the
preacher, and she receives as much benefit from the ceremony as
does the man. I hope you will always share each other’s burdens in
this way.” And wishing them happiness and prosperity, he sent them
on their way rejoicing.
The local paper gave a flowery account of the wedding that took
place on the ice, stating that it was the “slickest” wedding that had
ever occurred in that section. But the minister’s fee and the manner
of paying it was not allowed to become public, lest it should become
a troublesome precedent in matrimonial circles.
The following year, which was spent on the Centerpoint charge,
was a most fruitful one. Here, as in so many other places, he found
a splendid opportunity of demonstrating his favorite doctrine of the
resurrection—the resurrection of dead churches. The spiritual life of
the churches at Centerpoint was at ebb tide, and had been for an
indefinite time. Soon after his arrival the Methodist pastor, who was
also new in the town, called upon him to confer as to their plans for
revival work. As workers were scarce, it was thought best to plan
their meetings so that they would not conflict. Rev. Mr. Newgent,
Abraham-like, let his brother do the choosing, and the brother,
perhaps as anxious as Lot to get in on the ground floor, decided to
commence a revival at once. Newgent began a meeting at the same
time some few miles in the country. Newgent’s meeting immediately
developed into a revival of so great proportions that it became the
one overshadowing event of the whole country, drawing the
Methodist pastor’s congregation from him and rendering it
impracticable for him to continue. His situation was a rather lonely
one. In his extremity he sought another interview with his fellow
pastor, proposing to close his meeting at once if Newgent would join
him later in a union revival effort.
This Newgent consented to do on three conditions, as follows:
1. That the meetings be held in the United Brethren church.
2. That the United Brethren pastor do all the preaching.
3. That the United Brethren pastor do the managing.
Hard as the conditions seemed, the brother agreed to them. The
conditions, in fact, look egotistical and perhaps selfish on the
surface, but when the United Brethren pastor explained his reasons
for them they were seen to be neither. On the contrary they were
meant for the highest good of both churches, and were abundantly
vindicated by the outcome. He was intensely anxious that
Centerpoint have a genuine revival of religion. To promote such a
revival at any cost was his purpose. That this purpose might be
realized he would not permit modesty, formality, or any other
creature to stand in the way.
The United Brethren Church was the more commodious and had
the advantage in location. This was the reason for the first condition.
The reason for the second and third conditions was that Centerpoint
had been preached to death. A change of methods was imperative if
the people were to be reached. He wanted a meeting without
preaching, without too much human agency, but where God himself
might control to his own glory. Only by having the management left
to him could he apply the remedy needed according to his diagnosis
of the case.
His plan was now to be put to the test—a revival without
preaching, the laity to do the work as they felt divinely moved. The
meeting began on a Friday evening. But with no life there could be
no real activity. The chariot wheels dragged heavily at the first. On
Sunday morning he announced that at four o’clock p. m., a children’s
meeting would be held. Aside from selected helpers, only children
within a certain age limit would be admitted. Such meetings even at
that date were quite uncommon. The announcement, therefore,
aroused a great deal of curiosity. But that was one point in the
announcement. Something must be done to stir the people. There
must be a new avenue of approach to their cold hearts.
The children’s service produced the desired effect. At the
appointed hour the house was filled to overflowing. There were
three helpers, all ministers, present, who did their part according to
Newgent’s directions. Songs were sung, prayers offered by the
ministers as they were called upon, a brief talk by the leader, some
simple propositions, and the meeting closed in less than a half-hour
from the time it began. But that half-hour turned the tide in
Centerpoint. The children became the vanguard in a religious
movement that was to shake the town from center to circumference.
Many of them went home weeping to speak of the longing of their
tender hearts to fathers and mothers, who, in turn, were awakened
to a consciousness of their own need.
At the evening service which followed, seventy-five persons came
to the altar, most of whom professed conversion. The revival was no
longer a problem. It spread throughout the town and community like
fire in dry stubble. The church arose from the grave of lethargy and
formalism, cast off her grave clothes—and the doctrine of the
resurrection was again abundantly demonstrated.
Chapter Thirteen.
Becomes a Missionary Superintendent—Second
Marriage—An Unexpected Welcome—Forms a
Quaker Friendship—The Spirit Moves in a Quaker
Meeting—A Quaker’s Prayer Answered—Builds a
College—Shows What to do for a Dead Church—
Another Tilt on the Doctrine of Baptism—
Conversion of a Dunkard Preacher—Turns a Great
Movement in the Right Direction.

In the fall of 1876, Rev. Mr. Newgent entered upon his duties as
Superintendent of the Tennessee Mission Conference, under
appointment of the Home, Frontier, and Foreign Missionary
Association. In the meantime he had married Miss Annie Crowther,
of Terre Haute, Indiana, who, under the divine blessing, abides as
the companion of his joys and sorrows amid the lengthening
shadows. She is a woman of rare and excellent qualities, which
especially fitted her for her position as the wife of an active and
ambitious minister. She is in fullest accord with her husband’s
ambitions and tastes, and has contributed her part toward the
success of his career. He freely accords to her this credit. With this
queenly woman ordering its affairs, the Newgent home has ever
been a haven of real rest, a retreat for God’s servants especially. It
extends a welcome and hospitality—a true home spirit—that at once
makes the wayworn pilgrim feel at ease in body and mind, and
charms the hearts of the young as well.
At the time of their removal to Tennessee, the United Brethren
Church was new in the South. Its attitude of open hostility to slavery
largely shut it out of regions south of Mason and Dixon’s line. The
Tennessee Conference then had less than four hundred members,
with only six houses of worship. So a great field spread out before
the new Superintendent, taking him back to conditions in many
respects similar to those in which he began his ministerial labors. It
was still a time of reconstruction in church affairs as well as in
matters political. But his was a work of construction rather than of
reconstruction.
Aside from the need of laborers and the vast opportunities
afforded for building up the church in this section, one reason he
had for accepting this appointment was the condition of his own and
his wife’s health. Both were threatened with failing health, and a
change of climate was advised, the high altitude of eastern
Tennessee being recommended as especially adapted to their
physical needs.
They arrived at Limestone, Tennessee, on a Friday evening in
September. Here was illustrated how his fame as a genial, good
humored personality had spread throughout the Church, so that the
people felt that they were acquainted with “Jack” Newgent (later
Uncle Jack) even though they had never met him personally. Arriving
at the city some time after dark, worn by the long journey, the
discomforts of which were aggravated by their poor health, they
little dreamed of finding in that particular realm an acquaintance or
anyone who had any concern for them.
Great indeed was Newgent’s surprise when, as he alighted from
the train, a gentleman, a total stranger, with a lantern on his arm,
stepped up and in a familiar manner accosted him, “Hello! Is this
Jack Newgent?”
He had been so familiarly known as “Jack,” that he had resolved to
be known by the more grave and dignified appellation of Andrew J.
Newgent when he came into his new kingdom. But his expectation
perished, as it would have done even had the circumstances been
otherwise. A man’s name, like his clothes, is a part of him, and if it
does not fit, his friends will persist in trimming it until it does. The
personality and the title cannot be unequally yoked together.
“Well,” said the reverend gentleman from the Hoosier State, “I
suppose if I should land in the heart of Africa, some Hottentot would
come rushing out of the jungle and say, ‘Hello, Jack Newgent!’ Who
are you, anyway?” The stranger was Mr. W. C. Keezel, a prominent
layman in the conference, who had been advised of their coming by
Dr. D. K. Flickinger, Secretary of the Missionary Society, and was
there to take them to his hospitable home. It was a pleasant
surprise, and they felt at once that they were among friends whose
hearts God had touched with his spirit of kindness and tenderness.
Their anxieties were dispelled, and they felt as near heaven in
Tennessee as in Indiana.
Next day his host took him on a ten-mile ride by horseback over a
mountain road to a quarterly conference, where he met a number of
ministers, and began to get acquainted with his new co-workers. His
presence filled the little band of faithful toilers with new hope and
courage. He preached the following day (Sunday) at a neighboring
church to an immense crowd. Here he met Rev. Eli Marshall, a
minister of repute in the Quaker—or Friends—church, with whom he
was destined to form a close friendship, a friendship which revealed
later to both of these servants of God how mysteriously God moves
in answer to the earnest prayers of his faithful children.
Rev. Mr. Marshall was not only an able minister, but was also a
successful business man, being the owner of several plantations. He
took Newgent to his home, and later showed him a congenial
cottage on one of his plantations. “This is at thy disposal,” he said,
“if it suits thee.” Newgent replied that it was just such a place as he
was looking for, as it was but a short distance from town and the
railroad station, and inquired as to the rental value.
“Just move in,” said Marshall, “we will talk about that some other
time.”
But when Newgent insisted, he set a nominal price, which
indicated that he was not especially concerned about the financial
side of the transaction. He furthermore insisted on transporting
Newgent’s household goods from the station, but this privilege he
was compelled to share with Mr. Keezel. While they were moving his
goods from the train, his Quaker neighbors set to work and filled the
smoke-house with provisions, and supplied sufficient fuel to last him
through the winter. Such expressions of kindness and generosity
seldom had been seen.
The fourth week in October was the time for the Quakers’ yearly
meeting, to be held at Rev. Mr. Marshall’s home church. He had
issued an order to Newgent to have no engagement for that time, as
his presence and help were desired at the meeting. Under the
circumstances there was but one thing to do, and that was to
respect the order. These meetings were matters of no small
significance in that denomination. They usually lasted several days,
and were great seasons of fellowship. They were very largely
attended so that the program sometimes had to be carried out in
several sections. Newgent had never had the privilege of attending a
Quaker meeting, but his appreciation of the Quakers by this time
knew no bounds.
He first went to the meeting on Saturday morning and was
surprised to find more than a thousand people on the ground. His
friend, Rev. Mr. Marshall, met him immediately and said, “If the Spirit
moves thee to preach to-day, we want thee to preach in the church
this morning.” Some one was to preach in the school house nearby.
The Spirit moved, and Newgent preached.
In the afternoon he was “moved” to preach again. He was urged
to preach again at night. This time the Spirit was not consulted, but
his preaching had touched a responsive chord in the Quaker heart,
so it was taken for granted that the Spirit would be favorable. An
out-door service and a service in the school house besides that in
the church were required in order to accommodate the crowd.
Newgent declined to preach at this time, not wishing to usurp the
honors that belonged to the Quaker preachers. But the Quaker
“Spirit” refused to let him off. He was even urged to sing a special
song, which was a great departure from Quaker usage in those
days. While preaching with his usual power, it was evident to him
that great conviction prevailed in the congregation. As he had been
invited to depart from one of the Quaker usages, he now felt bold to
depart from another. Indeed he felt strongly moved by the Spirit to
give an invitation for seekers to come to the altar. The invitation
given, the altar was soon crowded with anxious penitents. He then
called upon the Quakers to come forward and to sing and pray with
the seekers. This a considerable number did, casting aside all
reserve, and the meeting became a typical United Brethren revival.
It was one time when the Spirit “moved” beyond question in a
Quaker meeting.
He was given right of way in the church on Sunday morning,
Sunday evening, and Monday evening. A new element was thus
diffused into Quakerdom. He held a meeting in that same
community a few weeks later, in which the Quakers took a leading
part, and which resulted in about a hundred conversions.
The best part of the whole procedure came to light when Newgent
called to pay his landlord the small pittance that was due on rent.
Rev. Mr. Marshall refused to accept even the nominal amount that
had been agreed upon.
“Let me explain,” he said, “I have never told anybody what I am
going to tell thee—not even my wife. Some three months ago I
moved my foreman out of that house, and began to pray for the
Lord to send us a good, live preacher from the North. I had got tired
of these slow-going Southern fellows. But I forgot to tell the Lord to
send a Quaker. So the Lord was free to send whomsoever he
pleased. And the first time I heard thee preach, I said, ‘There is the
answer to my prayer.’ Now, it would not do for me to charge rent of
the man the Lord sent in answer to my prayer, when he is living in
the property I vacated for him when I besought the Lord to send
him. That house is for thee as long as thee wants it.”
When this noble soul was called to heaven some years later, Rev.
Mr. Newgent was called from a distant State to preach his funeral.
Truly, he was a man of God.
When the conference projected a college enterprise at Greenville,
Rev. Mr. Newgent took up his residence at that place so as to give
personal attention and encouragement to the institution. This college
was afterwards moved to White Pine, Newgent being the leading
spirit in the matter of relocation. He served as financial agent and
supervised the construction of the building. Through his personal
efforts the building was erected and paid for.
The evangelistic gift and executive faculty, both of which were
prominent in our subject, peculiarly fitted him for the duties of
Missionary Superintendent amid such conditions as the Tennessee
Conference presented. Much incipient work had to be done. The
routine work of his office required only a small portion of his time,
leaving him free to do the work of an evangelist, to encourage weak
churches and to survey new territory to conquer. This narrative has
already afforded many examples of his constructive work along
these lines. One more characteristic incident may not be out of
place.
Near Limestone, Tennessee, was a church which was so
unpromising that the quarterly conference seriously considered
abandoning it and disposing of the property. It was well located, but
there were strong churches on either side, and the little church,
overshadowed as it was by these older organizations, had never
been able to gain a proper standing.
“Let us give it another chance,” said Newgent, who was presiding
at the meeting. “I will hold a meeting there at the first opportunity,
and we will see if it can be saved.” He held the meeting accordingly
and received ninety-seven members into the church, and the little,
struggling church was lifted to such a position of prestige and
prominence that it overshadowed its rivals, becoming a strong
center of religious influence.
But it was not enough to merely get people converted and
brought into the church. They must be taught in the doctrines of the
church, so as not to get their doctrinal ideas from other sources.
One of the strong churches of this community was of the Dunkard
order, and mainly through its influence a strong immersion sentiment
prevailed. At the close of the revival there were a large number of
applicants for baptism. According to prevailing custom, all expected
to be immersed. It was in order on such occasions for the baptismal
service to be prefaced by a sermon on baptism. Rev. Mr. Newgent
took advantage of the opportunity to make some remarks on the
mode of baptism, which was the one live subject in religious circles.
In his discourse he said:
“We often hear people say, ‘I want to be baptized as Jesus was.’ I
do not share this sentiment. For in one essential respect Jesus’
baptism was different from ours. It was for a different purpose. He
was baptized to fulfill the law; we, because we are sinners, either for
the forgiveness of sins or because they are forgiven.
“But we may be baptized in the same manner in which he was
baptized, and if you wish, I will tell you what that was. Paul said, ‘He
was made a priest like unto his brethren.’ Jesus said, ‘I am come,
not to destroy the law or the prophets, but to fulfill.’ He fulfilled
every jot and tittle of the law. The law required a priest to have the
water of consecration sprinkled upon his head when he was thirty
years of age. Hence, if Christ was made a priest like his brethren, it
is easy to see that his baptism was the same as that of the priests,
his brethren, and that the water was sprinkled upon his head at the
age of thirty; otherwise he would not have fulfilled every jot and
tittle of the law.”
A prominent Dunkard preacher present made a public statement
at the close of the discourse to the effect that, while he had always
believed and taught that Christ was baptized by immersion, he was
now fully convinced that he had been mistaken. When they came to
the baptismal service, all the applicants chose the mode of
sprinkling, though they had come prepared to be immersed.
Under his capable and aggressive leadership the conference
maintained a steady growth. At first its territory was confined to the
eastern part of the State. But in the early nineties he, with some
other ministers, advanced to the central and western parts of the
State on a sort of missionary-evangelistic campaign. They held a
number of meetings and were successful in winning quite a
sprinkling of converts. The work thus accomplished made possible
the organization of what was then known as the Tennessee River
Conference in 1896.
One of the most important events in connection with the
Tennessee Conference, and which was brought about mainly
through his influence, occurred in 1895. It is referred to as follows in
Berger’s History of the United Brethren Church, page 614:
“About two years ago a movement which had been for some time
in process of development, began to take definite form, resulting in
considerable additions both of ministers and laymen to the United
Brethren Church. The greater number of these came from the
Methodist Episcopal Church, some from the M. E. Church, South,
and a few from other denominations. Those coming from the
Methodist churches were attracted chiefly by the milder form of
episcopal government in the United Brethren Church. There was for
them no possible inducement in material or worldly considerations.
They could not look for larger salaries or easier fields of labor or
lighter sacrifices, nor was the prospect of official promotion better
than in the churches from which they came. Nor could they bring
with them any of the church-houses or other property which they
had aided in building. No thought or hope of this kind was
entertained; much less was any effort made to do so. Influenced by
principle alone, and in the face of present loss, they chose to cast in
their lot with us, and they have addressed themselves earnestly to
the work in their new relations. About twenty-five ministers in all,
with a considerable number of members, have thus connected
themselves with the United Brethren. Among the leading ministers of
the movement are: Dr. T. C. Carter, Rev. W. L. Richardson, J. D.
Droke, and others. They have been given a cordial welcome by the
United Brethren Church, not in any spirit of proselytism, for no
proselyting was done, nor from any desire to reap where others
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookball.com

You might also like