MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Minimization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42257] RE: [mg42256] Minimization
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 25 Jun 2003 05:50:04 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Moranresearch at aol.com [mailto:Moranresearch at aol.com]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, June 25, 2003 7:54 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg42257] [mg42256] Minimization
>

>I have a list of points l1= (xi,yi, zi) and a target point 
>(x0,y0,z0) how 
>would I efficiently find the 5 points in l1 closest to, ie 
>with the smallest Euclidian distance to, the target point? 

>John
>

John,

you might like to consider this example:

In[1]:= <<Statistics`ContinuousDistributions`
In[2]:=
distrs=NormalDistribution @@@ {{0,2},{1,.5},{1,1}}

...just to construct reasonable random points for the example

In[3]:= p0=Quantile[#,Random[]]&/@distrs
Out[3]= {0.0398838,0.831293,0.672626}

...a target point taken at random

In[10]:= pts=Transpose[RandomArray[#,{100000}]&/@distrs];

...a swarm of 100000 pts

In[11]:=
(ranks=Ordering[With[{r=#-p0},r.r]&/@pts];)//Timing
Out[11]= {3.886 Second,Null}

...on my (not very fast) computer

In[12]:= pts[[Take[ranks,5]]]
Out[12]=
{{0.0485567, 0.837748, 0.644697},
 {0.00418661, 0.854856, 0.650328},
 {0.0541791, 0.805918, 0.711151},
 {0.0666195, 0.788663, 0.657876},
 {0.0303403, 0.83237, 0.619968}}

these are the 5 closest points to the target.


In[13]:= With[{r=#-p0},Sqrt[r.r]]&/@%
Out[13]= {0.0299487, 0.0482361, 0.0482955, 0.0524375, 0.0535266}

these are there distances to the target.


Perhaps this is good enough for you, but this is possibly not best. We need
more to know from your process (how do you get at the points, serially?), is
the target known in advance? How many points do you have, Millions?,
Billions?, etc. to make better propositions.

--
Hartmut Wolf


  • Prev by Date: Re: format Text in graphics
  • Next by Date: RE: Transfering Packages Between Platforms and InputFor
  • Previous by thread: Minimization
  • Next by thread: Re: Minimization