[Date Index]
[Thread Index]
[Author Index]
Re: RE: Re: Re: distance function
*To*: mathgroup at smc.vnet.net
*Subject*: [mg70048] Re: [mg70014] RE: [mg68805] Re: [mg68772] Re: distance function
*From*: "Chris Chiasson" <chris at chiasson.name>
*Date*: Sun, 1 Oct 2006 04:09:21 -0400 (EDT)
*References*: <200609300912.FAA13156@smc.vnet.net>
Why not use caching? Also, Maxim said Norm is slow.
d[{p_,p_}]:=0
d[{p_,q_}]:=d[{p,q}]=d[{q,p}]=Sqrt[#.#]&[p-q]
If memory usage becomes a problem, you could always Clear d.
Alternatively, you could make a Module function that operates on an
entire matrix, using d as one of the temporary "variables" inside of
the Module. As long as you code it correctly (so that d doesn't appear
in the result expression), then d will automatically be Removed.
On 9/30/06, Coleman, Mark <Mark.Coleman at libertymutual.com> wrote:
>
> Out of curiosity, I tested these two approaches on a number of data sets
> for which I make frequent use. For some reason Jens code is running
> slower! I've been testing it out some lists of reals of size
> n=500,1000,2500, and 5000. Is it possible that the time for the
> conditional compares is exceeding the computational time of redundant
> calculations? Could someone try this out?
>
> (note: I'm working on some code for identifying outliers in large data
> sets. The efficient calculation of L-1 and L-2 distance matrices are
> important.)
>
> Thanks
>
> Mark
>
>
> -----Original Message-----
> From: Murray Eisenberg [mailto:murray at math.umass.edu]
To: mathgroup at smc.vnet.net
> Subject: [mg70048] [mg70014] [mg68805] Re: [mg68772] Re: distance function
>
> Yes, I KNOW that I'm computing the distances twice in my solution:
> that's why I said it's an "extravagant" solution!
>
> Jens-Peer Kuska wrote:
> > Hi Murray,
> >
> > at least you should compute the distances not twice because the matrix
>
> > is symmetric with zero diagonal ...
> >
> > d[{p_,p_}]:=0.0
> > d[{q_,p_}]/; OrderedQ[{q,p}]:=d[{q,p}]= Norm[p - q]
> > d[{q_,p_}]:=d[{p,q}]
> >
> > Regards
> > Jens
> >
> >
> > Murray Eisenberg wrote:
> >> If you don't mind an "extravagant" solution -- one that is
> >> conceptually simple and short but is probably inefficient due to
> >> redundant calculations -- then this works, I believe:
> >>
> >> d[{p_, q_}] := Norm[p - q]
> >> allDistances[pts_] := Union[Flatten[Outer[d, pts, pts]]]
> >>
> >>
> >>
> >> dimmechan at yahoo.com wrote:
> >>> In the book of Gaylord et al. (1996) there is one exercise which
> >>> asks (see page 113)
> >>>
> >>> "Given a list of points in the plane, write a function that finds
> >>> the set of all distances between the points."
> >>>
> >>> Although there is one solution, that solution makes use of the Table
>
> >>> and Length commands.
> >>>
> >>> Is it a way to define the same function using Higher-Order functions
>
> >>> like Outer, MapThread etc?
> >>>
> >>> Thanks in advance for any help.
> >>>
> >>>
> >
> >
>
> --
> Murray Eisenberg murray at math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower phone 413 549-1020 (H)
> University of Massachusetts 413 545-2859 (W)
> 710 North Pleasant Street fax 413 545-1801
> Amherst, MA 01003-9305
>
>
--
http://chris.chiasson.name/
Prev by Date:
**Re: HoldPattern question**
Next by Date:
**variance of product of random variables**
Previous by thread:
** Re: distance function**
Next by thread:
**Re: RE: Re: Re: distance function**
| |