Science: Maths and Stats Dr Andy Evans. Mathematics The classic texts for scientific computing are the Numerical Recipes books. Java code available to.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Lecture 5.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Guide To UNIX Using Linux Third Edition
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Training on R-language Mārtiņš Liberts Central Statistical Bureau of Latvia.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Programming for Geographical Information Analysis: Advanced Skills Lecture 8: Libraries II: Science Dr Andy Evans.
Basic R Programming for Life Science Undergraduate Students Introductory Workshop (Session 1) 1.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Introduction to Python
732A44 Programming in R.  Self-studies of the course book  2 Lectures (1 in the beginning, 1 in the end)  Labs (computer). Compulsory submission of.
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to Programming with RAPTOR
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to R Carol Bult The Jackson Laboratory Functional Genomics (BMB550) Spring 2011.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
Ch13-1 Chap 13 Introduction to Matlab 13.1 Introduction MATLAB : The MATrix LABoratory program Not only is the MATLAB programming language exceptionally.
1 Programming a Computer Lecture Ten. 2 Outline  A quick introduction to the programming language C  Introduction to software packages: Matlab for numerical.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Skill Area 311 Part B. Lecture Overview Assembly Code Assembler Format of Assembly Code Advantages Assembly Code Disadvantages Assembly Code High-Level.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Programming in R Intro, data and programming structures
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Coding Concepts (Basics)
Introduction to Matlab
MIS2502: Data Analytics Introduction to R and RStudio
Simulation And Modeling
> Introduction to Nelson Rios, Tulane University
Presentation transcript:

Science: Maths and Stats Dr Andy Evans

Mathematics The classic texts for scientific computing are the Numerical Recipes books. Java code available to buy:

Numerical Recipes For java there is also Hang T. Lau (2003) A Numerical Library in Java for Scientists and Engineers Colt JScience JAMA

Maple Commercial mathematics application (commercial licence $2,845). Does, for example, algebraic manipulation, calculus, etc. Outputs processes as C, C#, Java, Fortran, Visual Basic, and MATLAB code. C and Java APIs for program connection.

Mathematics Statistics Graphs and Networks Text and Language

Statistics R (GNU): Developed as a free version on the stats language S, combined with a functional programming language.

Programming languages We’ve dealt with Imperative Programming languages: commands about what to do to change the state of the program (i.e. its collected variables). These are usually also Procedural, in that the program is divided into procedures to change states. Most Procedural languages are now Object Orientated.

Programming languages The other branch of languages allow Declarative Programming: concentrates on describing what a program should do, not how, and avoiding state changes. Clearest examples are Functional Programming: everything is described as a reference to another function: a = x + 10; x = y + 2; Run program for the argument y = 12 Also Logical Programming: same kind of thing but based on finding logical proofs/derivations. Things that fall into the category mortal includes humans. Socrates is human. Run program to find if Socrates is mortal?

Declarative languages Examples: Lisp; Prolog; (bits of SQL) Beloved of academics, but weren’t used much in the real world, until recently (except SQL). Advantage is that they avoid unlimited internal and external state changes, therefore much easier to check and predict. Prolog useful for language processing. A version of Lisp, Scheme, inspired elements of R.

R Language and a series of packages. Written in C/C++/Fortran but Java can be used. Functional language but with procedural and OOP elements. Uses scalars, matrices, vectors, and lists. Can replace the GUI with a variety of alternatives. Powerful and increasingly stats software of choice, but steep learning curve and massive range of add-on packages.

RGui

Packages Lots come with it. Comprehensive R Archive Network (CRAN): Packages → Set CRAN Mirror… Packages → Install package(s)… library() : list packages library(packageName) : load package for use library(help = packageName) : what’s in a package detach("package:packageName") : unload

Example data1 <- read.csv(“m:\\r-projects\\data.tab", header = TRUE) attach(data1) plot(Age, Desperation, main="Age vs. Desperation") lineeq <- lm(Desperation ~ Age, data=data1) x <- seq(min(Age), max(Age), by=10.0) newData <- data.frame(Age = x) predictions <- predict(lineeq, newdata = newData) lines(Age, predictions) detach(data1) rm (data1, lineeq, newData, predictions, x)

Working with R R uses ‘Workspace’ directories. Good practice to work in a new directory for each project ( File → Change Dir… ) Dataset names etc. must have a letter before any numbers. R constructs data objects, that can be seen with objects() and removed with rm(objectName). If you save the workspace, it saves these objects in an.RData file.

Working with R Commands can be separated by new lines or enclosed thus: {command;command;command} If you fail to close a command, you’ll see “+”. You can load scripts of commands. Note that on Windows you just have to be careful to adjust all filepaths, thus: source("c:\\scripts\\commands.r") Or source("c:/scripts/commands.r") The scripts are just text files of commands.

Quick tips Simplest data structure is the vector of data x <- c(10.4, 5.6, 3.1, 6.4, 21.7) attach() makes data available by column name (cp. detach(name)). Vector elements can be searched and selected using indices or expressions in [], e.g.: y <- x[!is.na(x)] where na is “Not available” In operations using 2 vectors, the shortest gets cycled through as much as is needed.

Other data structures Matrices or more generally arrays Factors (handle categorical data). Vectors or lists (latter can be recursive) Data frames – tables of data Functions (store code) Each data element is assigned a mode, or data type: logical, numeric, complex, character or raw.

Quick tips $ can be used to look inside objects, e.g. myData$column1 Operators: +, -, *, / and ^ (i.e. raise to the power) Functions include: log, exp, sin, cos, tan, sqrt, max, min, length, sum, mean, var (variance), sort.

Help Best start is “Introduction to R”: ?solve : help for solve function help.start() : start the HTML help ??solve : search help for solve ?help : info other help systems

R-Spatial Large number of packages dealing with spatial analysis, including: Mapping (incl. GoogleMap/Chart, and KML production) Point pattern and cluster analysis. Geographically Weighted Regression. Network mathematics. Kriging and other interpolation. Excellent starting point is James Cheshire’s (CASA) :

Non-package addons R-Forge: GUIs, bridges to other languages, etc.

Programming R Has its own flow control: if ( condition ) { statement 1 } else { statement 2 } for (i in 1:3) print(i) Note that this is actually a “for-each” loop - “:” just generates a list of numbers, so you can also do this: x <- c("Hello","World") for (i in x) print(i)

Programming with R Various options, but best is rJava: Two parts: rJava itself : lets R use Java objects. JRI (Java/R Interface) : lets Java use R.

JRI Start by setting up an Rengine object. Can run it with or without an R prompt GUI. Send in standard R commands using Rengine’s eval(String) method. Can also assign () various values to a symbol re.assign(“x”, “10.0,20.0,30.0”); Methods for dealing with GUI elements (see also the iPlot and JavaGD packages).

Getting data back Two mechanisms: Push: Get back an object containing the information R would have output to the console (and a bit more). Callback: Java provides methods which R calls when different tasks done.

Push Get back a REXP object: Contains R output and other information. rexp.toString() : shows content. Can filter out information with: rexp.asDoubleArray() rexp.asStringArray() etc.

Callback Add an object to handle events: rengine.addMainLoopCallbacks(RMainLoopCallbacks) Largely set up to manage user interface interaction. RMainLoopCallbacks contains methods called at key moments, for example: rReadConsole() Called while R is waiting for user input.

Floating point numbers Be aware that floating point numbers are rounded. For example, in R, floating point numbers are rounded to (typically) 53 binary digits accuracy. This means numbers may differ depending on the algorithm sequence used to generate them. There is no guarantee that even simple floating point numbers will be accurate at large decimal places, even if they don’t appear to use them.

Floating point numbers David Goldberg (1991), “What Every Computer Scientist Should Know About Floating-Point Arithmetic”, ACM Computing Surveys, 23/1, 5– Hacker's Delight by Henry S. Warren Jr Randall Hyde’s “Write Great Code” series. users/vuik/wi211/disasters.html