Skip to content

Commit

Permalink
chore: Update environment processing and ARC classes
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Aug 15, 2024
1 parent 25c0477 commit d20226d
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 115 deletions.
2 changes: 1 addition & 1 deletion nbs/01_putils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@
"#| export\n",
"def get_abs_tol(key):\n",
" # dic = {'evolve': 0.01, 'ARC-evolve' : 0.01, 'ARC-display': 0.01, 'ARC': 0.01}\n",
" dic = { 'ARC-evolve' : 0.01, 'ARC-display': 0.1, 'ARC-change' : 0.01, 'ARC-zero': 0.01, 'ARC-gradient': 0.005}\n",
" dic = { 'ARC-evolve' : 0.01, 'ARC-display': 0.1, 'ARC-change' : 0.01, 'ARC-zero': 0.01, 'ARC-gradient': 0.0001}\n",
"\n",
" # if key in dic:\n",
" return dic[key]\n",
Expand Down
4 changes: 0 additions & 4 deletions nbs/04_hierarchy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2789,10 +2789,6 @@
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
28 changes: 17 additions & 11 deletions nbs/05_environments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1660,16 +1660,20 @@
" self.done = self.env_done\n",
" else:\n",
" self.done, details = ListChecker.check_list_unchanged(self.boxcar, rel_tol =get_rel_tol('ARC-change'), abs_tol=get_abs_tol('ARC-change'), gradient_abs_tol=get_abs_tol('ARC-gradient'))\n",
" if self.done:\n",
" self.env.add_to_gradient_list(details['gradient_range']) \n",
" # self.env.fitness_isclose_to_zero = ListChecker.check_float_list_close_to_zero(self.boxcar, rel_tol = 0, abs_tol=get_abs_tol('ARC-zero'), gradient_abs_tol=get_abs_tol('ARC-gradient'))\n",
"\n",
" if self.done:\n",
" self.env.add_to_fitness_list(max(self.boxcar) )\n",
" self.env.fitness_isclose_to_zero, _, _ = self.is_fitness_close_to_zero()\n",
" self.env.fitness_isclose_to_zero = self.is_fitness_close_to_zero()\n",
"\n",
" # if self.env.fitness_isclose_to_zero:\n",
" # print(self.env.iteration)\n",
" # print('gradient ', abs(max(gradients) - min(gradients)), max(abs(gradients)), gradient_mean, [ f'{g:4.4f}' for g in gradients] )\n",
" # print('fitness, ', self.boxcar)\n",
" # print('flist', self.env.fitness_list)\n",
"\n",
" # if self.boxcar[0]<0.01 and self.boxcar[9]<0.01:\n",
" # print('fitness_isclose_to_zero', self.env.fitness_isclose_to_zero)\n",
" # print(self.boxcar)\n",
" # print('---> ', gradient_mean, gradients)\n",
"\n",
" if self.debug:\n",
" if self.done:\n",
Expand All @@ -1682,7 +1686,7 @@
"\n",
" def is_fitness_close_to_zero(self):\n",
" # should this be max of fitness list\n",
" return ListChecker.check_float_list_close_to_zero(self.boxcar, rel_tol = 0, abs_tol=get_abs_tol('ARC-zero'), gradient_abs_tol=get_abs_tol('ARC-gradient'))\n",
" return ListChecker.check_float_list_close_to_zero(self.boxcar, rel_tol = 0, abs_tol=get_abs_tol('ARC-zero'))\n",
"\n",
"\n",
" def get_fitness_list(self):\n",
Expand Down Expand Up @@ -1716,7 +1720,7 @@
" else:\n",
" fit = self.env.fitness\n",
"\n",
" return {'fitness_list' : self.env.fitness_list, 'fitness' : fit}\n",
" return {'fitness_list' : self.env.fitness_list, 'fitness' : fit, 'gradient_list' : self.env.gradient_list}\n",
"\n",
" class Factory:\n",
" @staticmethod\n",
Expand All @@ -1739,11 +1743,17 @@
"output_type": "stream",
"text": [
"{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}\n",
"gradient -285.0 [ 0. 0. 0. -475. -950.] 950.0\n",
"ARC ARC | [4] | links constant \n",
"gradient -195.4 [ 0. 0. -475. -484. -18.] 484.0\n",
"ARC ARC | [5] | links constant \n",
"gradient -197.8 [ 0. -475. -484. -16. -14.] 484.0\n",
"ARC ARC | [6] | links constant \n",
"gradient -294.4 [-950. -484. -16. -12. -10.] 950.0\n",
"ARC ARC | [7] | links constant \n",
"gradient -12.0 [-18. -16. -12. -8. -6.] 18.0\n",
"ARC ARC | [8] | links constant \n",
"gradient -8.0 [-14. -12. -8. -4. -2.] 14.0\n",
"ARC ARC | [9] | links constant \n",
"{'type': 'ARC', 'name': 'ARC', 'value': [9], 'links': {0: 'constant'}, 'env_name': 'ARC'}\n",
"\n",
Expand Down Expand Up @@ -2034,10 +2044,6 @@
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
4 changes: 0 additions & 4 deletions nbs/07_errors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,6 @@
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
31 changes: 9 additions & 22 deletions nbs/14_helpers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
" if not float_list:\n",
" return True, {\"gradient\": None, \"mean\": None, \"std_dev\": None}\n",
"\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",
"\n",
"\n",
Expand All @@ -87,13 +84,17 @@
" for value in float_list[1:]\n",
" )\n",
"\n",
" sum_abs_gradient_close_to_zero = math.isclose(sum(abs(gradient)), 0, rel_tol=0, abs_tol=gradient_abs_tol)\n",
" gradients = np.gradient(float_list)\n",
" mean_value = np.mean(float_list)\n",
" std_dev = np.std(float_list)\n",
"\n",
" gradient_range = abs(max(gradients) - min(gradients)) \n",
" gradient_range_close_to_zero = math.isclose(gradient_range, 0, rel_tol=0, abs_tol=gradient_abs_tol)\n",
"\n",
" return all_close_to_first and sum_abs_gradient_close_to_zero, {\"gradient\": gradient, \"mean\": mean_value, \"std_dev\": std_dev}\n",
" return all_close_to_first and gradient_range_close_to_zero, {\"gradient_range\": gradient_range, \"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",
" def check_float_list_close_to_zero(float_list, rel_tol=1e-9, abs_tol=0.0):\n",
" \"\"\"\n",
" Checks if the values in the float list are close to zero within the specified tolerance\n",
" and if the gradient (difference between consecutive values) is close to zero within the specified gradient tolerance.\n",
Expand All @@ -108,22 +109,8 @@
" math.isclose(value, 0, rel_tol=rel_tol, abs_tol=abs_tol)\n",
" 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",
" \n",
" return values_close_to_zero, gradient_mean, gradients\n",
" \n",
" return values_close_to_zero\n",
" \n",
"\n",
"\n",
Expand Down
14 changes: 9 additions & 5 deletions nbs/15_arc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
" self.dataset = None\n",
" self.namespace = namespace\n",
" self.fitness_list = []\n",
"\n",
" self.gradient_list = []\n",
" # Render settings\n",
" self.screen_width = 1000\n",
" self.screen_height = 500\n",
Expand Down Expand Up @@ -700,6 +700,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.gradient_list = [] # Initialize an empty list for gradient\n",
" self.fitness_isclose_to_zero = False\n",
"\n",
" def next(self):\n",
Expand All @@ -725,6 +726,13 @@
" \"\"\"\n",
" self.fitness_list.append(fitness)\n",
"\n",
" def add_to_gradient_list(self, gradient): \n",
" \"\"\"\n",
" Add the provided gradient to the gradient list.\n",
" \"\"\"\n",
" self.gradient_list.append(gradient) \n",
"\n",
"\n",
" def is_environment_resolved(self):\n",
" max_fitness = max(self.fitness_list)\n",
" return max_fitness < 0.01\n",
Expand Down Expand Up @@ -1015,10 +1023,6 @@
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
71 changes: 35 additions & 36 deletions nbs/16_environment_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -252,7 +252,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -282,7 +282,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -390,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -461,7 +461,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -491,7 +491,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -554,10 +554,14 @@
" render=self.args['verbosed']['display_env'], runs=runs, experiment=experiment, min=min, plots=plots, plots_dir=self.args['plots_dir'],\n",
" enhanced_environment_properties=enhanced_environment_properties, title_prefix=title_prefix, early_termination=False)\n",
"\n",
" score = round(score ** 0.5)\n",
" score = round(score ** 0.5, 1)\n",
" print('Test score',score)\n",
" fitness_list = str( [f'{i:4.3f}' for i in self.env_processing_details['fitness_list']])\n",
" print('fitness_list', fitness_list)\n",
"\n",
" gradient_list = str( [f'{i:4.5f}' for i in self.env_processing_details['gradient_list']])\n",
" print('gradient_list', gradient_list)\n",
"\n",
" ram = round(get_ram_mb())\n",
" print('RAM', ram)\n",
" if experiment: \n",
Expand All @@ -568,12 +572,14 @@
" indstr = str(environment_properties['index'])\n",
" experiment.log_other('index', indstr)\n",
" experiment.log_other('fitness_list', fitness_list)\n",
" experiment.log_other('gradient_list', gradient_list)\n",
" input_set = environment_properties['input_set']\n",
" experiment.log_other('input_set', str(input_set))\n",
" experiment.log_metric('last_gen', self.env_processing_details['last_gen'])\n",
" experiment.log_metric('fitness', self.env_processing_details['fitness'])\n",
" experiment.log_metric('RAM', ram) \n",
" experiment.log_other('test_score', f'{score:4.3f}')\n",
" experiment.log_other('code', environment_properties['code'])\n",
"\n",
" return {}\n",
"\n",
Expand All @@ -600,7 +606,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -624,38 +630,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"G:\\My Drive\\data\\ga\\ARC\\FitnessError-MovingSumError-Mode07\\ga-000.000-s001-1x1-m007-ARC0009-1e1867dd3cfb6967b085ac003458aa46.properties\n",
"{'code': '007bbfb7', 'index': 0, 'dataset': 'test', 'control_set': ['dims'], 'input_set': ['env'], 'history': 10, 'initial': 100}\n",
"Test score 572\n"
]
},
{
"data": {
"text/plain": [
"{}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#| gui \n",
"env_proc.results(filepath='G:\\\\My Drive\\\\data\\\\ga\\\\ARC\\\\FitnessError-MovingSumError-Mode07\\\\ga-000.000-s001-1x1-m007-ARC0009-1e1867dd3cfb6967b085ac003458aa46.properties')\n",
"\n",
"#env_proc.results(filepath='G:\\\\My Drive\\\\data\\\\ga\\\\ARC\\\\FitnessError-MovingSumError-Mode07\\\\ga-000.000-s001-1x1-m007-ARC0009-1e1867dd3cfb6967b085ac003458aa46.properties')\n",
"# env_proc.results(filepath='testfiles\\\\data\\\\ga\\\\ga-000.000-s001-1x1-m007-ARC0010-9ddcf52416e60d65f19007957d07262d-consolidated.properties')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -676,6 +663,18 @@
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit d20226d

Please sign in to comment.