I am looking for the distance between the spatial median of a subset of points to all original points in the set preferences to model group decision making. I can build a for loop to return the subsets spatial medians but am having trouble extracting the optimized distances. Any help is greatly appreciated.
n = 5
preferences = RandomVariate[NormalDistribution[5, 2], {n, 2}]
dtotal[f_] := Total[Sqrt[Total[(Transpose[f] - {x, y})^2]]]
sodtotal = FindMinimum[dtotal[preferences], {x}, {y}]
sopt = {x /. sodtotal[[2]], y /. sodtotal[[2]]}
sodist = sodtotal[[1]]
SpatialMedian[preferences]
prefsub = Subsets[preferences, {1, n}]
subdtotal = Map[dtotal, Subsets[preferences, {1, n}]]
subopt = {}
For[i = 1, i <= Length[subdtotal], i++,
subopt = Append[
subopt, {x /. FindMinimum[subdtotal[[i]], {x}, {y}][[2]],
y /. FindMinimum[subdtotal[[i]], {x}, {y}][[2]]}]]
subopt
Creating Lists From Loops How do I find the Euclidean distance between one point and all the points in a list?
NMinimize
works better here instead ofFindMinimum
$\endgroup$