Mapping arbitrary strings to RGB values

前端 未结 8 1358
迷失自我
迷失自我 2021-01-05 03:49

I have a huge set of arbitrary natural language strings. For my tool to analyze them I need to convert each string to unique color value (RGB or other). I need color contras

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 04:01

    Here is my suggestion (I think there is a general name for this algorithm, but I'm too tired to remember it):

    You want to transform each string to a 3D point node(r, g, b) (you can scale the values so that they fit your range) such that the following error is minimized:

    Error = \sum_i{\sum_j{(dist(node_i, node_j) - dist(str_i, str_j))^2}}
    

    You can do this:

    1. First assign each string a random color (r, g, b)
    2. Repeat until you see fit (eg. error is adjusted less than \epsilon = 0.0001):
      1. Pick a random node
      2. Adjust it's position (r, g, b) such that the error is minimized
    3. Scale the coordinate system such that each nodes coordinates are in the range [0., 1.) or [0, 256]

提交回复
热议问题