├── .gitignore ├── Images ├── PID_Control.png ├── RL_Control.png ├── Screen Shot 2020-04-17 at 12.00.03 PM.png ├── Screen Shot 2020-04-17 at 12.00.38 PM.png ├── Screen Shot 2020-04-17 at 9.29.34 PM.png ├── Screen Shot 2020-04-17 at 9.29.58 PM.png ├── Screen Shot 2020-04-17 at 9.30.51 PM.png ├── Screen Shot 2020-04-17 at 9.38.46 PM.png ├── Screen Shot 2020-04-18 at 12.07.08 AM.png ├── Training_graph.png ├── readme.txt └── thermostat_control.png ├── LICENSE ├── README.md ├── RL Project.pptx ├── RL_Heat_DDPG_test.slx ├── _config.yml ├── ddpg_live(new).mlx ├── house_PID.slx ├── house_thermostat.slx └── sldemo_househeat_data.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /Images/PID_Control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/PID_Control.png -------------------------------------------------------------------------------- /Images/RL_Control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/RL_Control.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 12.00.03 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 12.00.03 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 12.00.38 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 12.00.38 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 9.29.34 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 9.29.34 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 9.29.58 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 9.29.58 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 9.30.51 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 9.30.51 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-17 at 9.38.46 PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-17 at 9.38.46 PM.png -------------------------------------------------------------------------------- /Images/Screen Shot 2020-04-18 at 12.07.08 AM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Screen Shot 2020-04-18 at 12.07.08 AM.png -------------------------------------------------------------------------------- /Images/Training_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/Training_graph.png -------------------------------------------------------------------------------- /Images/readme.txt: -------------------------------------------------------------------------------- 1 | Find the images in this folder. 2 | -------------------------------------------------------------------------------- /Images/thermostat_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/Images/thermostat_control.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Abhijit Krishna Menon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TemperatureControl-ReinforcementLearning 2 | Comparing the performance of a DDPG Reinforcement learning model to control temperature with that of a PID and a thermostat controller. 3 | 4 | Find video of the training process [here](https://youtu.be/jCeMeUJZ0eQ). 5 | 6 | Find the Google Slides Link to the project presentation [here](https://docs.google.com/presentation/d/1GeJfwOUY60LKVdWmeQffOwma1hy1oCtQ/edit#slide=id.p1). 7 | 8 | ## Thermostat controller controlling the temperature. 9 | Mean Square Error - 32.7782 10 | ![Thermostat controller](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/Images/thermostat_control.png) 11 | 12 | ## PID controller controlling the temperature. 13 | Mean Square Error - 23.9247 14 | ![PID controller](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/Images/PID_Control.png) 15 | 16 | ## DDPG RL Agent controller controlling the temperature. 17 | Mean Square Error - 26.8667 18 | ![RL controller](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/Images/RL_Control.png) 19 | 20 | 21 | 22 | ## Steps to recreate models: 23 | 1. Run [sldemo_househeat_data.m](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/sldemo_househeat_data.m), and make sure variables exist on the workspace. 24 | 2. Run [house_thermostat.slx](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/house_thermostat.slx) to generate a the plots for the control using a regular thermostat. 25 | 3. Run [house_PID.slx](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/house_PID.slx) to generate a the plots for the control using a Discrete PID controller. 26 | 4. Open the [ddpg_live(new).mlx](https://github.com/akmenon1996/TemperatureControl-ReinforcementLearning/blob/master/ddpg_live(new).mlx) live notebook. Start running each cell individually. (Make sure the variable - training is set to true in the notebook.) 27 | 28 | ### Warnings: 29 | Make sure to have the following toolkits installed to be able to recreate these simulations successfully: 30 | 1. Reinforcement Learning Toolkit. 31 | 2. Machine Learning Toolkit. 32 | 3. PID Tuner 33 | 34 | ### Run files using MATLAB 2020. 35 | 36 | ## Create your own reward function to tune model results. 37 | You will be able to tune the reward function for the simulation by updating the Reward block in the RL_Heat_DDPG_test.slx file. 38 | 39 | 40 | 41 | Use [this](https://www.mathworks.com/help/simulink/slref/thermal-model-of-a-house.html) link to set up base thermal model of the house from the MATLAB-SIMULINK website. 42 | 43 | -------------------------------------------------------------------------------- /RL Project.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/RL Project.pptx -------------------------------------------------------------------------------- /RL_Heat_DDPG_test.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/RL_Heat_DDPG_test.slx -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /ddpg_live(new).mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/ddpg_live(new).mlx -------------------------------------------------------------------------------- /house_PID.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/house_PID.slx -------------------------------------------------------------------------------- /house_thermostat.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akmenon1996/TemperatureControl-ReinforcementLearning/e68d11b598d2e5fe0a303dc81016effe2a16054d/house_thermostat.slx -------------------------------------------------------------------------------- /sldemo_househeat_data.m: -------------------------------------------------------------------------------- 1 | % SLDEMO_HOUSEHEAT_DATA 2 | % This script runs in conjunction with the "sldemo_househeat" 3 | % house thermodynamics example. Note that time is given in units of hours 4 | 5 | % Copyright 1990-2012 The MathWorks, Inc. 6 | 7 | % ------------------------------- 8 | % Problem constant 9 | % ------------------------------- 10 | % converst radians to degrees 11 | r2d = 180/pi; 12 | % ------------------------------- 13 | % Define the house geometry 14 | % ------------------------------- 15 | % House length = 30 m 16 | lenHouse = 30; 17 | % House width = 10 m 18 | widHouse = 10; 19 | % House height = 4 m 20 | htHouse = 4; 21 | % Roof pitch = 40 deg 22 | pitRoof = 40/r2d; 23 | % Number of windows = 6 24 | numWindows = 6; 25 | % Height of windows = 1 m 26 | htWindows = 1; 27 | % Width of windows = 1 m 28 | widWindows = 1; 29 | windowArea = numWindows*htWindows*widWindows; 30 | wallArea = 2*lenHouse*htHouse + 2*widHouse*htHouse + ... 31 | 2*(1/cos(pitRoof/2))*widHouse*lenHouse + ... 32 | tan(pitRoof)*widHouse - windowArea; 33 | % ------------------------------- 34 | % Define the type of insulation used 35 | % ------------------------------- 36 | % Glass wool in the walls, 0.2 m thick 37 | % k is in units of J/sec/m/C - convert to J/hr/m/C multiplying by 3600 38 | kWall = 0.038*3600; % hour is the time unit 39 | LWall = .2; 40 | RWall = LWall/(kWall*wallArea); 41 | % Glass windows, 0.01 m thick 42 | kWindow = 0.78*3600; % hour is the time unit 43 | LWindow = .01; 44 | RWindow = LWindow/(kWindow*windowArea); 45 | % ------------------------------- 46 | % Determine the equivalent thermal resistance for the whole building 47 | % ------------------------------- 48 | Req = RWall*RWindow/(RWall + RWindow); 49 | % c = cp of air (273 K) = 1005.4 J/kg-K 50 | c = 1005.4; 51 | % ------------------------------- 52 | % Enter the temperature of the heated air 53 | % ------------------------------- 54 | % The air exiting the heater has a constant temperature which is a heater 55 | % property. THeater = 50 deg C 56 | THeater = 60; 57 | % Air flow rate Mdot = 1 kg/sec = 3600 kg/hr 58 | Mdot = 3600; % hour is the time unit 59 | % ------------------------------- 60 | % Determine total internal air mass = M 61 | % ------------------------------- 62 | % Density of air at sea level = 1.2250 kg/m^3 63 | densAir = 1.2250; 64 | M = (lenHouse*widHouse*htHouse+tan(pitRoof)*widHouse*lenHouse)*densAir; 65 | % ------------------------------- 66 | % Enter the cost of electricity and initial internal temperature 67 | % ------------------------------- 68 | % Assume the cost of electricity is $0.09 per kilowatt/hour 69 | % Assume all electric energy is transformed to heat energy 70 | % 1 kW-hr = 3.6e6 J 71 | % cost = $0.09 per 3.6e6 J 72 | cost = 0.09/3.6e6; 73 | % TinIC = initial indoor temperature = 20 deg C 74 | TinIC = 10; 75 | --------------------------------------------------------------------------------