I've generated a series of points in 2D by a `DimensionReduce`

on a list of colors:

```
colors = RandomColor(100);
coords = DimensionReduce(colors, 2, Method -> "TSNE");
ListPlot(Thread(Style(coords, colors, PointSize -> .05)))
```

However, I would like to arrange these points in a regular 2D grid (or other grid) while preserving the neighborhoods as much as possible to achieve the following:

(This is just a model)

Is there a function to provide this transformation? Or do I rather write something to mix the colors in a grid to minimize the distances between the neighbors? Here is my rough attempt of such a process:

```
dm = DistanceMatrix(colors, DistanceFunction -> ColorDistance);
g = System`GridGraph({10, 10}, VertexSize -> .8);
adj = AdjacencyMatrix@g;
vneighbors =
GatherBy(Position(adj // Normal, 1), First)((;; , ;; , 2));
vlabels = Range(100);
Fold(SetProperty({#1, #2},
VertexStyle -> colors((vlabels((#2))))) &, g, Range(100))
```

```
Do(
While({swapi, swapj} = RandomInteger({1, 100}, 2); swapi == swapj);
cost = Total@
dm((vlabels((swapi)), vlabels((vneighbors((swapi)))))) +
Total@dm((vlabels((swapj)), vlabels((vneighbors((swapj))))));
swapcost =
Total@dm((vlabels((swapj)), vlabels((vneighbors((swapi)))))) +
Total@dm((vlabels((swapi)), vlabels((vneighbors((swapj))))));
If(cost > swapcost, temp = vlabels((swapi));
vlabels((swapi)) = vlabels((swapj)); vlabels((swapj)) = temp),
10000);
Fold(SetProperty({#1, #2},
VertexStyle -> colors((vlabels((#2))))) &, g, Range(100))
```

Is this the best solution to the problem? There has to be something cleverer that Mathematica can give me.