From feae8a7340d744271839f8a9b715f95afeedfb80 Mon Sep 17 00:00:00 2001 From: Connor Yates Date: Thu, 19 Sep 2019 20:03:21 -0700 Subject: [PATCH 1/2] Update gitignore --- .gitignore | 197 +++++++++++++++++++++++++++++++++++++++++ .idea/Rover-Domain.iml | 8 -- .idea/misc.xml | 7 -- .idea/modules.xml | 8 -- .idea/vcs.xml | 6 -- 5 files changed, 197 insertions(+), 29 deletions(-) create mode 100644 .gitignore delete mode 100644 .idea/Rover-Domain.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b5c903 --- /dev/null +++ b/.gitignore @@ -0,0 +1,197 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + diff --git a/.idea/Rover-Domain.iml b/.idea/Rover-Domain.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/Rover-Domain.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 3999087..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6de22ff..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From d954df6d8ced03642d2a30afb16bd7e7a0ec3f64 Mon Sep 17 00:00:00 2001 From: Connor Yates Date: Thu, 19 Sep 2019 20:36:00 -0700 Subject: [PATCH 2/2] Adds the ability to load/save parameters from a yaml to the Parameters object. Needs to use all the parameters as object members, not class members so vars() loads all instances properly. --- AADI_RoverDomain/parameters.py | 109 ++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 35 deletions(-) diff --git a/AADI_RoverDomain/parameters.py b/AADI_RoverDomain/parameters.py index 7b2d668..56461af 100644 --- a/AADI_RoverDomain/parameters.py +++ b/AADI_RoverDomain/parameters.py @@ -2,6 +2,7 @@ This file contains all constant test parameters which may be altered from this single location for convenience. """ +import yaml class Parameters: @@ -10,38 +11,76 @@ class Parameters: TODO: Heterogeneous rover domain code currently not implemented """ - # Run Parameters - stat_runs = 10 - generations = 1000 # Number of generations for CCEA in each stat run - new_world_config = False # False -> Reuse existing world config, True -> Use new world config - - # Visualizer - running = False # True keeps visualizer from closing until you 'X' out of window - - # Domain parameters - team_types = 'homogeneous' # Switch between 'homogeneous' and 'heterogeneous' rover domains - num_rovers = 12 # Number of rovers on map (GETS MULTIPLIED BY NUMBER OF TYPES) - coupling = 3 # Number of rovers required to view a POI for credit - num_pois = 10 # Number of POIs on map - num_steps = 20 # Number of steps rovers take each episode - min_distance = 1.0 # Minimum distance which may appear in the denominator of credit eval functions - x_dim = 30 # X-Dimension of the rover map - y_dim = 30 # Y-Dimension of the rover map - min_observation_dist = 3.0 # Minimum distance rovers must be to observe POIs - angle_resolution = 90 # Resolution of sensors (determines number of sectors) - sensor_model = "summed" # Should either be "density" or "closest" or "summed" - - # Neural network parameters - num_inputs = 8 - num_nodes = 9 - num_outputs = 2 - - # CCEA parameters - mutation_rate = 0.1 # Probability that a member of the offspring population will be mutated - percentage_mut = 0.01 # Percentage of bits which get flipped in an individual - epsilon = 0.1 # For e-greedy selection in CCEA - parent_pop_size = 20 - offspring_pop_size = 5 - - # User specific parameters - reward_type = "SDPP" # Switch between reward functions "Global" "Difference" "DPP" "SDPP" + def __init__(self): + # Run Parameters + self.stat_runs = 10 + self.generations = 1000 # Number of generations for CCEA in each stat run + self.new_world_config = False # False -> Reuse existing world config, True -> Use new world config + + # Visualizer + self.running = False # True keeps visualizer from closing until you 'X' out of window + + # Domain parameters + self.team_types = 'homogeneous' # Switch between 'homogeneous' and 'heterogeneous' rover domains + self.num_rovers = 12 # Number of rovers on map (GETS MULTIPLIED BY NUMBER OF TYPES) + self.coupling = 3 # Number of rovers required to view a POI for credit + self.num_pois = 10 # Number of POIs on map + self.num_steps = 20 # Number of steps rovers take each episode + self.min_distance = 1.0 # Minimum distance which may appear in the denominator of credit eval functions + self.x_dim = 30 # X-Dimension of the rover map + self.y_dim = 30 # Y-Dimension of the rover map + self.min_observation_dist = 3.0 # Minimum distance rovers must be to observe POIs + self.angle_resolution = 90 # Resolution of sensors (determines number of sectors) + self.sensor_model = "summed" # Should either be "density" or "closest" or "summed" + + # Neural network parameters + self.num_inputs = 8 + self.num_nodes = 9 + self.num_outputs = 2 + + # CCEA parameters + self.mutation_rate = 0.1 # Probability that a member of the offspring population will be mutated + self.percentage_mut = 0.01 # Percentage of bits which get flipped in an individual + self.epsilon = 0.1 # For e-greedy selection in CCEA + self.parent_pop_size = 20 + self.offspring_pop_size = 5 + + # User specific parameters + self.reward_type = "SDPP" # Switch between reward functions "Global" "Difference" "DPP" "SDPP" + + def load_yaml(self, filename): + """ + loads a set of parameters into this object with setattr + Does not require that all parameters are set, i.e. you can optionally set a specific set of parameters + :param filename: + :return: + """ + with open(file=filename) as f: + params = yaml.load(f) + for key in params: + setattr(self, key, params[key]) + + def save_yaml(self, filename): + """ + Saves ALL the parameters into a yaml file, not just the optionally set ones + :param filename: + :return: + """ + with open(file=filename, mode='w') as f: + yaml.dump(vars(self), f) + +if __name__ == '__main__': + with open("/tmp/param_tests.yaml", 'w') as f: + f.write(""" + test_a: 10 + stat_runs: 100 + """) + parameters = Parameters() + print("Before load") + print(parameters.stat_runs) + parameters.load_yaml("/tmp/param_tests.yaml") + print("After load") + print(parameters.test_a) + print(parameters.stat_runs) + parameters.save_yaml("/tmp/param_tests_out.yaml") +