introduction to computational models using...

32
Introduction to Computational Models Using Python CS4491 José M. Garrido C. Department of Computer Science College of Computing and Software Engineering Kennesaw State University June, 2016 José M. Garrido C. Introduction to Computational Models Using Python

Upload: lenga

Post on 16-Mar-2018

228 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Introduction to Computational Models UsingPythonCS4491

José M. Garrido C.

Department of Computer ScienceCollege of Computing and Software Engineering

Kennesaw State University

June, 2016

José M. Garrido C. Introduction to Computational Models Using Python

Page 2: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Problem Solving

A general process of problem solving involves the followingsteps:

1 Understanding the problem2 Describing the problem in a clear, complete, and

unambiguous form3 Designing a solution to the problem (algorithm)4 Developing a computer solution to the problem.5 Test

José M. Garrido C. Introduction to Computational Models Using Python

Page 3: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Computational Models

An essential modeling method is to use mathematicalentities such as numbers, functions, and sets to describeproperties and their relationships to problems andreal-world systems.Such models are known as mathematical models.A computational model is an implementation in a computersystem of a mathematical model and usually requires highperformance computational resources to execute.The computational model is used to study the behavior of alarge and complex system.

José M. Garrido C. Introduction to Computational Models Using Python

Page 4: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Developing Computational Models

Developing a computational model consists of:

Applying a formal software development processApplying Computer Science concepts, principles andmethods, such as:

Abstraction and decompositionProgramming principlesData structuresAlgorithm structuresConcurrency and synchronizationModeling and simulationMulti-threading, parallel, and distributed computing for highperformance (HPC)

José M. Garrido C. Introduction to Computational Models Using Python

Page 5: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Developing Computational Models

José M. Garrido C. Introduction to Computational Models Using Python

Page 6: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

A Computational Model

Is a computer model that implements thesolution to a (scientific) complex problemIt usually requires a mathematical model orrepresentation that has been formulated forthe problem.The software implementation often requireshigh-performance computing (HPC) torun.

José M. Garrido C. Introduction to Computational Models Using Python

Page 7: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Computational Science

Computational science is an emerging area (or discipline)that includes concepts, principles, and methods fromApplied Mathematics and Computer Science.These are applied in various areas of science andengineering to solve large-scale scientific problems.Computational modeling and computational thinking arethe foundational components of computational science andfocuses on reasoning about problems.

José M. Garrido C. Introduction to Computational Models Using Python

Page 8: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Computational Thinking

Reasoning about computer problem solvingThe ability to describe the requirements of a problem and,if possible, design a solution that can be implemented in acomputerMulti-disciplinary important problems require team workImplementation of a solution results in a computationalmodel

José M. Garrido C. Introduction to Computational Models Using Python

Page 9: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Multi-disciplinary Development of ComputationalModels

Applying interdisciplinary and multi-disciplinaryapproachesIncluding perspectives from the various sciences such as:

physicsbiologychemistryother disciplines.

José M. Garrido C. Introduction to Computational Models Using Python

Page 10: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

What Does Computational Science Involve?

Reasoning about computer problem solvingThe problem domain is multidisciplinaryThe ability to describe the requirements of a problem and,if possible, design a solution that can be implemented in acomputerDeveloping computational models needs the application ofcomputer science principles, concepts, and methods.

José M. Garrido C. Introduction to Computational Models Using Python

Page 11: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Multi-disciplinary and Inter-disciplinary Computing

Both are general approaches that are very useful in developingcomputational models with teams.

Multidisciplinary computing is a non-integrative mixtureof approaches from the various disciplines; each disciplineretains its methodologies and assumptions without changeor development from other disciplines within themultidisciplinary relationship.Interdisciplinary computing involves the combining of twoor more approaches each from an academic field into onesingle process. An interdisciplinary approach crossestraditional boundaries between academic disciplines.

José M. Garrido C. Introduction to Computational Models Using Python

Page 12: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Differences Between the Two Approaches

A Multidisciplinary team approach utilizes the skills andexperience of individuals from different disciplines, witheach discipline approaching the problem from their ownperspective.Most often, this approach involves separate individualanalysis. Multidisciplinary teams provide more knowledgeand experience than disciplines operating in isolation.An interdisciplinary team approach integrates separatediscipline approaches into a single analysis. It is acommon understanding and holistic view of all aspects ofthe problem.

José M. Garrido C. Introduction to Computational Models Using Python

Page 13: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Multi-dimensional Abstraction

The term multi-dimensional abstraction is proposed toemphasize the need to improve the development ofcomputational models with an interdisciplinary approach.For practical purposes, it involves a combined approach.Every member of the team must use abstraction to reducethe complexity of the real system to fit into the conceptualmodel.Each individual will use his/her own skills and knowledgeto determine the essential aspects of the system to model,within that part of the system that relates to their field.

José M. Garrido C. Introduction to Computational Models Using Python

Page 14: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

General Types of Computing in Computational Models

computing numerical values of variables that defineproperties of a systemoptimization of parameters of a system giving someconstraints (Linear and non-linear)showing the dynamical behavior of a system with time viasimulation (continuous or discrete)

José M. Garrido C. Introduction to Computational Models Using Python

Page 15: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Some Challenges of Computational Modeling

May need to apply several notations, techniques andmethods, such as: flowcharts, pseudo-code, UMLdiagrams, and/or othersUsually applies important CS/SE concepts, such as:abstraction and decompositionRequires a mathematical representation (a formalmathematical model)Not all problems can be easily modeled with mathematicsMany mathematical models do not have a formal (closed)solution

José M. Garrido C. Introduction to Computational Models Using Python

Page 16: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Software Tools for Numerical Solutions

Modeling at a high level of abstraction:

General purpose scientific computing environments/tools:Matlab, Octave, FreeMat, SciLabPyLab is an extension to the Python language, its five corecomponents are Python, NumPy, SciPy, Matplotlib, andIPython.Cython is an optimizing compiler for Python.Environments/tools for continuous simulation: Simulink(Matlab), Scicos (Scilab), Stella, Vensim, SimCAD, acsIX,Dymola, JMCAD, and others

José M. Garrido C. Introduction to Computational Models Using Python

Page 17: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Improving Performance

For improved performance, a more efficientimplementation of the computational model is necessary.Two relevant programming languages that provide veryefficient implementations are:

CFortran.

These have been used for very efficient numerical andscientific programming.

José M. Garrido C. Introduction to Computational Models Using Python

Page 18: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Enhancing the Process

The process of developing a computational model can beenhanced by including three levels of computerimplementation:

1 Prototyping, using the Matlab programming language2 Improved performance implementation, using: C or

Fortran programming languages.3 Include techniques, methods, and tools for high

performance computing (HPC).

José M. Garrido C. Introduction to Computational Models Using Python

Page 19: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Abstraction and Decomposition

Abstraction is recognized as a fundamental and essentialprinciple in problem solving and software development.Abstraction and decomposition are extremely importantin dealing with large and complex systems.Abstraction is the activity of hiding the details and exposingonly the essential features of a particular system.In modeling, one of the critical tasks is representing thevarious aspects of a system at different levels ofabstraction.A good abstraction captures the essential elements of asystem, and purposely leaving out the rest.

José M. Garrido C. Introduction to Computational Models Using Python

Page 20: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Temperature Conversion

The process of developing a computational model is illustratedin this section with an extremely simple problem: thetemperature conversion problem.

The mathematical representation of the solution to the problemis the formula expressing a temperature measurement F inFahrenheit in terms of the temperature measurement C inCelsius:

F =95

C + 32

Here C is a variable that represents the given temperature indegrees Celsius, and F is a derived variable, whose valuedepends on C.

José M. Garrido C. Introduction to Computational Models Using Python

Page 21: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Area and Perimeter of a Circle

Another simple problem is formulated and requires computingthe area and circumference of a circle, given its radius.

The mathematical model is:

cir = 2π r

area = π r2

José M. Garrido C. Introduction to Computational Models Using Python

Page 22: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Categories of Computational Models

From the perspective of how the model changes state in time,computational models can be divided into two generalcategories:

1 Continuous models2 Discrete models

A continuous model is one in which the changes of state in themodel occur continuously with time.

A model that represents the temperature in a boiler as part of apower plant can be considered a continuous model.

José M. Garrido C. Introduction to Computational Models Using Python

Page 23: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Continuous Model

José M. Garrido C. Introduction to Computational Models Using Python

Page 24: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Discrete Model

A discrete model represents a system that changes itsstates at discrete points in time, i.e., at specific instants.The model of a simple car-wash system is a discrete-eventmodel because an arrival event occurs, and causes achange in the state variable that represents the number ofcars in the queue that are waiting to receive service fromthe machine (the server).This state variable and any other only change its valueswhen an event occurs, i.e., at discrete instants.

José M. Garrido C. Introduction to Computational Models Using Python

Page 25: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Discrete Model

José M. Garrido C. Introduction to Computational Models Using Python

Page 26: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Programming Languages

A programming language includes a defined set of syntaxand semantic rules.There are several integrated development environments(IDE) that facilitate the development of programs.Examples of these are: Eclipse, Netbeans, CodeBlocks,and Codelite.Other tools include IDEs that are designed for numericaland scientific problem solving that have their ownprogramming language.There are several IDEs available for developing scientificapplications with Python. Some of these are: Spyder, IEP,Eric, PyDev, WingIDE, Canopy, Komodo IDE, andPycharm.

José M. Garrido C. Introduction to Computational Models Using Python

Page 27: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Interpreters and Python

An interpreter is a special program that performs syntaxchecking of a command in a user program written in ahigh-level programming language and immediatelyexecutes the command.Examples of interpreters are the ones used for thefollowing languages: Python, MATLAB, Octave, PHP, andPerl.The Python interpreter reads a command written in thePython programming language and immediately executesthe command.A Python program is a file of Python commands, so theprogram is also known as a script.In a terminal or command window, all the interaction with auser takes place by typing Python commands.

José M. Garrido C. Introduction to Computational Models Using Python

Page 28: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Python Interpreter

José M. Garrido C. Introduction to Computational Models Using Python

Page 29: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Working with the Python Interpreter

The command prompt is the symbol that the Pythoninterpreter displays on the window to alert the user that it iswaiting for a command.The Python prompt is >>> and is used for interactivemode of computing with Python.In a terminal window, the user starts the Python interpretersimply by typing python at the Linux prompt. Theinterpreter starts and displays the Python prompt >>>.Note how the Python interpreter immediately responds to acommand; this is the interactive mode of using Python.

José M. Garrido C. Introduction to Computational Models Using Python

Page 30: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Interactive Python

$ pythonPython 2.7.8 (default, May 20 2016, 15:20:10)[GCC 4.9.1] on linux2Type "help", "copyright", "credits" or "license" for more

information.>>> num = 15>>> num15>>> y = 20.6>>> y20.6>>> x = 2.56>>> j = 200>>> j200>>>

José M. Garrido C. Introduction to Computational Models Using Python

Page 31: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

More Operations Interactive Python

>>> z = y * x + 125.25>>> z177.986>>> z / 12.514.23888>>>

José M. Garrido C. Introduction to Computational Models Using Python

Page 32: Introduction to Computational Models Using …ksuweb.kennesaw.edu/~jgarrido/CS4491_notes/Scientific_comp_python...Introduction to Computational Models Using Python CS4491 José M

Questions?

José M. Garrido C. Introduction to Computational Models Using Python