[R] R in Industry
Ravi Varadhan
rvaradhan at jhmi.edu
Thu Feb 8 20:39:41 CET 2007
Here is a function to create a Toeplitz matrix of any size, and an example
of a 220 x 220 toeplitz matrix, which was created in almost no time:
################################################################
# Given a vector x, forms a Toeplitz matrix
#
toeplitz <- function (x, sym=T) {
if (!is.vector(x))
stop("x is not a vector")
n <- length(x)
if (!sym) {
if (!n%%2) stop("length of vector must be odd")
n2 <- (n+1)/2
A <- matrix(NA, n2, n2)
mat <- matrix(x[col(A) - row(A) + n2], n2, n2)
}
else {
A <- matrix(NA, n, n)
mat <- matrix(x[abs(col(A) - row(A)) + 1], n, n)
}
mat
}
###########################################
> system.time(top.mat <- toeplitz(runif(220)))
[1] 0.00 0.01 0.02 NA NA
Hope this is fast enough!
Best,
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan at jhmi.edu
Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
----------------------------------------------------------------------------
--------
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Stefan Grosse
Sent: Thursday, February 08, 2007 12:09 PM
To: Albrecht, Dr. Stefan (AZ Private Equity Partner)
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] R in Industry
I just ran on my Windows PC the benchmark from
http://www.sciviews.org/benchmark/index.html which is pretty old now.
Thats probably the reason for the errors which I did not correct. As
you see R has some advantages but Matlab has also some advantages.
However the differences are not to big. There is only one big
difference which indeed includes loops (Creation of a 220x220 Toeplitz
matrix) where Matlab is much faster. But maybe a simple change in the
programmation can change that...
Has someone in the list an updated script?
Stefan Grosse
The benchmarks:
R 2.4.1
R Benchmark 2.3
===============
I. Matrix calculation
---------------------
Creation, transp., deformation of a 1500x1500 matrix (sec):
0.863333333333335
800x800 normal distributed random matrix ^1000______ (sec):
0.136666666666666
Sorting of 2,000,000 random values__________________ (sec):
0.616666666666665
700x700 cross-product matrix (b = a' * a)___________ (sec):
0.559999999999997
Linear regression over a 600x600 matrix (c = a \ b') (sec): 0 #ERROR
II. Matrix functions
--------------------
FFT over 800,000 random values______________________ (sec):
0.559999999999997
Eigenvalues of a 320x320 random matrix______________ (sec):
0.493333333333335
Determinant of a 650x650 random matrix______________ (sec):
0.276666666666666
Cholesky decomposition of a 900x900 matrix__________ (sec): 0 #ERROR
Inverse of a 400x400 random matrix__________________ (sec): 0 #ERROR
III. Programmation
------------------
750,000 Fibonacci numbers calculation (vector calc)_ (sec):
0.466666666666669
Creation of a 2250x2250 Hilbert matrix (matrix calc) (sec):
1.01666666666667
Grand common divisors of 70,000 pairs (recursion)___ (sec):
0.396666666666671
Creation of a 220x220 Toeplitz matrix (loops)_______ (sec):
0.553333333333332
Escoufier's method on a 37x37 matrix (mixed)________ (sec):
2.66999999999999
--- End of test ---
Matlab 7.0.4
Matlab Benchmark 2
==================
Number of times each test is run__________________________: 3
I. Matrix calculation
---------------------
Creation, transp., deformation of a 1500x1500 matrix (sec): 0.29047
800x800 normal distributed random matrix ^1000______ (sec): 0.42967
Sorting of 2,000,000 random values__________________ (sec): 0.71432
700x700 cross-product matrix (b = a' * a)___________ (sec): 0.14748
Linear regression over a 600x600 matrix (c = a \ b') (sec): 0.12831
------------------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 0.26403
II. Matrix functions
--------------------
FFT over 800,000 random values______________________ (sec): 0.24591
Eigenvalues of a 320x320 random matrix______________ (sec): 0.38507
Determinant of a 650x650 random matrix______________ (sec): 0.091612
Cholesky decomposition of a 900x900 matrix__________ (sec): 0.11059
Inverse of a 400x400 random matrix__________________ (sec): 0.069414
------------------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 0.13556
III. Programmation
------------------
750,000 Fibonacci numbers calculation (vector calc)_ (sec): 1.2386
Creation of a 2250x2250 Hilbert matrix (matrix calc) (sec): 3.0541
Grand common divisors of 70,000 pairs (recursion)___ (sec): 1.7637
Creation of a 220x220 Toeplitz matrix (loops)_______ (sec): 0.0045972
Escoufier's method on a 37x37 matrix (mixed)________ (sec): 0.50481
------------------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 1.0331
Total time for all 15 tests_________________________ (sec): 9.1786
Overall mean (sum of I, II and III trimmed means/3)_ (sec): 0.33316
--- End of test ---
--
-------------------------------------------
lic. oec. Stefan Grosse
University of Erfurt
Microeconomics
Nordhäuser Str. 63
99089 Erfurt
Germany
phone +49-361 - 737 45 23
fax +49-361 - 737 45 29
mobile +49-1609- 760 33 01
web http://www.uni-erfurt.de/mikrooekonomie
mail stefan.grosse at uni-erfurt.de
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list