c# - Alternatives to nested Select in Linq -
working on clustering project, stumbled upon this, , i'm trying figure out if there's better solution 1 i've come with.
problem : given list<point> points
of points in r^n ( can think @ every point double array fo dimension n), double mindistance
, distance func<point,point,double> dist
, write linq expression returns, each point, set of other points in list closer him mindistance according dist.
my solution following:
var lst = points.select( x => points.where(z => dist(x, z) < mindistance) .tolist() ) .tolist();
so, after noticing that
- using linq not best idea, because calculate every distance twice
- the problem doesn't have practical use
- my code, if bad looking, works
i have following questions:
- is possible translate code in query expression? , if so, how?
- is there better way solve in dot notation?
the problem definition, want "for each point, set of other points" makes impossible solve without inner query - disguise in clever manner. if change data storage policy, , don't stick linq then, in general, there many approaches nearest neighbour search problem. example hold points sorted according values on 1 axis, can speed-up queries neighbours eliminating candidates without full distance calculation. here paper approach: flexible metric nearest neighbor classification.