Re: converting a R code to fortran
- From: "e p chandler" <epc8@xxxxxxxx>
- Date: 26 Feb 2007 22:08:44 -0800
On Feb 26, 10:44 am, Michel Olagnon <molag...@xxxxxxxxxxxxxxxxx>
wrote:
fortee wrote:
I am now trying to convert a R code to fortran. I did what I can do my
best but a running time of my code is forever with n=5000 and r=20000.
The following R code comes fromhttp://www.mcs.vuw.ac.nz/~ray/Brownian/algorithms.shtml
I need to iteration the following code 20, 000 times and get a
Kolmogorov-Smirnov(KS) statistics.
It is said on the web site: "With R though there is a distinct value to be
gained in performing computations in a vectorised (or even matrix) form, rather
than one value at a time."
I believe that the opposite is very often true for Fortran. You should try
to do as much as you can with each scalar value once you have fetched it
from memory to the CPU registers and before you store it again to memory,
and you should minimize memory use.
Look at the program that I posted on 2007-02-22. You should start from that
one. I tried to add comments to the inner loop now that I know what it does...
!
ks = 0.0
do j1 = 1, N+1 ! for each of the vertical lines s = cst
xd = 0.0 ! xd = sum_i I (x1_i < x1_j1
! & x2_i < x2_j2)
x1j = x1e(j1)
do m2 = 1, N+1
j2 = j2e (m2) ! take points in increasing t order
ks = max(ks, abs(xd-ns*x1j*x2e(j2))) ! check for supremum
if (x1e(j2)< x1j) then
xd = xd + 1.0 ! update xd for the rest of the loop, when
! point for the current t value is to the left
! of the current vertical line s = x1j
endif
enddo
enddo
!
ks= ks / sqrt (ns)
Here's my idea on solving this problem, which I suspect must be
O(N*N). Ignore the effect of duplicate values in X1 and X2. Compute
the ranks of the original entries in X1 and X2. Given the ranks,
ignore the numerical values. Consider the points in rank space, say on
a chess board with (1,1) at lower left and (N+1,N+1) at upper right.
Put the points (chess pieces) (x1(i),x2(i)) on the board. Starting at
the lower left work to the upper right either by traversing one file
at a time or by considering the boundary of an expanding square.
Compute the count of points to the left and below from those in
adjacent "kitty corner" cells. The only way a count rises is if you go
both up and right from a square which contains a piece.
Look at this like a chess board
.
- Follow-Ups:
- Re: converting a R code to fortran
- From: Michel Olagnon
- Re: converting a R code to fortran
- References:
- converting a R code to fortran
- From: fortee
- Re: converting a R code to fortran
- From: Michel Olagnon
- converting a R code to fortran
- Prev by Date: Re: integer*8 speed vs integer*4 speed
- Next by Date: Re: integer*8 speed vs integer*4 speed
- Previous by thread: Re: converting a R code to fortran
- Next by thread: Re: converting a R code to fortran
- Index(es):
Relevant Pages
|
|