16
Introduction to Julia for R Users Hans Werner Borchers Duale Hochschule Mannheim Köln R User Group Meetup December 2014 Hans W Borchers Köln R User Group Meetup 2014-12-12 1 / 32 Introduction to Julia for R Users Overview New programming languages since 2002 2002 Io Smalltalk, LISP; prototype-based 2003 Nemerle CLI; C#-like, LISP 2003 Scala JVM; Java, Smalltalk; stat.-typed 2004 Groovy JVM; Java, Python, Ruby, Smalltalk 2004 Nimrod Python, Pascal; statically-typed 2005 F# (Microsoft) CLI; C#-like, OCaml, Haskell 2007 Clojure JVM, CLR; LISP, Haskell, Erlang 2009 Go (Google) C, Oberon; statically typed 2010 Rust (Mozilla) C++-like, Erlang, LISP; LLVM 2012 Julia MATLAB (, R); mult.dispatch; LLVM 2014 Swift (Apple) Objective-C; LLVM See also: Python+numba, LuaJIT, Rubinius, RLLVM, Haskell, Matlab(?), ... Hans W Borchers Köln R User Group Meetup 2014-12-12 2 / 32

Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

  • Upload
    others

  • View
    22

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intro

duct

ionto

Julia

forR

User

s

Hans

Wer

nerB

orch

ers

Duale

Hoch

schu

leM

annh

eim

Köln

RUs

erGr

oup

Mee

tup

Dece

mbe

r201

4

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

121

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Ove

rview

New

prog

ram

min

glan

guag

essin

ce20

02

2002

IoSm

allt

alk,

LISP

;pr

otot

ype-

base

d20

03Ne

merl

eCL

I;C#

-lik

e,LI

SP20

03Sc

ala

JVM;

Java

,Sm

allt

alk;

stat

.-ty

ped

2004

Groo

vyJV

M;Ja

va,

Pyth

on,

Ruby

,Sm

allt

alk

2004

Nimr

odPy

thon

,Pa

scal

;st

atic

ally

-typ

ed20

05F#

(Mic

roso

ft)

CLI;

C#-l

ike,

OCam

l,Ha

skel

l20

07Cl

ojur

eJV

M,CL

R;LI

SP,

Hask

ell,

Erla

ng20

09Go

(Goo

gle)

C,Ob

eron

;st

atic

ally

type

d20

10Ru

st(M

ozil

la)

C++-

like

,Er

lang

,LI

SP;

LLVM

2012

Juli

aMA

TLAB

(,R)

;mu

lt.d

ispa

tch;

LLVM

2014

Swif

t(A

pple

)Ob

ject

ive-

C;LL

VM

See

also:

Pyth

on+

num

ba,L

uaJI

T,Ru

bini

us,R

LLVM

,Has

kell,

Mat

lab(?

),...

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

122

/32

Page 2: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Ove

rview

The

LLVM

com

piler

infra

struc

ture

proj

ect

“The

LLVM

proj

ectp

rovid

eslib

rarie

sfor

am

oder

n,in

dust

rials

treng

thop

timize

r,alo

ngwi

thco

dege

nera

tion

supp

ort[

and

inte

grat

edlin

ker]

form

any

CPUs

.The

libra

riesa

rebu

ildar

ound

awe

llsp

ecifi

edco

dere

pres

enta

tion,

calle

dLL

VMIn

term

ediat

eRe

pres

enta

tion

(IR).”

2012

ACM

Softw

are

Syst

emAw

ard

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

123

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Ove

rview

Wha

tisJ

ulia?

“Jul

iais

ahi

gh-le

vel,

high

-per

form

ance

dyna

mic

prog

ram

min

gla

ngua

gefo

rte

chni

calc

ompu

ting,

with

asy

ntax

that

isfa

milia

rto

user

sofo

ther

tech

nica

l[sc

ientifi

c]co

mpu

ting

envir

onm

ents

.

“Jul

ia’sL

LVM

-bas

edju

st-in

-tim

e(J

IT)c

ompi

lerco

mbi

ned

with

the

langu

age’s

desig

nall

owit

toap

proa

chan

dof

ten

mat

chth

epe

rform

ance

ofC.

“The

core

ofth

eJu

liaim

plem

enta

tion

islic

ense

dun

dert

heM

ITlic

ense

.Var

ious

libra

riesu

sed

byth

eJu

liaen

viron

men

tinc

lude

their

own

licen

sess

uch

asth

eGP

L,LG

PL,a

ndBS

D.”

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

124

/32

Page 3: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Ove

rview

40+

scien

tific

com

putin

gen

viron

men

ts

APL

Axio

mCh

Colt

[Jav

a]Eu

ler

Free

Mat

GAUS

SGD

L/PV

-WAV

EGe

nius

gret

lID

LIg

or_P

rojL

abLa

bVie

wMa

gma

Mapl

eMa

thca

dMa

them

atic

aMA

TLAB

Maxi

maMu

Pad

O-Ma

trix

Octa

veOr

igin

Lab

OxPA

RI/G

PPD

L[Pe

rl]

RRL

aBpl

usRO

OTS-

PLUS

SAGE

SAS

SCaV

iSSc

iLab

SciP

y[Py

thon

]Sc

iRub

ySp

eake

asy

Stat

aSc

iLua

[Lua

JIT]

Yori

ck

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

125

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Julia

synt

axan

dde

velo

pmen

t

REPL

:“He

llo,w

orld

.”ex

ampl

es

»h

="H

ello

";w

="w

orld

prin

tln(

"$h,

$w."

)He

llo,

worl

d.

»v

=[1

,2]

;A

=[1

2;3

4];

»w

=A

*v;

»A

\w

2-el

emen

tAr

ray{

Floa

t64,

1}:

1.0

2.0

»f(

x)=

x*

exp(

x);

»ma

p(f,

[0:0

.1:1

])11

-ele

ment

Arra

y{Fl

oat6

4,1}

:..

.H

ans

WBo

rche

rsKö

lnR

User

Grou

pM

eetu

p20

14-1

2-12

6/

32

Page 4: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Julia

synt

axan

dde

velo

pmen

t

Nice

tieso

fJul

iaSy

ntax

a=

[1.0

,2]

;b

=a;

b[1]

=0;

a#

0,2,

3,..

=0.

5772

1_56

649_

0153

2_86

f(x,

y,z)

=2x

+3y

+4z

r=

1//3

+1/

/6+

1//1

2+

1//1

5#

13//

20fa

ctor

ial(

big(

100)

)H

=[1

/(i+

j-1)

for

i=1:

8,j=

1:8]

22<

pi^e

<e^

pi<

24#

true

prin

tln(

"The

resu

ltof

pi*e

is$(

pi*e

).")

func

tion

f(x.

..)

for

ain

xpr

intl

n(a)

end

end

�ti

meq,

err

=qu

adgk

(sin

,0,

pi)

[1:5

]|>

x->x

.^2

|>su

m|>

inv

s=

:bfg

s#

symb

ol

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

127

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Julia

synt

axan

dde

velo

pmen

t

Som

edi

ffere

nces

toR

Julia

uses

=fo

rvar

iable

assig

nmen

t.Ve

ctor

sand

mat

rices

defin

edth

roug

hbr

acke

ts[,

];m

atrix

mul

tiplic

atio

n:*,

oper

atio

ns:.

*./

.+;

elem

entw

iseco

mpa

rison

s:.=

=.<

=.<

etc.

Nopa

rent

hese

sreq

uire

din

if,

for,

whil

eco

nstru

cts.

Use

true

inst

ead

ofTR

UE;0

or1

are

notb

oolea

ns.

Julia

dist

ingu

ishes

scala

rs,ve

ctor

s,m

atric

es,o

rarra

ysby

type

;ut

ilize

type

decla

ratio

nsfo

rerro

rhan

dlin

g.Fu

nctio

nar

gum

ents

are

prov

ided

byre

fere

nce,

notb

yva

lue.

Cons

eque

nce:

Func

tions

can

mut

ate

their

argu

men

ts.

Mul

tiple

retu

rnva

lues

thro

ugh

tupl

es;n

olis

tsor

nam

edve

ctor

s.St

atist

icsfu

nctio

nalit

yis

prov

ided

inpa

ckag

es,n

otin

Julia

base

.

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

128

/32

Page 5: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Trap

ezoid

alru

le—

vect

orize

d

func

tion

trap

z1(x

,y)

loca

ln

=le

ngth

(x)

ifle

ngth

(y)

!=n

erro

r("V

ecto

rsmu

stbe

ofsa

mele

ngth

")en

dsu

m((x

[2:e

nd]-

x[1:

end-

1]).

*(y[

2:en

d]+y

[1:e

nd-1

]))/

2en

d

»x

=li

nspa

ce(0

,pi

,10

0);

y=

sin(

x);

»pr

intl

n(tr

apz1

(x,

y));

gc()

1.99

9832

1638

9399

24»

@tim

e[t

rapz

1(x,

y)fo

ri

in1:

1000

];el

apse

dti

me:

0.02

0384

185

seco

nds

(692

1872

byte

sal

loca

ted)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

129

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Trap

ezoid

alru

le—

non-

vect

orize

d

func

tion

trap

z2(x

,y)

loca

ln

=le

ngth

(x)

ifle

ngth

(y)

!=n

erro

r("V

ecto

rs’x

’,’y

’mu

stbe

ofsa

mele

ngth

")en

dr

=0

ifn

==1

retu

rnr;

end

for

iin

2:n

r+=

(x[i

]-

x[i-

1])

*(y

[i]

+y[

i-1]

)en

dr

/2

end

»@t

ime

[tra

pz2(

x,y)

for

iin

1:10

00];

elap

sed

time

:0.

0096

1744

5se

cond

s(3

2159

04by

tes

allo

cate

d)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1210

/32

Page 6: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Trap

ezoid

alru

le—

type

-stab

le

func

tion

trap

z3(x

,y)

loca

ln

=le

ngth

(x)

ifle

ngth

(y)

!=n

erro

r("V

ecto

rs’x

’,’y

’mu

stbe

ofsa

mele

ngth

")en

dr

=0.

0if

n==

1re

turn

r;en

dfo

ri

in2:

nr

+=(x

[i]

-x[

i-1]

)*

(y[i

]+

y[i-

1])

end

r/

2en

d

@tim

e[t

rapz

3(x,

y)fo

ri

in1:

1000

];el

apse

dti

me:

0.00

1451

867

seco

nds

(479

04by

tes

allo

cate

d)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1211

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Trap

ezoid

alru

le—

w/o

boun

dsch

eckin

g

func

tion

trap

z{T<

:Num

ber}

(x::

Arra

yT,1

,y:

:Arr

ayT,

1)lo

cal

n=

leng

th(x

)if

leng

th(y

)!=

ner

ror(

"Vec

tors

’x’,

’y’

must

beof

same

leng

th")

end

r=

zero

(T)

ifn

==1

retu

rnr

end

for

iin

2:n

@inb

ound

sr

+=(x

[i]

-x[

i-1]

)*

(y[i

]+

y[i-

1])

end

r/

2en

d

»@t

ime

[tra

pz(x

,y)

for

iin

1:10

00];

elap

sed

time

:0.

0007

3023

3se

cond

s(4

7904

byte

sal

loca

ted)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1212

/32

Page 7: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Trap

ezoid

alru

le—

com

paris

ons

Resu

ltsan

dco

mpa

rison

with

Ran

dPy

thon

Timi

ngs

Resu

ltµ

s/lo

optr

apz1

0.02

0384

185

1.99

9832

1638

9399

2420

.4tr

apz2

0.00

9617

445

1.99

9832

1638

9399

299.

6tr

apz3

0.00

1451

867

1.99

9832

1638

9399

291.

5tr

apz

0.00

0740

450

1.99

9832

1638

9399

290.

75

R:un

vect

.28

s,ve

ct.

19µ

sco

mp:

78µ

s,15

µs

(=Re

njin

?)Rc

pp:

unve

ct.

3.5

µs

(inl

ine)

Pyth

on:

unve

ct.

119

µs,

vect

.39

µs

numb

a:un

vect

.0.

72µ

s,ve

ct.

54µ

s

MATL

AB:

unve

ct.

12µ

s,ve

ct.

35µ

sOc

tave

:un

vect

.20

00µ

s,ve

ct.

200

µs

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1213

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

How

tosp

eed

upfu

nctio

ns

Perfo

rman

cetip

s

Avoi

dgl

obal

varia

bles

(orm

ake

them

cons

t).

Forb

estp

erfo

rman

ce,u

seno

n-ve

ctor

ized

code

;de

vect

orize

arra

yas

signm

ents

,writ

eex

plici

telo

ops,

etc.

Brea

kfu

nctio

nsin

tom

ultip

lede

finiti

ons,

base

don

type

s.Ty

pest

abili

ty:A

void

chan

ging

the

type

ofa

varia

ble.

Acce

ssar

rays

inm

emor

yor

der,

i.e.,

along

colu

mns

.Av

oid

arra

yswi

thab

stra

ctty

pepa

ram

eter

s:Ve

ctor

{Rea

l}Pa

yat

tent

ion

tom

emor

yal

loca

tions

(see

mac

ro@t

ime)

:pr

eallo

cate

large

rdat

ast

ruct

ures

(arra

ys);

avoi

dth

ene

edto

copy

data

stru

ctur

es.

Appl

ype

rform

ance

anno

tatio

nsif

appr

opria

te(e

.g.,

@inb

ound

s)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1214

/32

Page 8: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Type

Syst

em

Julia

’snu

mer

icalt

ypes

Numb

er Real

Floa

ting

Poin

tBi

gFlo

atFl

oat6

4Fl

oat3

2Fl

oat1

6In

tege

rBi

gInt

Sign

ed Int1

28In

t64

[=In

t=]

Int3

2In

t16

Int8

Unsi

gned

Uint

128

Uint

64Ui

nt32

Uint

16Ui

nt8

Bool

Char

Rati

onal

Comp

lex

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1215

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Type

Syst

em

Oper

ator

over

loadi

ng

»me

thod

s(+)

#14

6me

thod

sfo

rge

neri

cfu

ncti

on+

+(x:

:Boo

l)at

bool

.jl:

34+(

x::B

ool,

y::B

ool)

atbo

ol.j

l:37

+(y:

:Flo

atin

gPoi

nt,x

::Bo

ol)

atbo

ol.j

l:47

...

»+(

s,t)

=s

*t

#wo

uld

bewr

ong

»++

(s,

t)=

s*

t#

isno

tpo

ssib

le»

⊕(s

,t)

=s

*t

#is

not

advi

sabl

e

»+(

s::S

trin

g,t:

:Str

ing)

=s

*t

»"1

23"

+".

.."

+"x

yz"

#=>

"123

...x

yz"

»+(

"123

",".

..",

"xyz

")»

+(["

123"

,".

..",

"xyz

"]..

.)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1216

/32

Page 9: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Type

Syst

em

User

-defi

ned

(or:

com

posit

e)ty

pes

immu

tabl

eGa

ussI

nt<:

Numb

er#

or:

type

Gaus

sInt

a::I

ntb:

:Int

#Ga

ussI

nt(n

::In

t,m:

:Int

)=

new(

n,m)

end

Gaus

sInt

(1,

1)#=

>Ga

ussI

nt(1

,1)

impo

rtBa

se.s

how,

Base

.nor

m,Ba

se.i

spri

mesh

ow(i

o::I

O,x:

:Gau

ssIn

t)=

show

(io,

comp

lex(

x.a,

x.b)

)Ga

ussI

nt(1

,1)

#=>

1+

1im

*(x:

:Gau

ssIn

t,y:

:Gau

ssIn

t)=

Gaus

sInt

(x.a

*y.a

-x.

b*y.

b,x.

a*y.

b+

x.b*

y.a)

;no

rm(x

::Ga

ussI

nt)

=x.

a^2

+x.

b^2;

ispr

ime(

x::G

auss

Int)

=is

prim

e(no

rm(x

));

#wr

ong!

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1217

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Opt

imiza

tion

Mod

eling

Optim

izatio

npa

ckag

esin

Julia

Opt

im–

BFGS

,CG,

simul

ated

anne

aling

GLP

K,C

bc,C

lp–

mixe

d-in

tege

rlin

earp

rogr

amm

ing

CPLE

X,G

urob

i,M

osek

–in

terfa

cing

com

mer

cials

yste

ms

Ipop

t–

inte

rface

toth

eIP

OPT

nonl

inea

rsol

ver(

COIN

-OR)

NLo

pt–

inte

rface

toth

eNL

optn

onlin

earo

ptim

izatio

nlib

rary

ECO

S,Co

nvex

–(d

iscip

lined

)con

vex

prog

ram

min

gso

lvers

JuM

P,M

athP

rogB

ase

–op

timiza

tion

mod

eling

langu

ages

Bla

ckB

oxO

ptim

,Jul

iaCM

AES

–gl

obal

optim

izatio

nLs

qFit,

Min

Find

er–

least

-squa

res,

allm

inim

a

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1218

/32

Page 10: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Opt

imiza

tion

Mod

eling

JuM

P–

Julia

forM

athe

mat

icalP

rogr

amm

ing

Dom

ain-sp

ecifi

cm

odeli

nglan

guag

efo

rmat

hem

atica

lpro

gram

min

g(i.

e.,op

timiza

tion)

Synt

axm

imics

natu

ralm

athe

mat

icale

xpre

ssio

nsPr

oblem

class

es:L

P,M

ILP,

SOCP

,non

linea

rpro

gram

min

gGe

neric

,sol

ver-i

ndep

ende

ntus

erin

terfa

ceSu

ppor

ted

solve

rs:Cb

c,Cl

p,CP

LEX,

ECO

S,GL

PK,G

urob

i,Ip

opt,

MO

SEK,

NLop

tSp

eed:

Prob

lemcr

eatio

nfa

ster

than

com

mer

cialm

odeli

ngto

ols

(AM

PL,G

AMS,

etc.)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1219

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Opt

imiza

tion

Mod

eling

Mod

eling

exam

ple:

Knap

sack

prob

lem

»p

=[9

2,57

,49

,68

,60

,43

,67

,84

,87

,72

];»

w=

[23,

31,

29,

44,

53,

38,

63,

85,

89,

82];

»ca

p=

165;

nite

ms=

10;

»us

ing

JuMP

,Cb

m=

Mode

l(so

lver

=Cbc

Solv

er()

@def

Var(

m,x[

1:ni

tems

],Bi

n)

»@s

etOb

ject

ive(

m,Ma

x,su

m{p[

i]*x

[i],

i=1:

nite

ms})

»@a

ddCo

nstr

aint

(m,

sum{

w[i]

*x[i

],i=

1:ni

tems

}<=

cap)

»st

atus

=so

lve(

m)»

getO

bjec

tive

Valu

e(m)

#16

idx

=[g

etVa

lue(

x[i]

)fo

ri

in1:

nite

ms]

[1,1

,1,0

,0,0

,0,0

,0,1

]#

1,2,

3,10

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1220

/32

Page 11: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Opt

imiza

tion

Mod

eling

Auto

mat

icDi

ffere

ntiat

ion(A

D)Au

tom

atic

diffe

rent

iatio

n“is

ase

toft

echn

ique

sto

num

erica

llyev

aluat

eth

ede

rivat

iveof

afu

nctio

nsp

ecifi

edby

aco

mpu

terp

rogr

am.”

Exam

ple:

lam

bert

Wis

anite

rativ

elyde

fined

func

tion

com

putin

gth

eLa

mbe

rtW

spec

ialfu

nctio

n,th

ere

verse

ofx

→x

·ex .

»la

mber

tW(1

.0)

#0.

5671

4329

0409

7838

Omeg

aco

nst.

»#

nume

rica

lde

riva

tive

at1.

usin

gDu

alNu

mber

lamb

ertW

(dua

l(1.

0,1.

0))

0.56

7143

2904

0978

38+

0.36

1896

2566

3488

92du

»#

exac

tde

riva

tive

»1.

0/

(1+

lamb

ertW

(1.0

)/

exp(

lamb

ertW

(1.0

))0.

3618

9625

6634

8892

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1221

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Stat

istics

with

Julia

Stat

istics

pack

ages

inJu

lia

Stat

sBas

e,Di

strib

utio

nsDi

stan

ces,

Clus

terin

gHy

poth

eses

Test

s,Ke

rnelD

ensit

yDi

men

siona

lityR

educ

tion

Data

Arra

ys,D

ataF

ram

esGL

M(D

oug

Bate

s)M

CMC

MLB

ase

NMF,

RegE

RMs

SVM

,Neu

ralN

ets

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1222

/32

Page 12: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Stat

istics

with

Julia

Data

Arra

ysan

dDa

taFr

ames

»us

ing

RDat

aset

s#

700+

Rda

tase

ts»

plan

ets

=da

tase

t("H

SAUR

","p

lane

ts")

»pl

anet

s[:M

ass]

»us

ing

Data

Arra

ys#

NAsu

ppor

usin

gDa

taFr

ames

»de

scri

be(p

lane

ts)

#su

mmar

y

The

Dat

aFra

mes

pack

age

supp

orts

func

tiona

lity

like

the

follo

wing

:jo

in,s

plit-

appl

y-co

mbi

neso

rting

,res

hapi

ngfa

ctor

s,m

odel

fram

es(fo

rmul

ae)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1223

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Calli

ngO

ther

Lang

uage

s

Callin

gC

and

Fortr

an

Shar

edlib

rary

spec

fun.

soha

sbee

nge

nera

ted

with

the

Rco

mm

and

“RCM

DSH

LIB

spec

fun.

f”

»x

=0.

y=

ccal

l((:

gamm

a_,"

./sp

ecfu

n"),

#(f

unct

ion,

libr

ary)

Floa

t64,

#ty

peof

retu

rnva

lue

(Ptr

{Flo

at64

},),

#in

put

type

sas

tupl

e&x

);#

inpu

t(s)

»y

1.77

2453

8509

0551

6#

sqrt

(pi)

But:

The

Julia

Core

team

inte

ndst

om

ake

poss

ible

the

com

pilat

ion

ofJu

liafu

nctio

nsan

dpa

ckag

esin

tosh

ared

libra

ries!

BUT:

... Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1224

/32

Page 13: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Calli

ngO

ther

Lang

uage

s

Rca

lling

Julia

?

“Jul

iaha

sani

cean

dsim

ple

Cin

terfa

ce.S

oth

atge

tsus

som

ethi

nglik

e.C

().

Buta

srec

ently

disc

usse

don

r-dev

el,yo

ure

ally

dono

twan

t.C(

),in

mos

tca

sesy

oura

ther

want

.Call

()in

orde

rto

pass

actu

alSE

XPva

riabl

esre

pres

entin

gre

alR

objec

ts.S

orig

htno

wIs

eelit

tlesc

ope

forJ

ulia

from

Rbe

caus

eof

this

limita

tion.

May

bean

indi

rect

inte

rface

usin

gtc

p/ip

toRs

erve

coul

dbe

afir

stst

art

befo

reJu

liam

atur

esa

little

and

wege

tapr

oper

C++

inte

rface

.[...

]An

dth

een

dof

the

day,

som

epa

tienc

em

aybe

need

ed.I

star

ted

tolo

okat

Rar

ound

1996

or19

97wh

enFr

itzLe

isch

mad

eth

efir

stan

noun

cem

ents

onth

eco

mp.

os.li

nux.

anno

unce

news

grou

p.An

dR

had

rath

erlim

ited

facil

ities

then

(but

the

full

prom

iseof

the

Sla

ngua

ge,o

fcou

rse,

sowe

knew

weha

da

win

ner)

.[...

]Ju

liam

aywe

llge

tthe

re.B

utfo

rnow

Isus

pect

man

yof

uswi

llge

twor

kdo

nein

R,an

dha

veju

sta

few

curio

usgl

imps

esat

Julia

.”Di

rkEd

delb

ütte

l,St

acko

verfl

ow,A

pril

1,20

12H

ans

WBo

rche

rsKö

lnR

User

Grou

pM

eetu

p20

14-1

2-12

25/

32In

trod

uctio

nto

Julia

forR

User

sCa

lling

Oth

erLa

ngua

ges

Para

lleliz

ation

“Jul

iapr

ovid

esa

mul

tipro

cess

ing

envir

onm

entb

ased

onm

essa

gepa

ssin

gto

allow

prog

ram

sto

run

onm

ultip

le[p

roce

ssor

s]in

sepa

rate

mem

ory

dom

ainsa

tonc

e.”

$ju

lia

-p2

...

»r

=re

mote

call

(1,

rand

,2,

2)»

fetc

h(r)

»@s

pawn

rand

(2,

2)»

s=

@spa

wnra

nd(2

,2)

»@e

very

wher

ef(

x)=

x*

exp(

x)»

r1=

remo

teca

ll_f

etch

(1,

f,1)

»r2

=re

mote

call

_fet

ch(2

,f,

2)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1226

/32

Page 14: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Plot

ting

and

Pyth

on

Gram

mar

ofGr

aphi

csin

Julia

»us

ing

Gadf

ly»

xs=

lins

pace

(-0.

3,5.

0);

ys=

map(

lamb

ertW

,xs

);»

fig

=pl

ot(x

=xs,

y=ys

,Ge

om.l

ine,

Guid

e.ti

tle=

"Lam

bert

Wfu

ncti

on")

»dr

aw(P

DF("

gadf

ly.p

df",

4inc

h,2i

nch)

,fi

g)

x-1

01

23

45

y

-0.5

0.0

0.5

1.0

1.5

Lam

bert

W f

unct

ion

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1227

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Plot

ting

and

Pyth

on

Callin

gPy

thon

Exam

ple:

Func

tion

inte

rpol

atio

n,sy

mbo

licin

tegr

atio

n

»us

ing

PyCa

ll»

xs=

[1.0

:10]

;ys

=sq

rt(x

s);

»@p

yimp

ort

scip

y.in

terp

olat

eas

spi

»fp

y=

spi.

inte

rp1d

(xs,

ys,

kind

="cu

bic"

pyca

ll(f

py,

Floa

t64,

pi)

#1.

7723

4955

2838

2518

»us

ing

SymP

x,y,

z=

Sym(

"xy

z")

»li

mit(

sin(

x)/x

,x,

1)#

z=

inte

grat

e(si

n(x)

/x,

x,1,

Inf)

-Si(

1)+

1.57

0796

3267

949

»fl

oat(

z)0.

6247

1325

6427

7136

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1228

/32

Page 15: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Refe

renc

esan

dO

utlo

ok

Web

Reso

urce

s

Julia

hom

epa

ge:j

ulial

ang.

org

Sour

ceCo

de:g

ithub

.com

/Jul

iaLan

g/ju

liaPe

rsona

lPac

kage

Arch

ives:

/jul

iarele

ases

[0.3

],/j

ulian

ight

lies[

0.4]

Avai

labl

epa

ckag

es:h

ttp:/

/iain

nz.g

ithub

.io/p

acka

ges.j

ulial

ang.

org/

Julia

Man

ual:

http

://d

ocs.j

ulial

ang.

org/

en/r

eleas

e-0.

3/m

anua

l/M

ailin

gLi

st:

http

s://g

roup

s.goo

gle.c

om/f

orum

/?fro

mgr

oups

=#

!foru

m/j

ulia-

user

sJu

liaB

logr

oll:

http

://w

ww.ju

liabl

ogge

rs.co

m/

The

Julia

Man

uali

saqu

itere

ason

able

intro

duct

ion

toth

eJu

lialan

guag

e.

David

Sand

ers:

Julia

tuto

rial,

SciP

y20

14St

even

John

son:

Keyn

ote

talk,

Euro

SciP

y20

14

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1229

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Refe

renc

esan

dO

utlo

ok

Edito

rsfo

rJul

iade

velop

men

t

Julia

Stud

io[o

utda

ted,

com

m.?

]Li

ght

Tabl

e(w

/Je

wel/

Juno

plug

in)

IPyt

hon

note

book

(w/

IJul

ia)se

eth

eJu

pyte

rpr

ojec

tEd

itors

with

synt

axhi

ghlig

htin

g(a

ndau

to-c

ompl

etio

n):

Subl

ime

Text

3(w

/Su

blim

e-Ju

lia)[

Linu

x]Te

xtM

ate

[Mac

],ge

dito

rKat

e[L

inux

]No

tepa

d++

[Win

dows

]Ec

lipse

(w/

LiCl

ipse

)Em

acs(

w/ju

lia-m

ode.e

l)vim

(w/

julia

-vim

)

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1230

/32

Page 16: Introduction to Julia for R Users - Meetupfiles.meetup.com/3576292/julia-handout2.pdf · Introduction to Julia for R Users Overview The LLVM compiler infrastructure project “The

Intr

oduc

tion

toJu

liafo

rRUs

ers

Refe

renc

esan

dO

utlo

ok

Julia

Spec

ialIn

tere

stGr

oups

Spec

ialIn

tere

stGr

oups

(SIG

s)in

Julia

have

afu

nctio

nsim

ilart

oth

e‘T

ask

View

s’in

R,bu

tthe

yals

okin

dof

orga

nize

the

task

area

.Ju

liaO

pt–

mat

hem

atica

lopt

imiza

tion

Julia

Stat

–st

atist

icsan

dm

achi

nelea

rnin

gJu

liaQ

uant

–qu

antit

ative

finan

ceJu

liaD

iff–

diffe

rent

iatio

nto

ols

Julia

DB

–da

taba

sein

tegr

atio

n

BioJ

ulia,

Julia

Astro

,Jul

iaQua

ntum

Julia

Spar

se,J

uliaG

PU,J

uliaW

eb

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1231

/32

Intr

oduc

tion

toJu

liafo

rRUs

ers

Refe

renc

esan

dO

utlo

ok

Conc

lusio

ns/

Ques

tions

1W

illJu

liasu

rvive

and

beco

me

am

ayor

play

er?

2..

.3 4 5 6 7 8 9 10

Han

sW

Borc

hers

Köln

RUs

erGr

oup

Mee

tup

2014

-12-

1232

/32