Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Aug 9, 2024
1 parent 6de1d1f commit 0f8bb76
Show file tree
Hide file tree
Showing 9 changed files with 1,625 additions and 369 deletions.
92 changes: 49 additions & 43 deletions nbs/04_hierarchy.ipynb

Large diffs are not rendered by default.

272 changes: 60 additions & 212 deletions nbs/05_environments.ipynb

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions nbs/14_helpers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"\n",
" \n",
" @staticmethod\n",
" def check_list_unchanged(float_list, rel_tol=1e-9, abs_tol=0.0):\n",
" def check_list_unchanged(float_list, rel_tol=1e-9, abs_tol=0.0, gradient_abs_tol=0.0):\n",
" \"\"\"\n",
" Checks if the list values are unchanged by calculating their gradient, mean, and standard deviation.\n",
"\n",
Expand All @@ -76,17 +76,21 @@
" if not float_list:\n",
" return True, {\"gradient\": None, \"mean\": None, \"std_dev\": None}\n",
"\n",
" gradient = np.gradient(float_list).mean()\n",
" gradient = np.gradient(float_list)\n",
" mean_value = np.mean(float_list)\n",
" std_dev = np.std(float_list)\n",
" first_value = float_list[0]\n",
" # Check if all values are close to the mean\n",
" all_close_to_mean = all(\n",
"\n",
"\n",
" all_close_to_first = all(\n",
" math.isclose(value, first_value, rel_tol=rel_tol, abs_tol=abs_tol)\n",
" for value in float_list[1:]\n",
" )\n",
"\n",
" return all_close_to_mean, {\"gradient\": gradient, \"mean\": mean_value, \"std_dev\": std_dev}\n",
" sum_abs_gradient_close_to_zero = math.isclose(sum(abs(gradient)), 0, rel_tol=0, abs_tol=gradient_abs_tol)\n",
"\n",
"\n",
" return all_close_to_first and sum_abs_gradient_close_to_zero, {\"gradient\": gradient, \"mean\": mean_value, \"std_dev\": std_dev}\n",
"\n",
" @staticmethod\n",
" def check_float_list_close_to_zero(float_list, rel_tol=1e-9, abs_tol=0.0, gradient_abs_tol=0.0):\n",
Expand All @@ -105,18 +109,21 @@
" for value in float_list\n",
" )\n",
" \n",
" # mean_value = np.mean(float_list)\n",
" # mean_close_to_zero = math.isclose(mean_value, 0, rel_tol=rel_tol, abs_tol=abs_tol)\n",
" \n",
" if len(float_list) == 1:\n",
" return values_close_to_zero\n",
" \n",
" gradients = np.gradient(float_list)\n",
" gradient_mean = np.mean(gradients)\n",
" \n",
" gradients_close_to_mean = all(\n",
" math.isclose(gradient, gradient_mean, rel_tol=0, abs_tol=gradient_abs_tol)\n",
" for gradient in gradients\n",
" )\n",
" # gradients_close_to_mean = all(\n",
" # math.isclose(gradient, gradient_mean, rel_tol=0, abs_tol=gradient_abs_tol)\n",
" # for gradient in gradients\n",
" # )\n",
" \n",
" return values_close_to_zero and gradients_close_to_mean, gradient_mean, gradients\n",
" return values_close_to_zero, gradient_mean, gradients\n",
" \n",
"\n",
"\n",
Expand Down Expand Up @@ -515,8 +522,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Execution time of challenges load: 0.0271 seconds\n",
"Execution time of solutions load: 0.0040 seconds\n",
"Execution time of challenges load: 0.0301 seconds\n",
"Execution time of solutions load: 0.0053 seconds\n",
"['007bbfb7', '00d62c1b', '017c7c7b', '025d127b', '045e512c', '0520fde7', '05269061', '05f2a901', '06df4c85', '08ed6ac7', '09629e4f', '0962bcdd', '0a938d79', '0b148d64', '0ca9ddb6', '0d3d703e', '0dfd9992', '0e206a2e', '10fcaaa3', '11852cab', '1190e5a7', '137eaa0f', '150deff5', '178fcbfb', '1a07d186', '1b2d62fb', '1b60fb0c', '1bfc4729', '1c786137', '1caeab9d', '1cf80156', '1e0a9b12', '1e32b0e9', '1f0c79e5', '1f642eb9', '1f85a75f', '1f876c06', '1fad071e', '2013d3e2', '2204b7a8', '22168020', '22233c11', '2281f1f4', '228f6490', '22eb0ac0', '234bbc79', '23581191', '239be575', '23b5c85d', '253bf280', '25d487eb', '25d8a9c8', '25ff71a9', '264363fd', '272f95fa', '27a28665', '28bf18c6', '28e73c20', '29623171', '29c11459', '29ec7d0e', '2bcee788', '2bee17df', '2c608aff', '2dc579da', '2dd70a9a', '2dee498d', '31aa019c', '321b1fc6', '32597951', '3345333e', '3428a4f5', '3618c87e', '3631a71a', '363442ee', '36d67576', '36fdfd69', '3906de3d', '39a8645d', '39e1d7f9', '3aa6fb7a', '3ac3eb23', '3af2c5a8', '3bd67248', '3bdb4ada', '3befdf3e', '3c9b0459', '3de23699', '3e980e27', '3eda0437', '3f7978a0', '40853293', '4093f84a', '41e4d17e', '4258a5f9', '4290ef0e', '42a50994', '4347f46a', '444801d8', '445eab21', '447fd412', '44d8ac46', '44f52bb0', '4522001f', '4612dd53', '46442a0e', '469497ad', '46f33fce', '47c1f68c', '484b58aa', '48d8fb45', '4938f0c2', '496994bd', '49d1d64f', '4be741c5', '4c4377d9', '4c5c2cf0', '50846271', '508bd3b6', '50cb2852', '5117e062', '5168d44c', '539a4f51', '53b68214', '543a7ed5', '54d82841', '54d9e175', '5521c0d9', '5582e5ca', '5614dbcf', '56dc2b01', '56ff96f3', '57aa92db', '5ad4f10b', '5bd6f4ac', '5c0a986e', '5c2c9af4', '5daaa586', '60b61512', '6150a2bd', '623ea044', '62c24649', '63613498', '6430c8c4', '6455b5f5', '662c240a', '67385a82', '673ef223', '6773b310', '67a3c6ac', '67a423a3', '67e8384a', '681b3aeb', '6855a6e4', '68b16354', '694f12f3', '6a1e5592', '6aa20dc0', '6b9890af', '6c434453', '6cdd2623', '6cf79266', '6d0160f0', '6d0aefbc', '6d58a25d', '6d75e8bb', '6e02f1e3', '6e19193c', '6e82a1ae', '6ecd11f4', '6f8cd79b', '6fa7a44f', '72322fa7', '72ca375d', '73251a56', '7447852a', '7468f01a', '746b3537', '74dd1130', '75b8110e', '760b3cac', '776ffc46', '77fdfe62', '780d0b14', '7837ac64', '794b24be', '7b6016b9', '7b7f7511', '7c008303', '7ddcd7ec', '7df24a62', '7e0986d6', '7f4411dc', '7fe24cdd', '80af3007', '810b9b61', '82819916', '83302e8f', '834ec97d', '8403a5d5', '846bdb03', '855e0971', '85c4e7cd', '868de0fa', '8731374e', '88a10436', '88a62173', '890034e9', '8a004b2b', '8be77c9e', '8d5021e8', '8d510a79', '8e1813be', '8e5a5113', '8eb1be9a', '8efcae92', '8f2ea7aa', '90c28cc7', '90f3ed37', '913fb3ed', '91413438', '91714a58', '9172f3a0', '928ad970', '93b581b8', '941d9a10', '94f9d214', '952a094c', '9565186b', '95990924', '963e52fc', '97999447', '97a05b5b', '98cf29f8', '995c5fa3', '99b1bc43', '99fa7670', '9aec4887', '9af7a82c', '9d9215db', '9dfd6313', '9ecd008a', '9edfc990', '9f236235', 'a1570a43', 'a2fd1cf0', 'a3325580', 'a3df8b1e', 'a416b8f3', 'a48eeaf7', 'a5313dff', 'a5f85a15', 'a61ba2ce', 'a61f2674', 'a64e4611', 'a65b410d', 'a68b268e', 'a699fb00', 'a740d043', 'a78176bb', 'a79310a0', 'a85d4709', 'a87f7484', 'a8c38be5', 'a8d7556c', 'a9f96cdd', 'aabf363d', 'aba27056', 'ac0a08a4', 'ae3edfdc', 'ae4f1146', 'aedd82e4', 'af902bf9', 'b0c4d837', 'b190f7f5', 'b1948b0a', 'b230c067', 'b27ca6d3', 'b2862040', 'b527c5c6', 'b548a754', 'b60334d2', 'b6afb2da', 'b7249182', 'b775ac94', 'b782dc8a', 'b8825c91', 'b8cdaf2b', 'b91ae062', 'b94a9452', 'b9b7f026', 'ba26e723', 'ba97ae07', 'bb43febb', 'bbc9ae5d', 'bc1d5164', 'bd4472b8', 'bda2d7a6', 'bdad9b1f', 'be94b721', 'beb8660c', 'c0f76784', 'c1d99e64', 'c3e719e8', 'c3f564a4', 'c444b776', 'c59eb873', 'c8cbb738', 'c8f0f002', 'c909285e', 'c9e6f938', 'c9f8e694', 'caa06a1f', 'cbded52d', 'cce03e0d', 'cdecee7f', 'ce22a75a', 'ce4f8723', 'ce602527', 'ce9e57f2', 'cf98881b', 'd037b0a7', 'd06dbe63', 'd07ae81c', 'd0f5fe59', 'd10ecb37', 'd13f3404', 'd22278a0', 'd23f8c26', 'd2abd087', 'd364b489', 'd406998b', 'd43fd935', 'd4469b4b', 'd4a91cb9', 'd4f3cd78', 'd511f180', 'd5d6de2d', 'd631b094', 'd687bc17', 'd6ad076f', 'd89b689b', 'd8c310e9', 'd90796e8', 'd9f24cd1', 'd9fac9be', 'dae9d2b5', 'db3e9e38', 'db93a21d', 'dbc1a6ce', 'dc0a314f', 'dc1df850', 'dc433765', 'ddf7fa4f', 'de1cd16c', 'ded97339', 'e179c5f4', 'e21d9049', 'e26a3af2', 'e3497940', 'e40b9e2f', 'e48d4e1a', 'e5062a87', 'e509e548', 'e50d258f', 'e6721834', 'e73095fd', 'e76a88a6', 'e8593010', 'e8dc4411', 'e9614598', 'e98196ab', 'e9afcf9a', 'ea32f347', 'ea786f4a', 'eb281b96', 'eb5a1d5d', 'ec883f72', 'ecdecbb3', 'ed36ccf7', 'ef135b50', 'f15e1fac', 'f1cefba8', 'f25fbde4', 'f25ffba3', 'f2829549', 'f35d900a', 'f5b8619d', 'f76d97a5', 'f8a8fe49', 'f8b3ba0a', 'f8c80d96', 'f8ff0b80', 'f9012d9b', 'fafffa47', 'fcb5c309', 'fcc82909', 'feca6190', 'ff28f65a', 'ff805c23']\n",
"400\n",
"(['00d62c1b', '025d127b', '045e512c', '0520fde7', '05269061', '05f2a901', '06df4c85', '08ed6ac7', '09629e4f', '0962bcdd', '0a938d79', '0ca9ddb6', '0d3d703e', '0dfd9992', '0e206a2e', '11852cab', '150deff5', '178fcbfb', '1a07d186', '1b2d62fb', '1b60fb0c', '1bfc4729', '1caeab9d', '1e0a9b12', '1e32b0e9', '1f0c79e5', '1f642eb9', '1f876c06', '2204b7a8', '22168020', '22233c11', '2281f1f4', '228f6490', '22eb0ac0', '234bbc79', '23581191', '253bf280', '25d487eb', '25d8a9c8', '25ff71a9', '264363fd', '272f95fa', '28e73c20', '29623171', '29c11459', '29ec7d0e', '2bcee788', '2bee17df', '2c608aff', '2dd70a9a', '2dee498d', '31aa019c', '321b1fc6', '32597951', '3345333e', '3618c87e', '3631a71a', '363442ee', '36d67576', '36fdfd69', '3906de3d', '39e1d7f9', '3aa6fb7a', '3ac3eb23', '3bd67248', '3bdb4ada', '3befdf3e', '3c9b0459', '3e980e27', '3eda0437', '40853293', '4093f84a', '41e4d17e', '4258a5f9', '42a50994', '4347f46a', '444801d8', '447fd412', '44d8ac46', '4612dd53', '484b58aa', '4938f0c2', '496994bd', '4c5c2cf0', '50846271', '508bd3b6', '50cb2852', '5168d44c', '543a7ed5', '54d82841', '54d9e175', '5521c0d9', '5582e5ca', '56dc2b01', '56ff96f3', '57aa92db', '5c0a986e', '5c2c9af4', '60b61512', '6150a2bd', '623ea044', '63613498', '6455b5f5', '67385a82', '673ef223', '67a3c6ac', '67a423a3', '6855a6e4', '68b16354', '694f12f3', '6a1e5592', '6aa20dc0', '6c434453', '6cdd2623', '6cf79266', '6d0160f0', '6d0aefbc', '6d58a25d', '6d75e8bb', '6e02f1e3', '6e19193c', '6e82a1ae', '6f8cd79b', '72322fa7', '73251a56', '7447852a', '74dd1130', '760b3cac', '776ffc46', '794b24be', '7b6016b9', '7ddcd7ec', '7df24a62', '7e0986d6', '7f4411dc', '810b9b61', '82819916', '83302e8f', '834ec97d', '8403a5d5', '855e0971', '85c4e7cd', '868de0fa', '88a10436', '890034e9', '8d510a79', '8e5a5113', '8eb1be9a', '8f2ea7aa', '90f3ed37', '913fb3ed', '91714a58', '928ad970', '93b581b8', '941d9a10', '952a094c', '9565186b', '95990924', '963e52fc', '97999447', '98cf29f8', '99fa7670', '9d9215db', '9dfd6313', '9edfc990', 'a1570a43', 'a2fd1cf0', 'a3df8b1e', 'a416b8f3', 'a48eeaf7', 'a5313dff', 'a5f85a15', 'a61f2674', 'a64e4611', 'a65b410d', 'a699fb00', 'a78176bb', 'a79310a0', 'a85d4709', 'a8d7556c', 'a9f96cdd', 'aabf363d', 'aba27056', 'ae3edfdc', 'aedd82e4', 'af902bf9', 'b1948b0a', 'b230c067', 'b27ca6d3', 'b2862040', 'b527c5c6', 'b548a754', 'b60334d2', 'b6afb2da', 'b7249182', 'b775ac94', 'b782dc8a', 'b8825c91', 'b8cdaf2b', 'ba26e723', 'ba97ae07', 'bb43febb', 'bd4472b8', 'bda2d7a6', 'bdad9b1f', 'beb8660c', 'c0f76784', 'c1d99e64', 'c3f564a4', 'c444b776', 'c8f0f002', 'c9e6f938', 'c9f8e694', 'caa06a1f', 'cbded52d', 'ce22a75a', 'ce9e57f2', 'cf98881b', 'd037b0a7', 'd06dbe63', 'd07ae81c', 'd22278a0', 'd23f8c26', 'd2abd087', 'd364b489', 'd406998b', 'd43fd935', 'd4a91cb9', 'd4f3cd78', 'd511f180', 'd5d6de2d', 'd687bc17', 'd6ad076f', 'd89b689b', 'd8c310e9', 'd90796e8', 'd9f24cd1', 'dae9d2b5', 'db3e9e38', 'db93a21d', 'dbc1a6ce', 'dc1df850', 'dc433765', 'ddf7fa4f', 'ded97339', 'e179c5f4', 'e21d9049', 'e26a3af2', 'e3497940', 'e40b9e2f', 'e48d4e1a', 'e5062a87', 'e509e548', 'e73095fd', 'e76a88a6', 'e8593010', 'e8dc4411', 'e9614598', 'e9afcf9a', 'ea32f347', 'ea786f4a', 'ec883f72', 'ecdecbb3', 'ed36ccf7', 'ef135b50', 'f15e1fac', 'f1cefba8', 'f25ffba3', 'f2829549', 'f35d900a', 'f76d97a5', 'f8a8fe49', 'f8c80d96', 'fcc82909'], 274)\n",
Expand Down
96 changes: 28 additions & 68 deletions nbs/15_arc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -31,18 +27,14 @@
}
],
"source": [
"%load_ext autoreload\n",
"%reload_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| default_exp arc"
Expand All @@ -51,11 +43,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -72,11 +60,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -94,11 +78,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand Down Expand Up @@ -184,7 +164,7 @@
" return False\n",
" if self.initial_index is not None:\n",
" return False\n",
" print(f\"Index: {self.index}\")\n",
" # print(f\"Index: {self.index}\")\n",
" self.create_env()\n",
" return True\n",
"\n",
Expand Down Expand Up @@ -447,11 +427,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -518,11 +494,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -589,11 +561,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -649,11 +617,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand Down Expand Up @@ -720,7 +684,7 @@
" self.iteration += 1 # Increment iteration\n",
" if self.iteration > self.runs:\n",
" # print(self.iteration, self.index)\n",
" self.iteration = 1\n",
" # self.iteration = 1\n",
" self.done = True\n",
" return self.state, self.fitness, self.done, self.info\n",
"\n",
Expand All @@ -738,6 +702,7 @@
" self.iteration = 1 # Reset iteration\n",
" self.num_actions = self.info['num_actions'] # Set num_actions\n",
" self.fitness_list = [] # Initialize an empty list for fitness\n",
" self.fitness_isclose_to_zero = False\n",
"\n",
" def next(self):\n",
" \"\"\"\n",
Expand All @@ -751,6 +716,17 @@
" return False\n",
" return self.arc_data.next()\n",
"\n",
" def add_to_fitness_list(self, fitness): \n",
" \"\"\"\n",
" Add the provided fitness to the fitness list.\n",
" \"\"\"\n",
" self.fitness_list.append(fitness)\n",
"\n",
" def is_environment_resolved(self):\n",
" max_fitness = max(self.fitness_list)\n",
" return max_fitness < 0.01\n",
"\n",
"\n",
" def get_environment_score(self):\n",
" \"\"\"\n",
" Get the environment score.\n",
Expand Down Expand Up @@ -934,11 +910,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -981,11 +953,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#|gui\n",
Expand All @@ -997,11 +965,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -1011,11 +975,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"metadata": {},
"outputs": [],
"source": []
}
Expand Down
Loading

0 comments on commit 0f8bb76

Please sign in to comment.