Displaying 20 results from an estimated 20000 matches similar to: "newbie:looking for an efficient way to compute distance vector"
2008 Jan 31
3
fastest way to compute the squared Euclidean distance between two vectors in R
I have a program which needs to compute squared Euclidean distance
between two vectors million of times, which the Rprof shows is the
bottleneck. I wondered if there is any faster way than my own simple
function
distance2 = function(x1, x2)
{
temp = x1-x2
sum(temp*temp)
}
I have searched the R-help archives and can not find anything except
when the arguments are matrices. Thanks for any
2009 Jun 26
1
50993 point distance matrix, too big to as.matrix, looking for another way to calculate point-level summary
Hello, Im working on a 50933 point count bird abundance dataset. I've
succeeded in calculating a distance matrix for this entire set, but I don't
have sufficient memory to convert this to a matrix, as below...
abun.dist <- dist(abun.mat[1:50993,1:235)
test <- rowMeans(as.matrix(abun.dist))
Error in matrix(0, size, size) : too many elements specified
ive been able to run a hclust()
2011 Aug 24
3
Efficient way to Calculate the squared distances for a set of vectors to a fixed vector
I am pretty new to R. So this may be an easy question for most of you.
?
I would like to calculate the squared distances of a large set (let's say 20000) of vectors (let's say dimension of 5) to a fixed vector.
?
Say I have a data frame MY_VECTORS with 20000 rows and 5 columns, and one 5x1 vector y. I would like to efficiently calculate the squared distances?between each of the 20000
2007 Nov 16
1
Efficient way to compute power of a sparse matrix
Dear all,
I would like to compute power of a square non symmetric matrix. This is
a part of a simulation study. Matrices are quite large (e.g., 900 by
900), and contains many 0 (more than 99 %). I have try the function
mtx.exp of the Biodem package:
library(Biodem)
m <- matrix(0, 900, 900)
i <- sample(1:900, 3000, replace = T)
j <- sample(1:900, 3000, replace = T)
for(x in 1:3000)
2012 Aug 06
1
more efficient way to parallel
Dear All,
Suppose I have a program as below: Outside is a loop for simulation (with
random generated data), inside there are several sapply()'s (10~100) over
the data and something else, but these sapply's have to be sequential. And
each sapply do not involve very intensive calculation (a few seconds only).
So the outside loop takes minutes to finish one iteration.
I guess the better way
2012 Jun 16
1
Efficient distance calculation on big matrix
Hi All,
I'm working on analyzing a large data set, lets asume that
dim(Data)=c(1000,8700). I want to calculate the canberra distance
between the columns of this matrix, and using a toy example ('test' is
a matrix filled with random numbers 0-1):
> system.time(d<-as.matrix(dist(t(test), method = "canberra", diag = FALSE, upper = FALSE, p = 2)))
user system
2012 Jun 20
0
compute similarity distance
Hi,
I just started to use R for my Phd. I have to write a Formula by witch, given two matrices of vectors (electrostatic potential map) I shall calculate the similarity between them.
Could you please tell me if I'am doing it right. The complecte formula is attached to an image file
the script
#!/usr/bin/env Rscript
options(max.print=2000000)
x<-read.table("a")
2008 Mar 27
1
A faster way to compute finite-difference gradient of a scalar function of a large number of variables
Hi All,
I would like to compute the simple finite-difference approximation to the
gradient of a scalar function of a large number of variables (on the order
of 1000). Although a one-time computation using the following function
grad() is fast and simple enough, the overhead for repeated evaluation of
gradient in iterative schemes is quite significant. I was wondering whether
there are
2008 Jan 07
2
Efficient way to substract all entries in two vectors from each other
Hi all,
I'm to inexperienced to come up with the matrix solution elusively appearing
on the horizon for the following problem and would appreciate if you could
give me a nudge ...
I have two vectors a, and b and need to find the closest match for each
value of a in b.
How to do that efficiently?
Thanks, Joh
2012 Aug 19
1
moving distance between two sets of data
On the surface this seems pretty simple, but I flummoxed. I have two sets of numbers they bounce around zero, positive one and negative one. They have a relationship between them, where one diverges away from the other. I want create a second set of numbers that tracks that divergence.
#Lets make some data like mine, kinda
Firstset <- runif(100, min = -1 , max =1)
Secondset <- runif(100,
2007 Dec 20
3
Efficient way to find consecutive integers in vector?
Hi all,
Does anybody have a magic trick handy to isolate directly consecutive
integers from something like this:
c(1,2,3,4,7,8,9,10,12,13)
The result should be, that groups 1-4, 7-10 and 12-13 are consecutive
integers ...
Thanks for any hints, Joh
2009 Sep 28
6
What is the most efficient way to split a table into 2 groups?
I have the following:
@lot = Lot.find(params[:id])
part_nums = Part.all(:conditions => ["id <> ?", @lot.part.id])
I guess I should mention that
Lot :belongs_to => :part
I was looking at the log following the execution of these two
statements and I saw something like this:
Lot Load (0.4ms) SELECT * FROM "lots" WHERE ("lots"."id" = 13)
Part
2010 Jun 02
1
compute the associate vector of distances between leaves in a binary non-rooted tree
Hello.
I'd like to compute the associate vector of distances between leaves in a binary non-rooted tree. The definition of a distance between two leaves in a binary non-rooted tree is the number of edges in the path joining the two leaves.
I've tried the ape package but I'm unable to find this vector.
For example, using rtree(5,rooted=F) I've obtained the following tree:
$edge
2012 Oct 08
1
Any better way of optimizing time for calculating distances in the mentioned scenario??
Dear All,
I'm dealing with a case, where 'manhattan' distance of each of 100
vectors is calculated from 10000 other vectors. For achieving this,
following 4 scenarios are tested:
1) scenario 1:
> x<-read.table("query.vec")
> v<-read.table("query.vec2")
> d<-matrix(nrow=nrow(v),ncol=nrow(x))
> for (i in 1:nrow(v)){
+ d[i,]<-
2007 Oct 16
2
Canberra distance
Hi,
I misunderstand the definition of Canberra distance in R.
On Internet and in function description pages of dist() from stats and
Dist() from amap, Canberra distance between vectors x and y, d(x,y), is :
d(x,y) = sum(abs(x-y)/(x+y))
But in use, through simple examples, we find that the formula is :
d(x,y) = (NZ + 1)/NZ * sum(abs(x-y)/(x+y))
with NZ = nb of pairs of coordinates that are
2006 Oct 21
1
Problems running IsoMDS using vegdist with pres-abs data and two sites with zero distance
Hi
I have just (finally) started to poke around in R and wanted to analyse
a stream fish dataset with 28 sites and 18 species. When trying to
follow the Vegan manual to run nmds from distance measures calculated by
the vegdist function it turns out that I have two sites (streams) with
the exactly the same four species (I have used pres-abs data in this
case). When I try to run isoMDS I get an
2013 Apr 24
2
Distance matrices Combinations
Dear UseRs,
MY PROBLEM IS A SMALL PIECE OF A REAL BIG AND A COMPLICATED PROBLEM. IF I DELIBERATE IN A VERY SIMPLE WAY THEN ALL I
WANT IS TO PUT ALL THE POSSIBLE COMBINATIONS OF 75 DISTANCE MATRICES (BY TAKING 4 MATRICES, MORE COMMONLY 75C4), in the following equation.
t<-as.matrix((MAT1)^2+(MAT2)^2+(MAT3)^2+(MAT4)^2+,upper=T,diag=T))
Then "1215450" values of "t"(one for
2012 May 26
1
Kolmogorov-Smirnov test and the plot of max distance between two ecdf curves
Hi all,
given this example
#start
a<-c(0,70,50,100,70,650,1300,6900,1780,4930,1120,700,190,940,
760,100,300,36270,5610,249680,1760,4040,164890,17230,75140,1870,22380,5890,2430)
length(a)
b<-c(0,0,10,30,50,440,1000,140,70,90,60,60,20,90,180,30,90,
3220,490,20790,290,740,5350,940,3910,0,640,850,260)
length(b)
out<-ks.test(log10(a+1),log10(b+1))
# max distance D
2004 Nov 09
1
gdist and gower distance
Dear All,
I would like to ask clarifications on the gower distnce matrix calculated by the function gdistin the library mvpart.
Here is a dummy example:
> library(mvpart)
Loading required package: survival
Loading required package: splines
mvpart package loaded: extends rpart to include
multivariate and distance-based partitioning
> x=matrix(1:6, byrow=T, ncol=2)
> x
[,1]
2013 Mar 22
3
Distance calculation
Hi Elisa,
I hope this is what you wanted.
dat1<-read.csv("peaks.csv",sep=",")
#Subset
dat2<-dat1[1:5,]
res1<-do.call(cbind,lapply(seq_len(nrow(dat2)),function(i) do.call(rbind,lapply(split(rbind(dat2[i,],dat2[-i,]),1:nrow(rbind(dat2[i,],dat2[-i,]))), function(x) {x1<-rbind(dat2[i,],x);