Skip to content

Commit

Permalink
Test for the color context representation question
Browse files Browse the repository at this point in the history
  • Loading branch information
cgpotts committed Jul 26, 2020
1 parent 4b9683d commit 1a58d90
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion hw_colors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,39 @@
" f_jkl = ...\n",
"```\n",
"and collect these `f_jkl` values in a list of 27 values. Additionally, in Python, [`2j` produces a value with `real` and `imag` attributes](https://docs.python.org/3.7/library/cmath.html). Each element `f_jkl` should have these components. If you concatenate the `real` and `imag` parts of all the `f_jkl`, you will have a 54-dimensional representation, as in the paper. Remember to start with an HSV representation, and with $h$ in $[0, 360]$, $s$ in $[0, 200]$, and $v$ in $[0, 200]$ (or else do the scaling differently). Note that the values in our corpus are in HLS format, [which are easily converted to HSV](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL).\n",
"\n"
"\n",
"The following test seeks to ensure only that the output of your `represent_color_context` will be compatible with the models we are creating:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def test_represent_color_context(func):\n",
" \"\"\"`func` should be `represent_color_context`\"\"\"\n",
" example = [\n",
" [0.786, 0.58, 0.87],\n",
" [0.689, 0.44, 0.92],\n",
" [0.628, 0.32, 0.81]]\n",
" result = func(example)\n",
" assert len(result) == len(example), \\\n",
" (\"Color context representations need to represent each color \"\n",
" \"separately. (We assume the final color is the target.)\")\n",
" for i, color in enumerate(result):\n",
" assert all(isinstance(x, float) for x in color), \\\n",
" (\"All color representations should be lists of floats. \"\n",
" \"Color {} is {}\".format(i, color))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_represent_color_context(represent_color_context)"
]
},
{
Expand Down

0 comments on commit 1a58d90

Please sign in to comment.