Indro Montanelli – Aspra critica a partiti e magistrati

July 21, 2011 Leave a comment

Check out this video on YouTube:

Sent from a mobile device.

Categories: Uncategorized

Prova

May 30, 2011 Leave a comment

Book to check out

September 2, 2010 Leave a comment

These two books seem interesting.

R in a Nutshell
Joseph Adler
O’Reilly, 2010
ISBN: 978-0-596-80170-0

Graphics for Statistics and Data Analysis with R
Kevin J. Keen
Chapman and Hall/CRC, 2010
ISBN: 9781584880875

Only thing is that R cannot really fit a nutshell!

Categories: R

Now, I am happy

July 19, 2010 Leave a comment

Many sources [here and here] have been discussing the performance benefit optimized BLAS/Lapack and I wanted to try directly.

I wanted to give it a try as I am using R for some heavy duty matrix calculations.

I downloaded the MKL Intel Blas/Lapack libraries and installed it. This went very smooth.

I then tried to follow Michael’s suggestions to compile R 2.11.1 (well, it’s suggestions are about 2.10). It compiled fine, but I could not get R to use more than one core (no matter how hard I tried!). To get a multithreaded version of R I had to disable compilation of R as a shared library. It’s probably better not to compile R as a shared library anyway (see here for details).

This is my configuration (including compiler flags and commands)

$ gcc -v
gcc version 4.4.0 20090514 (Red Hat 4.4.0-6) (GCC)
export FFLAGS="-march=core2 -O3"
export CFLAGS="-march=core2 -O3"
export CXXFLAGS="-march=core2 -O3"
export FCFLAGS="-march=core2 -O3"
MKL_LIB_PATH=/opt/intel/mkl/10.2.5.035/lib/em64t
export LD_LIBRARY_PATH=$MKL_LIB_PATH
export LDFLAGS="-L${MKL_LIB_PATH},-Bdirect,--hash-style=both,-Wl,-O1"
MKL="-L${MKL_LIB_PATH} -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_lapack -lmkl_core -liomp5 -lpthread"
./configure --with-blas="$MKL" --with-lapack
make
make check

Benchmark

The simple R-benchmark-25.R test script is a quick-running survey of general R performance. The Community-developed test consists of three sets of small benchmarks, referred to in the script as Matrix Calculation, Matrix Functions, and Program Control.

See Simon Urbanek’s notes about benchmarking and a reference benchmark.

Below, the results of my new R with MKL:


R Benchmark 2.5
===============
Number of times each test is run__________________________: 3

I. Matrix calculation
---------------------
Creation, transp., deformation of a 2500x2500 matrix (sec): 0.517999999999953
2400x2400 normal distributed random matrix ^1000____ (sec): 0.68966666666673
Sorting of 7,000,000 random values__________________ (sec): 1.0783333333333
2800x2800 cross-product matrix (b = a' * a)_________ (sec): 0.605999999999995
Linear regr. over a 3000x3000 matrix (c = a \ b')___ (sec): 0.260333333333392
--------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 0.600455102863175

II. Matrix functions
--------------------
FFT over 2,400,000 random values____________________ (sec): 0.541333333333303
Eigenvalues of a 640x640 random matrix______________ (sec): 0.892333333333378
Determinant of a 2500x2500 random matrix____________ (sec): 0.28133333333335
Cholesky decomposition of a 3000x3000 matrix________ (sec): 0.231333333333358
Inverse of a 1600x1600 random matrix________________ (sec): 0.332666666666645
--------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 0.370025581291834

III. Programmation
------------------
3,500,000 Fibonacci numbers calculation (vector calc)(sec): 1.01633333333333
Creation of a 3000x3000 Hilbert matrix (matrix calc) (sec): 0.431666666666653
Grand common divisors of 400,000 pairs (recursion)__ (sec): 1.68333333333336
Creation of a 500x500 Toeplitz matrix (loops)_______ (sec): 0.709333333333348
Escoufier's method on a 45x45 matrix (mixed)________ (sec): 0.58400000000006
--------------------------------------------
Trimmed geom. mean (2 extremes eliminated): 0.749491068589986

Total time for all 15 tests_________________________ (sec): 9.85600000000015
Overall mean (sum of I, II and III trimmed means/3)_ (sec): 0.55016494784761
--- End of test ---

Categories: R Tags:

R Random Number Generator

July 4, 2010 Leave a comment

I was programming a particle filter routine that makes heavy use of rnorm. When I completed the coding effort, I was not satisfied at all with the speed of the computation.

Speed is paramount here as the output of my routine is a likelihood function that is then passed to a Metropolis-Hasting mcmc.

With my surprise, the biggest improvement came from changing the normal random number  from “Inversion” (the default) to “Kinderman-Ramage”.

RNGkind(normal.kind = 'Kinderman-Ramage')

I am getting a speed up of about 25%: not bad at all. But then I am wondering why “Kinderman-Ramage” is not the default normal RNG. The “Kenderman-Ramage” algorithm used to be buggy in R, but it is fixed in recent implementations (see this article).

This is an example of the speed up on my machine:

> RNGkind(normal.kind = 'Inversion')
> system.time(rnorm(1000000))
user system elapsed
0.125 0.006 0.131

> RNGkind(normal.kind = 'Kinderman-Ramage')
> system.time(rnorm(1000000))
user system elapsed
0.06 0.00 0.06

Categories: R

Eclipse for R

May 11, 2010 Leave a comment

I found this interesting post that discusses using Eclipse, R, and Sweave.

I probably should try Eclipse one day.

Categories: R

Strip JSTOR first page

September 13, 2008 Leave a comment

This simple apple script will strip the first page of a jstor document. It requires Adobe Acrobat to be installed on your machine to run. Copy it in the script editor, save it as an application, and then add it to the Finder as a button.

on run
tell application "Finder"
if selection is {} then
quit
else
set finderSelection to selection as alias list
end if
end tell
deletepage(finderSelection)
end run


on open (theList)
deletepage(theList)
end open


on deletepage(listOfAliases)
repeat with eachitem in listOfAliases
tell application "Adobe Acrobat Professional"
activate
open eachitem
set Doc_Ref to the front document
delete first page
close Doc_Ref saving yes
end tell
end repeat
end deletepage

Categories: Apple Script

TextMate Emacs-like indentation (for R files)

November 11, 2007 8 comments

If you use OS X, TextMate is hands down the best editor available for this platform. It integrate perfectly with the OS X environment. While the Project Window is probably the greatest thing about TextMate for the everyday user, its extensibility is what makes it a wonderful companion in editing.

The biggest complain I have about TextMate is that it does not handle indentation very well. I write a lot of R code and I am used to the indentation provided by ess (Emacs Speak Statistics). Frustrated, I decided to do something about it. After looking for option I realized that I could combine the feature of Emacs with those of TextMate to improve indentation. In practice I was able to use emacs (with ess) as beckend for the indentation. If you want to try follow the following steps:

1. Install ess (Emacs Speak Statistics) from http://ess.r-project.or in /usr/share/emacs/site-lisp;

2. In TextMate go to Bundles|Bundle Editor|Show Bundle Editor…

3. Create a new command, say Tidy

4. Add the following script:

#!/usr/bin/perl
my $in;
my $now = "tidyRcode";
my $file = "/tmp/tmptx_${now}.R";
my $eb=$ENV{'TM_BUNDLE_SUPPORT'};
open FILE, ">$file" or die "unable to open $file $!";
while () {
print FILE $_;
}
close(FILE);
`emacs -batch --eval "(require 'ess)" ${file} --eval '(indent-region (point-min) (point-max) nil)' -f ess-fix-miscellaneous -f save-buffer &> /dev/null`;
my $in = `cat ${file}`;
print $in;

5. Select the following options:

  • Input: Selected Text or Document;
  • Output: Replace Selected Text;
  • Key Equivalent: Shift+Cmd+H;
  • Scope Selector: source.r

You can see the picture below with my setting

TextMate Emacs-like indentation (for R files)

Now you are ready to go. While you are editing R code, simply select and press Shift+Cmd+H and you will see your code….the ess way.

UPDATE: The perl code does not work on Leopard (at least my Leopard with Emacs 22.1.1 + Textmate 1.5.9).

This version in Ruby works:

#!/usr/bin/ruby
require “ftools”
# Handle selection (less useful, probably) or full file.
tmp_file = “/tmp/textmate-tidy.#{$}.R”
selected = ENV['TM_SELECTED_TEXT'] || ”
if (selected.empty?)
raise(“No selected text or file.”) if (ENV['TM_FILEPATH'].empty?)
File.copy(ENV['TM_FILEPATH'], tmp_file)
else
File.open(tmp_file, ‘w’) { |fout| fout.print selected }
end
user = ENV['USER'] ||”
user_opt = “-u #{user}” unless (user.empty?)
cmd = “emacs -u \”#{user}\” -batch \”#{tmp_file}\” -eval \”(require ‘ess)\” -eval \”(indent-region (point-min) (point-max) nil)\” -f ess-fix-miscellaneous -f save-buffer &> /dev/null”
system(cmd) || raise(“Failed to indent with Emacs.”)
system(“cat #{tmp_file}”)
File.delete(tmp_file)
Categories: R, TextMate
Follow

Get every new post delivered to your Inbox.