Posts

Improve R's Performance using JuliaCall

Image
Improve R's Performance using JuliaCall Improve R's Performance using JuliaCall with Mandel Set Example What is Mandelbrot Set? Mandelbrot set is the set of complex numbers c for which the sequence {0,  f c (0), f c ( f c (0)), …,  f c ( n ) (0),…} remains bounded in absolute value where function f c ( z )= z 2  +  c . For more detailed introduction, you could go to Wikipedia page for Mandelbrot set . The calculation for Mandelbrot set involves heavy computation, and here we will use JuliaCall to speed up the computation by rewriting R function in Julia, and we will also see some easy and useful tips in writing higher performance Julia code. In this example, we will see that JuliaCall actually brings more than 100 times speedup of the calculation. Pure R Implementation The R implementation for the calculation of Mandelbrot set is quite straightforward. Note that it could be proved that if absolute value of one item in the sequence is greater than 2,

Convex Optimization in R by convexjlr

Image
The aim of package convexjlr is to provide optimization results rapidly and reliably in R once you formulate your problem as a convex problem. Having this in mind, we write this vignette in a problem-oriented style. The vignette will walk you through several examples using package convexjlr : Lasso; Logistic regression; Support Vector Machine (SVM); Smallest circle covering multiple points. Although these problems already have mature solutions, the purpose here is to show the wide application of convex optimization and how you can use convexjlr to deal with them easily and extendably. Some of the examples here are of statistics nature (like Lasso and logistic regression), and some of the examples here are of machine-learning nature (like SVM), they may be appealing to readers with certain backgrounds. If you don’t know either of this, don’t be afraid, the smallest circle problem requires no certain background knowledge. We hope you can get ideas for how to use convexjlr

Bring the power of Julia into R through XRJulia package (2)

Introduction to Julia and XRJulia package by example Julia is a high-performance language, it is easy to learn if you are already familiar with R . You can find introduction and many useful links for Julia from https://julialang.org/ . XRJulia is a package for R by John M. Chambers. It enables us to access to all the functionality provided by Julia in R . You can get it from CRAN or the latest version from https://github.com/johnmchambers/XRJulia . The purpose of this article is to give a brief introduction to Julia and XRJulia with some small examples. After installing XRJulia package, let us type the following code into R : library("XRJulia") ev <- RJulia() ev$Eval("1+1") ## 2 ev$Command("a = 1+1") ev$Eval("a") ## 2 The first line is to load the XRJulia library, and the second line is to start a Julia session with the name ev (which is the abbreviation for evaluator). And then you can evaluate some expression using ev$Eval

Bring the power of Julia into R through XRJulia package

R is the software for statistics. It is easy to use and have great flexibility. The most important of all, it has a lot of packages which greatly expand the power of R. But R sometimes suffer from low performance issues. Julia is a new programming language whose main goal is to let high performance scientific computing becomes easy. In this series of blogs, I will talk about how to use XRJulia package to bring the high performance of Julia into the great ecosystem of R, which combines the best of the two worlds. I will first talk about some general recipes to speed up R code, and then talk about why choose Julia and XRJulia. And the introduction to R and XRJulia will be in the second blog of this series. General Advice on speeding up your R script When you have some performance issue with your R script, there are several things you can do: Profile your code, identify the bottleneck for your script, and then try to alleviate it. For example, if the bottleneck of your code is a dee