Ruby in the context of scientific computing



Similar documents
6.170 Tutorial 3 - Ruby Basics

COMPARATIVE STUDY OF BROWSER BASED OPEN SOURCE TESTING TOOLS WATIR AND WET

Programming Languages

THE ROAD TO CODE. ANDROID DEVELOPMENT IMMERSIVE May 31. WEB DEVELOPMENT IMMERSIVE May 31 GENERAL ASSEMBLY

VOIP and Ruby. The Convergence of Web and Voice Applications using Open Source Software. Justin Grammens Localtone Interactive

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

2! Multimedia Programming with! Python and SDL

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Introduction to Python

Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

Chapter 15 Functional Programming Languages

BEST WEB PROGRAMMING LANGUAGES TO LEARN ON YOUR OWN TIME

Scientific Programming, Analysis, and Visualization with Python. Mteor 227 Fall 2015

Interested in Expanding your Technical Skills?

Evolution of the Major Programming Languages

The IBM i on Rails + + Anthony Avison anthony@powerruby.com. Copyright 2014 PowerRuby, Inc.

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Apache Thrift and Ruby

CS 106 Introduction to Computer Science I

by Pearson Education, Inc. All Rights Reserved.

CIS 192: Lecture 13 Scientific Computing and Unit Testing

Getting Started with the Internet Communications Engine

CSCI 3136 Principles of Programming Languages

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

JRuby Now and Future Charles Oliver Nutter JRuby Guy Sun Microsystems

Tutorial on Writing Modular Programs in Scala

A Comparison of Programming Languages for Graphical User Interface Programming

Assignment 2: Option Pricing and the Black-Scholes formula The University of British Columbia Science One CS Instructor: Michael Gelbart

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

Mrs: MapReduce for Scientific Computing in Python

Introduction to Python

Programming Using Python

Software Engineering Best Practices. Christian Hartshorne Field Engineer Daniel Thomas Internal Sales Engineer

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

PYTHON Basics

Scientific Programming in Python

C# and Other Languages

JRuby Power on the JVM. Ola Bini JRuby Core Developer ThoughtWorks

Art of Code Front-end Web Development Training Program

Rake Task Management Essentials

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

Moving from CS 61A Scheme to CS 61B Java

Pipe Cleaner Proteins. Essential question: How does the structure of proteins relate to their function in the cell?

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Fact Extraction for Ruby on Rails Platform

Acta Universitaria ISSN: Universidad de Guanajuato México

Symbol Tables. Introduction

Pete Helgren Ruby On Rails on i

McGraw-Hill The McGraw-Hill Companies, Inc.,

PHP vs. Python vs. Ruby The web scripting language shootout

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Unit testing using Python nose

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Today's Topics. COMP 388/441: Human-Computer Interaction. simple 2D plotting. 1D techniques. Ancient plotting techniques. Data Visualization:

Programming Languages CIS 443

GContracts Programming by Contract with Groovy. Andre Steingress

Data sharing in the Big Data era

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

Chapter 13: Program Development and Programming Languages

03 - Lexical Analysis

Java Interview Questions and Answers

Introduction to Software Paradigms & Procedural Programming Paradigm

Charles Dierbach. Wiley

How To Develop Software

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

The programming language C. sws1 1

Practical Essbase Web Services

Server-Side Scripting and Web Development. By Susan L. Miertschin

Computational Mathematics with Python

Crowdsourcing suggestions to programming problems for dynamic web development languages

ANSA and μeta as a CAE Software Development Platform

Web Development Frameworks

Textual Modeling Languages

Ruby on Rails. Object Oriented Analysis & Design CSCI-5448 University of Colorado, Boulder. -Dheeraj Potlapally

Efficiency Considerations of PERL and Python in Distributed Processing

Android Developer Fundamental 1

Software Visualization Tools for Component Reuse

How To Program A Computer

SimpleFSM - a domain-specific language for SIP communication systems - Part I: Language description

Chapter 3.2 C++, Java, and Scripting Languages. The major programming languages used in game development.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Android Application Development Course Program

Netbeans 6.0. José Maria Silveira Neto. Sun Campus Ambassador

Part I Courses Syllabus

MEAP Edition Manning Early Access Program Nim in Action Version 1

Introduction to the course, Eclipse and Python

Adding Panoramas to Google Maps Using Ajax

Whitepapers at Amikelive.com

Introducing Tetra: An Educational Parallel Programming System

CloudLinux is a proven solution for shared hosting providers that:

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

Transcription:

Ruby in the context of scientific computing 16 January 2014 1/24

Overview Introduction Characteristics and Features Closures Ruby and Scientific Computing SciRuby Bioruby Conclusion References 2/24

Introduction Created by Yukihiro "Matz" Matsumoto First public release in 1995 Specification published in 2010 Was mostly popularized by Ruby on Rails (a web framework) Google searches for "Ruby programming" according to Google Trends 3/24

Introduction Main objective: to make developers happy :) The biggest goal of Ruby is developer friendliness, and productivity of application development and intuitive description of program behaviors take precedence over brevity of the language specification itself and ease of implementation. - Specification document RubyGems: package management platform for sharing Ruby programs and libraries gem install mygem 4/24

Implementations Many implementations: Ruby MRI (CRuby), YARV, JRuby, Rubinius, IronRuby, Ruby.NET, etc. Ruby MRI: Matz's Ruby Interpreter, also known as CRuby Reference implementation YARV merged with MRI since 1.9 This presentation's focus: Ruby MRI Many plugins and gems might not work with other implementations 5/24

Performance Interpreted, dynamically typed Perforamce in the same order of magnitude as Python and PHP...and not as good as compiled, statically-typed languages (C/C++, Java, C#, etc.) 6/24

Programming paradigms Supports multiple paradigms Procedural: Procedural-style code outside classes is in the Object class scope Object Oriented: (Almost) everything is an object Even classes E.g., binary operators are just syntactic sugar for method calls: 1 + 2 is the same as 1.+(2) Functional Closures Higher-order functions Implicit return 7/24

Classes and Modules Classes can be reopened and modified at any point The same can be done with instance objects class String def append_exclamation self + "!" end end No multiple inheritance, no Interfaces Mixins via Modules module Constants PI = 3.1416 E = 2.7183 def pi_squared return PI ** 2 end end class Calculator include Constants end 8/24

Type system Dynamic and strong typing Duck typing ( if it walks like a duck an quacks like a duck... ) It is the object's methods and properties, not its class or inheritance status, that determine semantics words = ["This", "is", "a", "sentence"] if words.respond_to?("join") words.join(" ") + "." end => "This is a sentence." 9/24

Closures Associated with functional programming (Old) definition from Wikipedia: In computer science, a closure is a first-class function with free variables that are bound in the lexical environment. Closures are functions that can be passed around like objects are bound to the scope where they were created Ruby makes heavy use of closures (via Blocks, Procs and Lambdas) 10/24

Blocks Blocks Enclosed with either {} or do/end fibonacci = [1, 1] 10.times do fibonacci << fibonacci[-2] + fibonacci[-1] end => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144] Methods can be made to accept Blocks as parameters using the yield keyword def pass_arg_to_block(arg) yield arg end pass_arg_to_block(5) { n n * 10 } => 50 11/24

Blocks, Procs, Lambdas Blocks are not objects, e.g. can't get passed around Solution: Procs and Lambdas Lambdas are the same as Procs, but: more strict argument checking different handling of return calls multiply_by_ten = Proc.new { n n * 10 } # OR = proc { n n * 10 } # OR = lambda { n n * 10 } pass_arg_to_block(5, &multiply_by_ten) => 50 [1, 2, 3].map(&multiply_by_ten) => [10, 20, 30] 12/24

Threads Green threads in 1.8 Native threads in 1.9 Global Interpreter Lock: only one thread executed at a time No true concurrency Better integrity protection (e.g. many extensions are not thread safe) BUT: doesn't atuomatically stop you from writing thread-unsafe code! Other implementations deal with threads differently 13/24

Ruby and Scientific Computing Due to historical reasons, Python grew into a widely-used language in scientific computing (SciPy/NumPy, matplotlib, etc.), while Ruby didn't Google's promotion of Python Ruby community being mainly focused on Rails...but such a thing as scientific Ruby does exist: SciRuby BioRuby 14/24

SciRuby Collection of libraries for various scientific tasks First (Git) commit in 2011 Might not be ready for mission critical tasks yet Word to the wise: These gems have been tested, but are not battle-hardened. If you re thinking of using NMatrix (or other SciRuby components) to write mission critical code, such as for a self-driving car or controlling an ARKYD 100 satellite, you should expect to encounter a few bugs and be prepared for them. - sciruby.com 15/24

SciRuby Visualization Rubyvis (Plotrb?) Statistics and probability Statsample Distribution Numeric Minimization Integration Nmatrix 16/24

Rubyvis Plotting require 'rubyvis' vis = Rubyvis::Panel.new do width 150 height 150 bar do data [1, 1.2, 1.7, 1.5, 0.7, 0.3] width 20 height { d d * 80} bottom(0) left {index * 25} end end vis.render outfile = open('rv-out.svg', 'w') outfile.write (vis.to_svg) outfile.close() 17/24

Rubyvis: More Plotting 18/24

Statsample A statistics suite for Ruby Sample code: require 'statsample' ss_analysis(statsample::graph::boxplot) do n=30 a=rnorm(n-1, 50, 10) b=rnorm(n, 30, 5) c=rnorm(n, 5, 1) a.push(2) boxplot(:vectors=>[a,b,c], :width=>300, :height=>300, :groups=> %w{first first second}, :minimum=>0) end Statsample::Analysis.run # Open svg file on *nix application defined 19/24

Minimization and Integration Minimization require 'integration' require 'minimization' d = Minimization::Brent.new(-1000, 20000, proc { x x**2}) d.iterate puts d.x_minimum puts d.f_minimum # Output: # 4.005934284325451e-31 # 1.604750949033406e-61 Integration puts Integration.integrate(1, 2, {:tolerance=>1e-10,:method=>:simpson}) { x x**2} normal_pdf=lambda { x (1/Math.sqrt(2*Math::PI))*Math.exp(-(x**2/ 2))} puts Integration.integrate(Integration::MInfini ty, 0, {:tolerance=>1e-10}, &normal_pdf) puts Integration.integrate(0, Integration::Infinity, {:tolerance=>1e-10}, &normal_pdf) # Output: # 2.333333333333333 # 0.5 # 0.5 20/24

BioRuby A project that aims to provide a set of tools for tasks in computationial biology and bioinformatics (sequence analysis, pathway analysis, sequence alignment, etc.) Bioinformatics is an interdisciplinary field that develops and improves on methods for storing, retrieving, organizing and analyzing biological data. A major activity in bioinformatics is to develop software tools to generate useful biological knowledge. - Wikipedia A major task in bioinformatics is analyzing character sequences. BioRuby helps with this. Biogem: Tool that aids bioinformaticians in writing plugins and sharing them with the rest of the BioRuby community Image source: http://www.medicine.uiowa.edu 21/24

BioRuby: Example bioruby> seq = Bio::Sequence::NA.new("atgcatgcaaaa") ==> "atgcatgcaaaa" bioruby> seq.complement ==> "ttttgcatgcat" bioruby> seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1) ==> "gcatgc" bioruby> seq.gc_percent ==> 33 bioruby> seq.composition ==> {"a"=>6, "c"=>2, "g"=>2, "t"=>2} bioruby> seq.translate # each three nucleotides represent an amino acid ==> "MHAK" bioruby> seq.translate.codes # (standard) amino acids have abbreviations ==> ["Met", "His", "Ala", "Lys"] bioruby> seq.translate.names ==> ["methionine", "histidine", "alanine", "lysine"] bioruby> seq.translate.molecular_weight ==> 485.605 bioruby> counts = {'a'=>seq.count('a'),'c'=>seq.count('c'),'g'=>seq.count('g'),'t'=>seq.count('t')} ==> {"a"=>6, "c"=>2, "g"=>2, "t"=>2} bioruby> randomseq = Bio::Sequence::NA.randomize(counts) ==> "aaacatgaagtc" 22/24

Conclusion Feature-rich, developer-friendly multi-paradigm language Powerful mixture of object-oriented and functional programming Scientific libraries available Lower performance but higher programmer productivity vs. compiled/statically-typed languages Good for prototyping? Fun to use! 23/24

Refrences Official Ruby website https://www.ruby-lang.org/en/about/ Ruby documentation http://ruby-doc.org/ Computer Language Benchmarks Game http://benchmarksgame.alioth.debian.org Closures and Higher-Order Functions http://weblog.raganwald.com/2007/01/closures-and-higher-order-functions.html Closures A Simple Explanation (Using Ruby) http://www.skorks.com/2010/05/closures-a-simple-explanation-using-ruby/ SciRuby http://sciruby.com/ BioRuby http://bioruby.open-bio.org/ 24/24