I don't know exactly how the Distance functions are to be used but if you do methods(pairwise) you see that it is only define if x and y are two dimensional.
On Wednesday, July 2, 2014 5:22:58 PM UTC+3, Donald Lacombe wrote: > > Greetings! > > I am a new Julia user and have the following issue. I am writing code to > calculate a knn spatial weight matrix to estimate a spatial econometric > model. Using the MATLAB code from Jim LeSage's Econometrics Toolbox, I > converted that code into Julia as follows: > > xc = rand(8); > > yc = rand(8); > > n = length(xc); > > k = 2; > > distance = zeros(n); > > nnlist = zeros(n,k); > > tempw = zeros(n,n); > > > for i=1:n; > > xi = xc[i,1]; > > yi = yc[i,1]; > > distance = (xc - xi*ones(n)).^2 + (yc - yi*ones(n)).^2 > > temp = sortperm(distance) > > nnlist[i,1:k] = temp[2:k+1,1]'; > > end > > > for i=1:n > > tempw[i,nnlist[i,:]] = 1; > > end > > > W = tempw/k; > > > This is a "toy" example and I was wondering if I can use the Distance package > to simplify the distance = (xc - xi*ones(n)).^2 + (yc - yi*ones(n)).^2 > formula. I tried using the pairwise option like so: > > > R = pairwise(Euclidean(),xc,yc) but received the following message: > > > R = pairwise(Euclidean(),xc,yc) > > MethodError(pairwise,(Euclidean(),[0.05961066617957589,0.018538084399339905,0.39282193332224646,0.7006919213133509,0.5099836895629475,0.8448415935222402,0.2985674570217043,0.8022287058003177],[0.5808687231553928,0.9655167324458858,0.026306556019434435,0.6565373244339141,0.11927452074471412,0.11873635450496622,0.6271632933770979,0.7081439899673692])) > > I'd like to be able to utilize the Distance package but am a bit stumped. The > code as written works but it's bugging me that I cannot seem to get the above > command to work. I also get the following error when loading Distance: > > > using Distance > > Warning: could not import Base.foldl into NumericExtensions > > Warning: could not import Base.foldr into NumericExtensions > > Warning: could not import Base.sum! into NumericExtensions > > Warning: could not import Base.maximum! into NumericExtensions > > Warning: could not import Base.minimum! into NumericExtensions > > > If there is anyone who can address this I'd greatly appreciate it. > Incidentally, the help on this group is one reason I am making the change. > > > Don > > > > >
