Re: [R] dist like function but where you can configure the method

2014-05-17 Thread David L Carlson
Rowlingson Subject: Re: [R] dist like function but where you can configure the method Ouch, First : my question was not how to implement dist but if there is a more generic dist function than stats:dist. Secondly: ks.test is ment as a placeholder (see the comment in the code I did send) for any

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Jari Oksanen
Witold E Wolski wewolski at gmail.com writes: Looking for an fast dist implementation where I could pass my own dist function to the method parameter i.e. mydistfun = function(x,y){ return(ks.test(x,y)$p.value) #some mystique implementation } wow = dist(data,method=mydistfun)

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Witold E Wolski
Dear Jari, Thanks for your reply... The overhead would be 2 for loops for(i in 1:dim(x)[2]) for(j in i:dim(x)[2]) isn't it? Or are you seeing a different way to implement it? A for loop is pretty expensive in R. Therefore I am looking for an implementation similar to apply or lapply were the

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Barry Rowlingson
On Fri, May 16, 2014 at 4:46 PM, Witold E Wolski wewol...@gmail.com wrote: Dear Jari, Thanks for your reply... The overhead would be 2 for loops for(i in 1:dim(x)[2]) for(j in i:dim(x)[2]) isn't it? Or are you seeing a different way to implement it? A for loop is pretty expensive in R.

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Bert Gunter
Yes, ... and further apply-type functions still have to loop at the interpreter level, and generally take about the same time as their translation to for loops (with suitable caveats for this kind of vague assertion). Their chief advantage is readability and adherence to R's functional paradigm

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Jari Oksanen
I did not regard the loops as the overhead but a part of the process. Overhead is setting attributes. The loop is not so very expensive compared to ks.test(). You can always replace the loop with an apply on the vector of indices, but about the only way to speed up calculations is to use

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Rui Barradas
Hello, The compiler package is good at speeding up for loops but in this case the gain is neglectable. The ks test is the real time problem. library(compiler) f1 - function(n){ for(i in 1:100){ for(i in 1:100){ ks.test(runif(100),runif(100))

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Witold E Wolski
Ouch, First : my question was not how to implement dist but if there is a more generic dist function than stats:dist. Secondly: ks.test is ment as a placeholder (see the comment in the code I did send) for any other function taking two vector arguments. Third: I do subscribe to the idea that a

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread William Dunlap
system.time(apply(t(1:(n*n)),1,myfunc)) User System verstrichen 0.190.000.19 That calls 'myfunc' exactly once: system.time(apply(t(1:(3*3)), 1, print)) [1] 1 2 3 4 5 6 7 8 9 user system elapsed 0 0 0 Bill Dunlap TIBCO Software

Re: [R] dist like function but where you can configure the method

2014-05-16 Thread Bert Gunter
If the apply() call is not empty, its contents must of course be interpreted. That's where the time goes. system.time(for(i in 1:1e6)rnorm(1)) user system elapsed 5.250.005.29 system.time(lapply(1:1e6,rnorm,n=1)) user system elapsed 9.640.019.72

[R] dist like function but where you can configure the method

2014-05-15 Thread Witold E Wolski
Looking for an fast dist implementation where I could pass my own dist function to the method parameter i.e. mydistfun = function(x,y){ return(ks.test(x,y)$p.value) #some mystique implementation } wow = dist(data,method=mydistfun) thanks -- Witold Eryk Wolski