├── test.sh ├── train.sh ├── requirements.txt ├── .gitignore ├── docs ├── _build │ ├── html │ │ ├── _static │ │ │ ├── custom.css │ │ │ ├── file.png │ │ │ ├── plus.png │ │ │ ├── minus.png │ │ │ ├── css │ │ │ │ ├── fonts │ │ │ │ │ ├── lato-bold.woff │ │ │ │ │ ├── lato-bold.woff2 │ │ │ │ │ ├── lato-normal.woff │ │ │ │ │ ├── lato-normal.woff2 │ │ │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ │ │ ├── lato-bold-italic.woff │ │ │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ │ ├── lato-bold-italic.woff2 │ │ │ │ │ ├── lato-normal-italic.woff │ │ │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ │ ├── fontawesome-webfont.woff2 │ │ │ │ │ └── lato-normal-italic.woff2 │ │ │ │ └── badge_only.css │ │ │ ├── documentation_options.js │ │ │ ├── js │ │ │ │ ├── badge_only.js │ │ │ │ ├── html5shiv.min.js │ │ │ │ ├── html5shiv-printshiv.min.js │ │ │ │ └── theme.js │ │ │ ├── _sphinx_javascript_frameworks_compat.js │ │ │ ├── pygments.css │ │ │ ├── doctools.js │ │ │ ├── sphinx_highlight.js │ │ │ └── language_data.js │ │ ├── objects.inv │ │ ├── _sources │ │ │ ├── env.rst.txt │ │ │ ├── DDPG.rst.txt │ │ │ ├── main.rst.txt │ │ │ ├── utils.rst.txt │ │ │ ├── buffer.rst.txt │ │ │ ├── matrics.rst.txt │ │ │ ├── ploting.rst.txt │ │ │ ├── random_sa.rst.txt │ │ │ ├── simulator.rst.txt │ │ │ ├── test_trained_agent.rst.txt │ │ │ ├── modules.rst.txt │ │ │ └── index.rst.txt │ │ ├── .buildinfo │ │ ├── search.html │ │ ├── _modules │ │ │ ├── index.html │ │ │ ├── random_sa.html │ │ │ └── matrics.html │ │ ├── test_trained_agent.html │ │ ├── simulator.html │ │ ├── random_sa.html │ │ ├── main.html │ │ ├── index.html │ │ ├── py-modindex.html │ │ ├── matrics.html │ │ ├── buffer.html │ │ └── ploting.html │ └── doctrees │ │ ├── DDPG.doctree │ │ ├── env.doctree │ │ ├── main.doctree │ │ ├── buffer.doctree │ │ ├── index.doctree │ │ ├── matrics.doctree │ │ ├── modules.doctree │ │ ├── ploting.doctree │ │ ├── utils.doctree │ │ ├── random_sa.doctree │ │ ├── simulator.doctree │ │ ├── environment.pickle │ │ └── test_trained_agent.doctree ├── env.rst ├── DDPG.rst ├── main.rst ├── utils.rst ├── buffer.rst ├── matrics.rst ├── ploting.rst ├── random_sa.rst ├── simulator.rst ├── test_trained_agent.rst ├── modules.rst ├── Makefile ├── make.bat ├── conf.py └── index.rst ├── Utils ├── random_sa.py ├── metrics.py └── utils.py ├── DDPG ├── buffer.py └── DDPG.py ├── Simulation └── simulator.py ├── test_trained_agent.py ├── readme.md └── main.py /test.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /train.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # igonore 2 | 3 | __pycache__ 4 | 5 | data -------------------------------------------------------------------------------- /docs/_build/html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /docs/env.rst: -------------------------------------------------------------------------------- 1 | env module 2 | ========== 3 | 4 | .. automodule:: env 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/DDPG.rst: -------------------------------------------------------------------------------- 1 | DDPG module 2 | =========== 3 | 4 | .. automodule:: DDPG 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/main.rst: -------------------------------------------------------------------------------- 1 | main module 2 | =========== 3 | 4 | .. automodule:: main 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/utils.rst: -------------------------------------------------------------------------------- 1 | utils module 2 | ============ 3 | 4 | .. automodule:: utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/buffer.rst: -------------------------------------------------------------------------------- 1 | buffer module 2 | ============= 3 | 4 | .. automodule:: buffer 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/matrics.rst: -------------------------------------------------------------------------------- 1 | matrics module 2 | ============== 3 | 4 | .. automodule:: matrics 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/ploting.rst: -------------------------------------------------------------------------------- 1 | ploting module 2 | ============== 3 | 4 | .. automodule:: ploting 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/doctrees/DDPG.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/DDPG.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/env.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/env.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/main.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/main.doctree -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/doctrees/buffer.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/buffer.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/matrics.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/matrics.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/modules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/modules.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/ploting.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/ploting.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/utils.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/utils.doctree -------------------------------------------------------------------------------- /docs/_build/html/_sources/env.rst.txt: -------------------------------------------------------------------------------- 1 | env module 2 | ========== 3 | 4 | .. automodule:: env 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/random_sa.rst: -------------------------------------------------------------------------------- 1 | random\_sa module 2 | ================= 3 | 4 | .. automodule:: random_sa 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/simulator.rst: -------------------------------------------------------------------------------- 1 | simulator module 2 | ================ 3 | 4 | .. automodule:: simulator 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/doctrees/random_sa.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/random_sa.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/simulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/simulator.doctree -------------------------------------------------------------------------------- /docs/_build/html/_sources/DDPG.rst.txt: -------------------------------------------------------------------------------- 1 | DDPG module 2 | =========== 3 | 4 | .. automodule:: DDPG 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/main.rst.txt: -------------------------------------------------------------------------------- 1 | main module 2 | =========== 3 | 4 | .. automodule:: main 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/html/_sources/utils.rst.txt: -------------------------------------------------------------------------------- 1 | utils module 2 | ============ 3 | 4 | .. automodule:: utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/buffer.rst.txt: -------------------------------------------------------------------------------- 1 | buffer module 2 | ============= 3 | 4 | .. automodule:: buffer 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/matrics.rst.txt: -------------------------------------------------------------------------------- 1 | matrics module 2 | ============== 3 | 4 | .. automodule:: matrics 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/ploting.rst.txt: -------------------------------------------------------------------------------- 1 | ploting module 2 | ============== 3 | 4 | .. automodule:: ploting 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/doctrees/test_trained_agent.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/doctrees/test_trained_agent.doctree -------------------------------------------------------------------------------- /docs/_build/html/_sources/random_sa.rst.txt: -------------------------------------------------------------------------------- 1 | random\_sa module 2 | ================= 3 | 4 | .. automodule:: random_sa 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/simulator.rst.txt: -------------------------------------------------------------------------------- 1 | simulator module 2 | ================ 3 | 4 | .. automodule:: simulator 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /docs/test_trained_agent.rst: -------------------------------------------------------------------------------- 1 | test\_trained\_agent module 2 | =========================== 3 | 4 | .. automodule:: test_trained_agent 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikas-rajpoot/Contorl-CSTR-using-Reinforcement-learning/HEAD/docs/_build/html/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /docs/_build/html/_sources/test_trained_agent.rst.txt: -------------------------------------------------------------------------------- 1 | test\_trained\_agent module 2 | =========================== 3 | 4 | .. automodule:: test_trained_agent 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/modules.rst: -------------------------------------------------------------------------------- 1 | RL_1 2 | ==== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | DDPG 8 | buffer 9 | env 10 | main 11 | matrics 12 | ploting 13 | random_sa 14 | simulator 15 | test_trained_agent 16 | utils 17 | -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 215f65fade843df030dd76ad4eef9e53 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | RL_1 2 | ==== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | DDPG 8 | buffer 9 | env 10 | main 11 | matrics 12 | ploting 13 | random_sa 14 | simulator 15 | test_trained_agent 16 | utils 17 | -------------------------------------------------------------------------------- /Utils/random_sa.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy as np 3 | 4 | def sample_actions(): 5 | F = 5 + random.random() * 95 6 | Q = -1 * random.random() * 8500 7 | 8 | return np.array([F, Q]).reshape(2, ) 9 | 10 | 11 | 12 | def sample_states(): 13 | c_a = 0.1 + random.random() * 1.9 14 | c_b = 0.1 + random.random() * 1.9 15 | t_r = 50 + random.random() * 100 16 | t_k = 50 + random.random() * 90 17 | 18 | return np.array([c_a, c_b, t_r, t_k]).reshape(4, ) 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/_build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '1.0.0', 4 | LANGUAGE: 'en', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false, 12 | SHOW_SEARCH_SUMMARY: true, 13 | ENABLE_SEARCH_SHORTCUTS: true, 14 | }; -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/_build/html/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | # -- Project information ----------------------------------------------------- 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 8 | 9 | 10 | import os 11 | import sys 12 | sys.path.insert(0, os.path.abspath('..')) 13 | 14 | project = 'Reinforcement learning agent to control the CSTR process.' 15 | copyright = '2023, Vikas Rajpoot' 16 | author = 'Vikas Rajpoot' 17 | release = '1.0.0' 18 | 19 | # -- General configuration --------------------------------------------------- 20 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 21 | # 22 | # extensions = [] 23 | 24 | extensions = [ 25 | 'sphinx.ext.autodoc', 26 | 'sphinx.ext.napoleon', 27 | 'sphinx.ext.viewcode', 28 | ] 29 | 30 | templates_path = ['_templates'] 31 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 32 | 33 | # exclude_patterns = [] 34 | 35 | html_theme = 'sphinx_rtd_theme' 36 | 37 | 38 | 39 | # -- Options for HTML output ------------------------------------------------- 40 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 41 | 42 | # html_theme = 'alabaster' 43 | html_static_path = ['_static'] 44 | -------------------------------------------------------------------------------- /DDPG/buffer.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch 3 | import Utils.utils as utils 4 | 5 | class ReplayBuffer(object): 6 | 7 | def __init__(self, state_dim, action_dim, max_size=int(1e6)): 8 | self.max_size = max_size 9 | self.ptr = 0 10 | self.size = 0 11 | 12 | self.state = np.zeros((max_size, state_dim)) 13 | self.action = np.zeros((max_size, action_dim)) 14 | self.next_state = np.zeros((max_size, state_dim)) 15 | self.reward = np.zeros((max_size, 1)) 16 | self.not_done = np.zeros((max_size, 1)) 17 | 18 | self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 19 | 20 | 21 | def add(self, state, action, next_state, reward, done): 22 | self.state[self.ptr] = state 23 | self.action[self.ptr] = action 24 | self.next_state[self.ptr] = next_state 25 | self.reward[self.ptr] = reward 26 | self.not_done[self.ptr] = 1. - done 27 | 28 | self.ptr = (self.ptr + 1) % self.max_size 29 | self.size = min(self.size + 1, self.max_size) 30 | 31 | 32 | def sample(self, batch_size): 33 | ind = np.random.randint(0, self.size, size=batch_size) 34 | 35 | return ( 36 | torch.FloatTensor(self.state[ind]).to(self.device), 37 | torch.FloatTensor(self.action[ind]).to(self.device), 38 | torch.FloatTensor(self.next_state[ind]).to(self.device), 39 | torch.FloatTensor(self.reward[ind]).to(self.device), 40 | torch.FloatTensor(self.not_done[ind]).to(self.device) 41 | ) 42 | 43 | def save_buffer(self): 44 | buffer_data = np.concatenate([self.state, self.action, self.reward, 45 | self.next_state, self.not_done], axis=1) 46 | 47 | file = utils.global_dir + '/data/buffer_data.csv' 48 | np.savetxt(file, buffer_data, delimiter=',') 49 | -------------------------------------------------------------------------------- /Simulation/simulator.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from math import exp 3 | from scipy.integrate import odeint 4 | 5 | 6 | def cstr_dynamics(ti,tf,y01, y02, y03, y04, F, Q_dot): 7 | 8 | def func(y,t): 9 | # parameters 10 | K0_ab = 1.287e12 # K0 [h^-1] 11 | K0_bc = 1.287e12 # K0 [h^-1] 12 | K0_ad = 9.043e9 # K0 [l/mol.h] 13 | R_gas = 8.3144621e-3 # Universal gas constant 14 | E_A_ab = 9758.3*1.00 #* R_gas# [kj/mol] 15 | E_A_bc = 9758.3*1.00 #* R_gas# [kj/mol] 16 | E_A_ad = 8560.0*1.0 #* R_gas# [kj/mol] 17 | H_R_ab = 4.2 # [kj/mol A] 18 | H_R_bc = -11.0 # [kj/mol B] Exothermic 19 | H_R_ad = -41.85 # [kj/mol A] Exothermic 20 | Rou = 0.9342 # Density [kg/l] 21 | Cp = 3.01 # Specific Heat capacity [kj/Kg.K] 22 | Cp_k = 2.0 # Coolant heat capacity [kj/kg.k] 23 | A_R = 0.215 # Area of reactor wall [m^2] 24 | V_R = 10.01 #0.01 # Volume of reactor [l] 25 | m_k = 5.0 # Coolant mass[kg] 26 | T_in = 130.0 # Temp of inflow [Celsius] 27 | K_w = 4032.0 # [kj/h.m^2.K] 28 | C_A0 = (5.7+4.5)/2.0*1.0 # Concentration of A in input Upper bound 5.7 lower bound 4.5 [mol/l] 29 | #beta = 0.9 30 | #alpha = 0.95 31 | beta = 1 32 | alpha = 1 33 | dydt1 = F*(C_A0 - y[0]) -(beta * K0_ab * exp((-E_A_ab)/((y[2]+273.15))))*y[0] - (K0_ad * exp((-alpha*E_A_ad)/((y[2]+273.15))) )*(y[0]**2) 34 | dydt2 = -F*y[1] + (beta * K0_ab * exp((-E_A_ab)/((y[2]+273.15))))*y[0] - (K0_bc * exp((-E_A_bc)/((y[2]+273.15))))*y[1] 35 | dydt3 = (((beta * K0_ab * exp((-E_A_ab)/((y[2]+273.15))))*y[0]*H_R_ab + (K0_bc * exp((-E_A_bc)/((y[2]+273.15))))*y[1]*H_R_bc + (K0_ad * exp((-alpha*E_A_ad)/((y[2]+273.15))))*(y[0]**2)*H_R_ad)/(-Rou*Cp)) + F*(T_in-y[2]) +((K_w*A_R*(y[3]-y[2]))/(Rou*Cp*V_R)) 36 | dydt4 = (Q_dot + K_w*A_R*(y[2]-y[3]))/(m_k*Cp_k) 37 | return [dydt1,dydt2,dydt3,dydt4] 38 | 39 | 40 | #Initial Conditions 41 | # tf = ti + 0.005 42 | y0 = np.zeros((4,1)) 43 | y0[0] = y01 44 | y0[1] = y02 45 | y0[2] = y03 46 | y0[3] = y04 47 | y0 = [y01, y02, y03, y04] 48 | t = np.linspace(ti,tf) # tspan 49 | 50 | y = odeint(func, y0, t) # solver 51 | 52 | y = y[-1] 53 | 54 | return y 55 | 56 | -------------------------------------------------------------------------------- /Utils/metrics.py: -------------------------------------------------------------------------------- 1 | import Utils.utils as utils 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | def plot_series(series, title, xlabel, ylabel, file): 6 | """ 7 | """ 8 | x = list(range(500, len(series)+500)) 9 | plt.figure(figsize=(10, 6)) 10 | plt.xticks(fontsize=16) 11 | plt.yticks(fontsize=16) 12 | plt.title(title, fontsize=24) 13 | plt.xlabel(xlabel, fontsize=24) 14 | plt.ylabel(ylabel, fontsize=24) 15 | plt.plot(x, series) 16 | plt.savefig(file) 17 | plt.close() 18 | 19 | 20 | def plot_sliding_mean(data, window, titile, xlabel, ylabel, file): 21 | 22 | m_cl = [] 23 | for i in range(0, len(data)-window): 24 | # print(i) 25 | me = sum(data[i:i+window])/window 26 | m_cl.append(me) 27 | 28 | 29 | plot_series(m_cl, titile, xlabel, ylabel, file) 30 | 31 | 32 | if __name__=="__main__": 33 | 34 | file1 = utils.global_dir + '/data/mat/reward_list.csv' 35 | file2 = utils.global_dir + '/data/mat/actor_loss 17.csv' 36 | file3 = utils.global_dir + '/data/mat/critic_loss17.csv' 37 | # file4 = utils.global_dir + '/data/mat/ep_len.csv' 38 | 39 | reward = np.loadtxt(file1, delimiter=',') 40 | actor_loss = np.loadtxt(file2, delimiter=',') 41 | critic_loss = np.loadtxt(file3, delimiter=',') 42 | # ep_len = np.loadtxt(file4, delimiter=',') 43 | 44 | 45 | reward = reward[511:-10] 46 | critic_loss = critic_loss[100:-1000000] 47 | actor_loss = actor_loss[100:-1000000] 48 | 49 | 50 | file1 = utils.global_dir + '/data/mat/reward_list.png' 51 | file2 = utils.global_dir + '/data/mat/actor_loss.png' 52 | file3 = utils.global_dir + '/data/mat/critic_loss.png' 53 | # file4 = utils.global_dir + '/data/mat/ep_len.png' 54 | 55 | plot_series(reward, 'Reward', 'episode ', 'reward', file1) 56 | plot_series(actor_loss, 'Actor loss', 'number of updates ', 'actor loss', file2) 57 | plot_series(critic_loss, 'critic loss', 'number of updates ', 'critic loss', file3) 58 | # # plot_series(ep_len, 'ep length', 'episode ', 'ep length', file4) 59 | 60 | # window = 10 61 | # plot_sliding_mean(reward, window, 'Reward', 'episode ', 'reward', file1) 62 | # plot_sliding_mean(actor_loss, window, 'Actor loss', 'episode ', 'actor loss', file2) 63 | 64 | # window = 500 65 | # plot_sliding_mean(critic_loss, window, 'critic loss', 'episode ', 'critic loss', file3) 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /docs/_build/html/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. Stable Baselines3 documentation master file, created by 2 | sphinx-quickstart on Thu Sep 26 11:06:54 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Stable-Baselines3 Docs - Reliable Reinforcement Learning Implementations 7 | ======================================================================== 8 | 9 | `Stable Baselines3 (SB3) `_ is a set of reliable implementations of reinforcement learning algorithms in PyTorch. 10 | It is the next major version of `Stable Baselines `_. 11 | 12 | 13 | Github repository: https://github.com/DLR-RM/stable-baselines3 14 | 15 | Paper: https://jmlr.org/papers/volume22/20-1364/20-1364.pdf 16 | 17 | RL Baselines3 Zoo (training framework for SB3): https://github.com/DLR-RM/rl-baselines3-zoo 18 | 19 | RL Baselines3 Zoo provides a collection of pre-trained agents, scripts for training, evaluating agents, tuning hyperparameters, plotting results and recording videos. 20 | 21 | SB3 Contrib (experimental RL code, latest algorithms): https://github.com/Stable-Baselines-Team/stable-baselines3-contrib 22 | 23 | 24 | Main Features 25 | -------------- 26 | 27 | - Unified structure for all algorithms 28 | - PEP8 compliant (unified code style) 29 | - Documented functions and classes 30 | - Tests, high code coverage and type hints 31 | - Clean code 32 | - Tensorboard support 33 | - **The performance of each algorithm was tested** (see *Results* section in their respective page) 34 | 35 | 36 | .. toctree:: 37 | :maxdepth: 2 38 | :caption: User Guide 39 | 40 | modules 41 | 42 | 43 | 44 | 45 | .. Citing Stable Baselines3 46 | .. ------------------------ 47 | .. To cite this project in publications: 48 | 49 | .. .. code-block:: bibtex 50 | 51 | .. @article{stable-baselines3, 52 | .. author = {Antonin Raffin and Ashley Hill and Adam Gleave and Anssi Kanervisto and Maximilian Ernestus and Noah Dormann}, 53 | .. title = {Stable-Baselines3: Reliable Reinforcement Learning Implementations}, 54 | .. journal = {Journal of Machine Learning Research}, 55 | .. year = {2021}, 56 | .. volume = {22}, 57 | .. number = {268}, 58 | .. pages = {1-8}, 59 | .. url = {http://jmlr.org/papers/v22/20-1364.html} 60 | .. } 61 | 62 | .. Contributing 63 | .. ------------ 64 | 65 | .. To any interested in making the rl baselines better, there are still some improvements 66 | .. that need to be done. 67 | .. You can check issues in the `repo `_. 68 | 69 | .. If you want to contribute, please read `CONTRIBUTING.md `_ first. 70 | 71 | .. Indices and tables 72 | .. ------------------- 73 | 74 | * :ref:`genindex` 75 | * :ref:`search` 76 | * :ref:`modindex` 77 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. Stable Baselines3 documentation master file, created by 2 | sphinx-quickstart on Thu Sep 26 11:06:54 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Stable-Baselines3 Docs - Reliable Reinforcement Learning Implementations 7 | ======================================================================== 8 | 9 | `Stable Baselines3 (SB3) `_ is a set of reliable implementations of reinforcement learning algorithms in PyTorch. 10 | It is the next major version of `Stable Baselines `_. 11 | 12 | 13 | Github repository: https://github.com/DLR-RM/stable-baselines3 14 | 15 | Paper: https://jmlr.org/papers/volume22/20-1364/20-1364.pdf 16 | 17 | RL Baselines3 Zoo (training framework for SB3): https://github.com/DLR-RM/rl-baselines3-zoo 18 | 19 | RL Baselines3 Zoo provides a collection of pre-trained agents, scripts for training, evaluating agents, tuning hyperparameters, plotting results and recording videos. 20 | 21 | SB3 Contrib (experimental RL code, latest algorithms): https://github.com/Stable-Baselines-Team/stable-baselines3-contrib 22 | 23 | 24 | Main Features 25 | -------------- 26 | 27 | - Unified structure for all algorithms 28 | - PEP8 compliant (unified code style) 29 | - Documented functions and classes 30 | - Tests, high code coverage and type hints 31 | - Clean code 32 | - Tensorboard support 33 | - **The performance of each algorithm was tested** (see *Results* section in their respective page) 34 | 35 | 36 | .. toctree:: 37 | :maxdepth: 2 38 | :caption: User Guide 39 | 40 | modules 41 | 42 | 43 | 44 | 45 | .. Citing Stable Baselines3 46 | .. ------------------------ 47 | .. To cite this project in publications: 48 | 49 | .. .. code-block:: bibtex 50 | 51 | .. @article{stable-baselines3, 52 | .. author = {Antonin Raffin and Ashley Hill and Adam Gleave and Anssi Kanervisto and Maximilian Ernestus and Noah Dormann}, 53 | .. title = {Stable-Baselines3: Reliable Reinforcement Learning Implementations}, 54 | .. journal = {Journal of Machine Learning Research}, 55 | .. year = {2021}, 56 | .. volume = {22}, 57 | .. number = {268}, 58 | .. pages = {1-8}, 59 | .. url = {http://jmlr.org/papers/v22/20-1364.html} 60 | .. } 61 | 62 | .. Contributing 63 | .. ------------ 64 | 65 | .. To any interested in making the rl baselines better, there are still some improvements 66 | .. that need to be done. 67 | .. You can check issues in the `repo `_. 68 | 69 | .. If you want to contribute, please read `CONTRIBUTING.md `_ first. 70 | 71 | .. Indices and tables 72 | .. ------------------- 73 | 74 | * :ref:`genindex` 75 | * :ref:`search` 76 | * :ref:`modindex` 77 | -------------------------------------------------------------------------------- /docs/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} -------------------------------------------------------------------------------- /test_trained_agent.py: -------------------------------------------------------------------------------- 1 | import DDPG.DDPG as dg 2 | import Env.env as e 3 | import Utils.utils as utils 4 | import numpy as np 5 | import Utils.ploting as ploting 6 | import time 7 | 8 | 9 | def closed_loop_simulation_rl(): 10 | 11 | """ 12 | Function is used to test trained RL agent (actor network) which is saved in the folder ./data/models/.., 13 | 14 | It saves the states and action in the ./data/test_data/.., and plot in the ./data/test_plots/.. :::: 15 | """ 16 | 17 | cstr = e.cstr_env() 18 | 19 | state_dim = cstr.observation_space.shape[0] 20 | action_dim = cstr.action_space.shape[0] 21 | 22 | ddpg = dg.DDPG(state_dim, action_dim) 23 | 24 | dir = utils.global_dir + '/data' 25 | 26 | ddpg.load(dir, 17) 27 | 28 | states = [] 29 | actions = [] 30 | 31 | start = time.time() 32 | for ep in range(0, 1): 33 | 34 | print("running..", ep) 35 | 36 | obs, _ = cstr.reset() 37 | states.clear() 38 | actions.clear() 39 | 40 | scaled_states = [] 41 | scaled_action = [] 42 | 43 | for itr in range(500): 44 | 45 | scaled_states.append(obs) 46 | 47 | s = obs[:4] 48 | 49 | s_t = utils.reverse_normalize_minmax_states(s) 50 | 51 | error = utils.reverse_normalize_minmax_error(np.array(obs[4])) 52 | ierror = utils.reverse_normalize_minmax_ierror(np.array(obs[5])) 53 | 54 | o_obs = np.concatenate([s_t, error, ierror]) 55 | # print(o_obs) 56 | 57 | states.append(o_obs) 58 | 59 | 60 | a = ddpg.select_action(obs) 61 | scaled_action.append(a) 62 | 63 | # next_state, reward, terminated, trancate, _ 64 | obs, rewards, done, tranc, _ = cstr.step(a) 65 | 66 | a = utils.reverse_normalize_minmax_actions(a) 67 | # s = utils.reverse_normalize_minmax_states(s) 68 | 69 | actions.append(a) 70 | 71 | # actions.append(a) 72 | # states.append(s) 73 | 74 | # if done: 75 | # break 76 | 77 | end = time.time() 78 | 79 | time_in_second = (end - start) 80 | time_in_min = time_in_second/60 81 | 82 | print("time in seconds : ", time_in_second ) 83 | print("time in minutes : ", time_in_min ) 84 | 85 | 86 | file_name = './data/time_rl'+'.txt' 87 | with open(file_name, 'w') as file: 88 | file.write("time in seconds :" + str(round(time_in_second, 2))) 89 | file.write("\ntime in minutes :" + str(round(time_in_min, 2))) 90 | 91 | Xk = np.array(states) 92 | Uk = np.array(actions) 93 | 94 | file1 = utils.global_dir + "/data/test_data/xk" + str(ep) + ".csv" 95 | file2 = utils.global_dir + "/data/test_data/uk" + str(ep)+ ".csv" 96 | 97 | np.savetxt(file1, Xk, delimiter=',') 98 | np.savetxt(file2, Uk, delimiter=',') 99 | 100 | 101 | file3 = utils.global_dir + "/data/test_plots/fig_" + str(ep) + '.jpg' 102 | 103 | Xk = Xk[:, [0, 1, 2, 3]] 104 | ploting.plot_rl_comparision(Xk, Uk, ep, file3) 105 | 106 | Xk = np.array(scaled_states) 107 | Uk = np.array(scaled_action) 108 | 109 | 110 | # file1 = utils.global_dir + "/data/test_data/s_xk" + str(ep) + ".csv" 111 | # file2 = utils.global_dir + "/data/test_data/s_uk" + str(ep)+ ".csv" 112 | 113 | # np.savetxt(file1, Xk, delimiter=',') 114 | # np.savetxt(file2, Uk, delimiter=',') 115 | 116 | 117 | 118 | if __name__=="__main__": 119 | closed_loop_simulation_rl() 120 | -------------------------------------------------------------------------------- /docs/_build/html/_static/js/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Search — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 53 | 54 |
58 | 59 |
60 |
61 |
62 |
    63 |
  • 64 | 65 |
  • 66 |
  • 67 |
68 |
69 |
70 |
71 |
72 | 73 | 80 | 81 | 82 |
83 | 84 |
85 | 86 |
87 |
88 |
89 | 90 |
91 | 92 |
93 |

© Copyright 2023, Vikas Rajpoot.

94 |
95 | 96 | Built with Sphinx using a 97 | theme 98 | provided by Read the Docs. 99 | 100 | 101 |
102 |
103 |
104 |
105 |
106 | 111 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /docs/_build/html/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview: module code — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 50 | 51 |
55 | 56 |
57 |
58 |
59 |
    60 |
  • 61 | 62 |
  • 63 |
  • 64 |
65 |
66 |
67 |
68 |
69 | 70 |

All modules for which code is available

71 | 82 | 83 |
84 |
85 |
86 | 87 |
88 | 89 |
90 |

© Copyright 2023, Vikas Rajpoot.

91 |
92 | 93 | Built with Sphinx using a 94 | theme 95 | provided by Read the Docs. 96 | 97 | 98 |
99 |
100 |
101 |
102 |
103 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/_build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | !function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){t(1),n.exports=t(3)},function(n,e,t){(function(){var e="undefined"!=typeof window?window.jQuery:t(2);n.exports.ThemeNav={navBar:null,win:null,winScroll:!1,winResize:!1,linkScroll:!1,winPosition:0,winHeight:null,docHeight:null,isRunning:!1,enable:function(n){var t=this;void 0===n&&(n=!0),t.isRunning||(t.isRunning=!0,e((function(e){t.init(e),t.reset(),t.win.on("hashchange",t.reset),n&&t.win.on("scroll",(function(){t.linkScroll||t.winScroll||(t.winScroll=!0,requestAnimationFrame((function(){t.onScroll()})))})),t.win.on("resize",(function(){t.winResize||(t.winResize=!0,requestAnimationFrame((function(){t.onResize()})))})),t.onResize()})))},enableSticky:function(){this.enable(!0)},init:function(n){n(document);var e=this;this.navBar=n("div.wy-side-scroll:first"),this.win=n(window),n(document).on("click","[data-toggle='wy-nav-top']",(function(){n("[data-toggle='wy-nav-shift']").toggleClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift")})).on("click",".wy-menu-vertical .current ul li a",(function(){var t=n(this);n("[data-toggle='wy-nav-shift']").removeClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift"),e.toggleCurrent(t),e.hashChange()})).on("click","[data-toggle='rst-current-version']",(function(){n("[data-toggle='rst-versions']").toggleClass("shift-up")})),n("table.docutils:not(.field-list,.footnote,.citation)").wrap("
"),n("table.docutils.footnote").wrap("
"),n("table.docutils.citation").wrap("
"),n(".wy-menu-vertical ul").not(".simple").siblings("a").each((function(){var t=n(this);expand=n(''),expand.on("click",(function(n){return e.toggleCurrent(t),n.stopPropagation(),!1})),t.prepend(expand)}))},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),t=e.find('[href="'+n+'"]');if(0===t.length){var i=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(t=e.find('[href="#'+i.attr("id")+'"]')).length&&(t=e.find('[href="#"]'))}if(t.length>0){$(".wy-menu-vertical .current").removeClass("current").attr("aria-expanded","false"),t.addClass("current").attr("aria-expanded","true"),t.closest("li.toctree-l1").parent().addClass("current").attr("aria-expanded","true");for(let n=1;n<=10;n++)t.closest("li.toctree-l"+n).addClass("current").attr("aria-expanded","true");t[0].scrollIntoView()}}catch(n){console.log("Error expanding nav for anchor",n)}},onScroll:function(){this.winScroll=!1;var n=this.win.scrollTop(),e=n+this.winHeight,t=this.navBar.scrollTop()+(n-this.winPosition);n<0||e>this.docHeight||(this.navBar.scrollTop(t),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",(function(){this.linkScroll=!1}))},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current").attr("aria-expanded","false"),e.siblings().find("li.current").removeClass("current").attr("aria-expanded","false");var t=e.find("> ul li");t.length&&(t.removeClass("current").attr("aria-expanded","false"),e.toggleClass("current").attr("aria-expanded",(function(n,e){return"true"==e?"false":"true"})))}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:n.exports.ThemeNav,StickyNav:n.exports.ThemeNav}),function(){for(var n=0,e=["ms","moz","webkit","o"],t=0;t= 0 && 56 | !jQuery(node.parentNode).hasClass(className) && 57 | !jQuery(node.parentNode).hasClass("nohighlight")) { 58 | var span; 59 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 60 | if (isInSVG) { 61 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 62 | } else { 63 | span = document.createElement("span"); 64 | span.className = className; 65 | } 66 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 67 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 68 | document.createTextNode(val.substr(pos + text.length)), 69 | node.nextSibling)); 70 | node.nodeValue = val.substr(0, pos); 71 | if (isInSVG) { 72 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 73 | var bbox = node.parentElement.getBBox(); 74 | rect.x.baseVal.value = bbox.x; 75 | rect.y.baseVal.value = bbox.y; 76 | rect.width.baseVal.value = bbox.width; 77 | rect.height.baseVal.value = bbox.height; 78 | rect.setAttribute('class', className); 79 | addItems.push({ 80 | "parent": node.parentNode, 81 | "target": rect}); 82 | } 83 | } 84 | } 85 | else if (!jQuery(node).is("button, select, textarea")) { 86 | jQuery.each(node.childNodes, function() { 87 | highlight(this, addItems); 88 | }); 89 | } 90 | } 91 | var addItems = []; 92 | var result = this.each(function() { 93 | highlight(this, addItems); 94 | }); 95 | for (var i = 0; i < addItems.length; ++i) { 96 | jQuery(addItems[i].parent).before(addItems[i].target); 97 | } 98 | return result; 99 | }; 100 | 101 | /* 102 | * backward compatibility for jQuery.browser 103 | * This will be supported until firefox bug is fixed. 104 | */ 105 | if (!jQuery.browser) { 106 | jQuery.uaMatch = function(ua) { 107 | ua = ua.toLowerCase(); 108 | 109 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 110 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 111 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 112 | /(msie) ([\w.]+)/.exec(ua) || 113 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 114 | []; 115 | 116 | return { 117 | browser: match[ 1 ] || "", 118 | version: match[ 2 ] || "0" 119 | }; 120 | }; 121 | jQuery.browser = {}; 122 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 123 | } 124 | -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #f8f8f8; } 8 | .highlight .c { color: #3D7B7B; font-style: italic } /* Comment */ 9 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 10 | .highlight .k { color: #008000; font-weight: bold } /* Keyword */ 11 | .highlight .o { color: #666666 } /* Operator */ 12 | .highlight .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */ 13 | .highlight .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */ 14 | .highlight .cp { color: #9C6500 } /* Comment.Preproc */ 15 | .highlight .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */ 16 | .highlight .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */ 17 | .highlight .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */ 18 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 19 | .highlight .ge { font-style: italic } /* Generic.Emph */ 20 | .highlight .gr { color: #E40000 } /* Generic.Error */ 21 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 22 | .highlight .gi { color: #008400 } /* Generic.Inserted */ 23 | .highlight .go { color: #717171 } /* Generic.Output */ 24 | .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 25 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 26 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 27 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 28 | .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ 29 | .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ 30 | .highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */ 31 | .highlight .kp { color: #008000 } /* Keyword.Pseudo */ 32 | .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ 33 | .highlight .kt { color: #B00040 } /* Keyword.Type */ 34 | .highlight .m { color: #666666 } /* Literal.Number */ 35 | .highlight .s { color: #BA2121 } /* Literal.String */ 36 | .highlight .na { color: #687822 } /* Name.Attribute */ 37 | .highlight .nb { color: #008000 } /* Name.Builtin */ 38 | .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 39 | .highlight .no { color: #880000 } /* Name.Constant */ 40 | .highlight .nd { color: #AA22FF } /* Name.Decorator */ 41 | .highlight .ni { color: #717171; font-weight: bold } /* Name.Entity */ 42 | .highlight .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */ 43 | .highlight .nf { color: #0000FF } /* Name.Function */ 44 | .highlight .nl { color: #767600 } /* Name.Label */ 45 | .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 46 | .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ 47 | .highlight .nv { color: #19177C } /* Name.Variable */ 48 | .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 49 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 50 | .highlight .mb { color: #666666 } /* Literal.Number.Bin */ 51 | .highlight .mf { color: #666666 } /* Literal.Number.Float */ 52 | .highlight .mh { color: #666666 } /* Literal.Number.Hex */ 53 | .highlight .mi { color: #666666 } /* Literal.Number.Integer */ 54 | .highlight .mo { color: #666666 } /* Literal.Number.Oct */ 55 | .highlight .sa { color: #BA2121 } /* Literal.String.Affix */ 56 | .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ 57 | .highlight .sc { color: #BA2121 } /* Literal.String.Char */ 58 | .highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */ 59 | .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ 60 | .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ 61 | .highlight .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */ 62 | .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ 63 | .highlight .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */ 64 | .highlight .sx { color: #008000 } /* Literal.String.Other */ 65 | .highlight .sr { color: #A45A77 } /* Literal.String.Regex */ 66 | .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ 67 | .highlight .ss { color: #19177C } /* Literal.String.Symbol */ 68 | .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ 69 | .highlight .fm { color: #0000FF } /* Name.Function.Magic */ 70 | .highlight .vc { color: #19177C } /* Name.Variable.Class */ 71 | .highlight .vg { color: #19177C } /* Name.Variable.Global */ 72 | .highlight .vi { color: #19177C } /* Name.Variable.Instance */ 73 | .highlight .vm { color: #19177C } /* Name.Variable.Magic */ 74 | .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Base JavaScript utilities for all Sphinx HTML documentation. 6 | * 7 | * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | "use strict"; 12 | 13 | const BLACKLISTED_KEY_CONTROL_ELEMENTS = new Set([ 14 | "TEXTAREA", 15 | "INPUT", 16 | "SELECT", 17 | "BUTTON", 18 | ]); 19 | 20 | const _ready = (callback) => { 21 | if (document.readyState !== "loading") { 22 | callback(); 23 | } else { 24 | document.addEventListener("DOMContentLoaded", callback); 25 | } 26 | }; 27 | 28 | /** 29 | * Small JavaScript module for the documentation. 30 | */ 31 | const Documentation = { 32 | init: () => { 33 | Documentation.initDomainIndexTable(); 34 | Documentation.initOnKeyListeners(); 35 | }, 36 | 37 | /** 38 | * i18n support 39 | */ 40 | TRANSLATIONS: {}, 41 | PLURAL_EXPR: (n) => (n === 1 ? 0 : 1), 42 | LOCALE: "unknown", 43 | 44 | // gettext and ngettext don't access this so that the functions 45 | // can safely bound to a different name (_ = Documentation.gettext) 46 | gettext: (string) => { 47 | const translated = Documentation.TRANSLATIONS[string]; 48 | switch (typeof translated) { 49 | case "undefined": 50 | return string; // no translation 51 | case "string": 52 | return translated; // translation exists 53 | default: 54 | return translated[0]; // (singular, plural) translation tuple exists 55 | } 56 | }, 57 | 58 | ngettext: (singular, plural, n) => { 59 | const translated = Documentation.TRANSLATIONS[singular]; 60 | if (typeof translated !== "undefined") 61 | return translated[Documentation.PLURAL_EXPR(n)]; 62 | return n === 1 ? singular : plural; 63 | }, 64 | 65 | addTranslations: (catalog) => { 66 | Object.assign(Documentation.TRANSLATIONS, catalog.messages); 67 | Documentation.PLURAL_EXPR = new Function( 68 | "n", 69 | `return (${catalog.plural_expr})` 70 | ); 71 | Documentation.LOCALE = catalog.locale; 72 | }, 73 | 74 | /** 75 | * helper function to focus on search bar 76 | */ 77 | focusSearchBar: () => { 78 | document.querySelectorAll("input[name=q]")[0]?.focus(); 79 | }, 80 | 81 | /** 82 | * Initialise the domain index toggle buttons 83 | */ 84 | initDomainIndexTable: () => { 85 | const toggler = (el) => { 86 | const idNumber = el.id.substr(7); 87 | const toggledRows = document.querySelectorAll(`tr.cg-${idNumber}`); 88 | if (el.src.substr(-9) === "minus.png") { 89 | el.src = `${el.src.substr(0, el.src.length - 9)}plus.png`; 90 | toggledRows.forEach((el) => (el.style.display = "none")); 91 | } else { 92 | el.src = `${el.src.substr(0, el.src.length - 8)}minus.png`; 93 | toggledRows.forEach((el) => (el.style.display = "")); 94 | } 95 | }; 96 | 97 | const togglerElements = document.querySelectorAll("img.toggler"); 98 | togglerElements.forEach((el) => 99 | el.addEventListener("click", (event) => toggler(event.currentTarget)) 100 | ); 101 | togglerElements.forEach((el) => (el.style.display = "")); 102 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) togglerElements.forEach(toggler); 103 | }, 104 | 105 | initOnKeyListeners: () => { 106 | // only install a listener if it is really needed 107 | if ( 108 | !DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS && 109 | !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS 110 | ) 111 | return; 112 | 113 | document.addEventListener("keydown", (event) => { 114 | // bail for input elements 115 | if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; 116 | // bail with special keys 117 | if (event.altKey || event.ctrlKey || event.metaKey) return; 118 | 119 | if (!event.shiftKey) { 120 | switch (event.key) { 121 | case "ArrowLeft": 122 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 123 | 124 | const prevLink = document.querySelector('link[rel="prev"]'); 125 | if (prevLink && prevLink.href) { 126 | window.location.href = prevLink.href; 127 | event.preventDefault(); 128 | } 129 | break; 130 | case "ArrowRight": 131 | if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) break; 132 | 133 | const nextLink = document.querySelector('link[rel="next"]'); 134 | if (nextLink && nextLink.href) { 135 | window.location.href = nextLink.href; 136 | event.preventDefault(); 137 | } 138 | break; 139 | } 140 | } 141 | 142 | // some keyboard layouts may need Shift to get / 143 | switch (event.key) { 144 | case "/": 145 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) break; 146 | Documentation.focusSearchBar(); 147 | event.preventDefault(); 148 | } 149 | }); 150 | }, 151 | }; 152 | 153 | // quick alias for translations 154 | const _ = Documentation.gettext; 155 | 156 | _ready(Documentation.init); 157 | -------------------------------------------------------------------------------- /docs/_build/html/_static/sphinx_highlight.js: -------------------------------------------------------------------------------- 1 | /* Highlighting utilities for Sphinx HTML documentation. */ 2 | "use strict"; 3 | 4 | const SPHINX_HIGHLIGHT_ENABLED = true 5 | 6 | /** 7 | * highlight a given string on a node by wrapping it in 8 | * span elements with the given class name. 9 | */ 10 | const _highlight = (node, addItems, text, className) => { 11 | if (node.nodeType === Node.TEXT_NODE) { 12 | const val = node.nodeValue; 13 | const parent = node.parentNode; 14 | const pos = val.toLowerCase().indexOf(text); 15 | if ( 16 | pos >= 0 && 17 | !parent.classList.contains(className) && 18 | !parent.classList.contains("nohighlight") 19 | ) { 20 | let span; 21 | 22 | const closestNode = parent.closest("body, svg, foreignObject"); 23 | const isInSVG = closestNode && closestNode.matches("svg"); 24 | if (isInSVG) { 25 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 26 | } else { 27 | span = document.createElement("span"); 28 | span.classList.add(className); 29 | } 30 | 31 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 32 | parent.insertBefore( 33 | span, 34 | parent.insertBefore( 35 | document.createTextNode(val.substr(pos + text.length)), 36 | node.nextSibling 37 | ) 38 | ); 39 | node.nodeValue = val.substr(0, pos); 40 | 41 | if (isInSVG) { 42 | const rect = document.createElementNS( 43 | "http://www.w3.org/2000/svg", 44 | "rect" 45 | ); 46 | const bbox = parent.getBBox(); 47 | rect.x.baseVal.value = bbox.x; 48 | rect.y.baseVal.value = bbox.y; 49 | rect.width.baseVal.value = bbox.width; 50 | rect.height.baseVal.value = bbox.height; 51 | rect.setAttribute("class", className); 52 | addItems.push({ parent: parent, target: rect }); 53 | } 54 | } 55 | } else if (node.matches && !node.matches("button, select, textarea")) { 56 | node.childNodes.forEach((el) => _highlight(el, addItems, text, className)); 57 | } 58 | }; 59 | const _highlightText = (thisNode, text, className) => { 60 | let addItems = []; 61 | _highlight(thisNode, addItems, text, className); 62 | addItems.forEach((obj) => 63 | obj.parent.insertAdjacentElement("beforebegin", obj.target) 64 | ); 65 | }; 66 | 67 | /** 68 | * Small JavaScript module for the documentation. 69 | */ 70 | const SphinxHighlight = { 71 | 72 | /** 73 | * highlight the search words provided in localstorage in the text 74 | */ 75 | highlightSearchWords: () => { 76 | if (!SPHINX_HIGHLIGHT_ENABLED) return; // bail if no highlight 77 | 78 | // get and clear terms from localstorage 79 | const url = new URL(window.location); 80 | const highlight = 81 | localStorage.getItem("sphinx_highlight_terms") 82 | || url.searchParams.get("highlight") 83 | || ""; 84 | localStorage.removeItem("sphinx_highlight_terms") 85 | url.searchParams.delete("highlight"); 86 | window.history.replaceState({}, "", url); 87 | 88 | // get individual terms from highlight string 89 | const terms = highlight.toLowerCase().split(/\s+/).filter(x => x); 90 | if (terms.length === 0) return; // nothing to do 91 | 92 | // There should never be more than one element matching "div.body" 93 | const divBody = document.querySelectorAll("div.body"); 94 | const body = divBody.length ? divBody[0] : document.querySelector("body"); 95 | window.setTimeout(() => { 96 | terms.forEach((term) => _highlightText(body, term, "highlighted")); 97 | }, 10); 98 | 99 | const searchBox = document.getElementById("searchbox"); 100 | if (searchBox === null) return; 101 | searchBox.appendChild( 102 | document 103 | .createRange() 104 | .createContextualFragment( 105 | '" 109 | ) 110 | ); 111 | }, 112 | 113 | /** 114 | * helper function to hide the search marks again 115 | */ 116 | hideSearchWords: () => { 117 | document 118 | .querySelectorAll("#searchbox .highlight-link") 119 | .forEach((el) => el.remove()); 120 | document 121 | .querySelectorAll("span.highlighted") 122 | .forEach((el) => el.classList.remove("highlighted")); 123 | localStorage.removeItem("sphinx_highlight_terms") 124 | }, 125 | 126 | initEscapeListener: () => { 127 | // only install a listener if it is really needed 128 | if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) return; 129 | 130 | document.addEventListener("keydown", (event) => { 131 | // bail for input elements 132 | if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; 133 | // bail with special keys 134 | if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return; 135 | if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) { 136 | SphinxHighlight.hideSearchWords(); 137 | event.preventDefault(); 138 | } 139 | }); 140 | }, 141 | }; 142 | 143 | _ready(SphinxHighlight.highlightSearchWords); 144 | _ready(SphinxHighlight.initEscapeListener); 145 | -------------------------------------------------------------------------------- /docs/_build/html/_static/language_data.js: -------------------------------------------------------------------------------- 1 | /* 2 | * language_data.js 3 | * ~~~~~~~~~~~~~~~~ 4 | * 5 | * This script contains the language-specific data used by searchtools.js, 6 | * namely the list of stopwords, stemmer, scorer and splitter. 7 | * 8 | * :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS. 9 | * :license: BSD, see LICENSE for details. 10 | * 11 | */ 12 | 13 | var stopwords = ["a", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "near", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]; 14 | 15 | 16 | /* Non-minified version is copied as a separate JS file, is available */ 17 | 18 | /** 19 | * Porter Stemmer 20 | */ 21 | var Stemmer = function() { 22 | 23 | var step2list = { 24 | ational: 'ate', 25 | tional: 'tion', 26 | enci: 'ence', 27 | anci: 'ance', 28 | izer: 'ize', 29 | bli: 'ble', 30 | alli: 'al', 31 | entli: 'ent', 32 | eli: 'e', 33 | ousli: 'ous', 34 | ization: 'ize', 35 | ation: 'ate', 36 | ator: 'ate', 37 | alism: 'al', 38 | iveness: 'ive', 39 | fulness: 'ful', 40 | ousness: 'ous', 41 | aliti: 'al', 42 | iviti: 'ive', 43 | biliti: 'ble', 44 | logi: 'log' 45 | }; 46 | 47 | var step3list = { 48 | icate: 'ic', 49 | ative: '', 50 | alize: 'al', 51 | iciti: 'ic', 52 | ical: 'ic', 53 | ful: '', 54 | ness: '' 55 | }; 56 | 57 | var c = "[^aeiou]"; // consonant 58 | var v = "[aeiouy]"; // vowel 59 | var C = c + "[^aeiouy]*"; // consonant sequence 60 | var V = v + "[aeiou]*"; // vowel sequence 61 | 62 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 63 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 64 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 65 | var s_v = "^(" + C + ")?" + v; // vowel in stem 66 | 67 | this.stemWord = function (w) { 68 | var stem; 69 | var suffix; 70 | var firstch; 71 | var origword = w; 72 | 73 | if (w.length < 3) 74 | return w; 75 | 76 | var re; 77 | var re2; 78 | var re3; 79 | var re4; 80 | 81 | firstch = w.substr(0,1); 82 | if (firstch == "y") 83 | w = firstch.toUpperCase() + w.substr(1); 84 | 85 | // Step 1a 86 | re = /^(.+?)(ss|i)es$/; 87 | re2 = /^(.+?)([^s])s$/; 88 | 89 | if (re.test(w)) 90 | w = w.replace(re,"$1$2"); 91 | else if (re2.test(w)) 92 | w = w.replace(re2,"$1$2"); 93 | 94 | // Step 1b 95 | re = /^(.+?)eed$/; 96 | re2 = /^(.+?)(ed|ing)$/; 97 | if (re.test(w)) { 98 | var fp = re.exec(w); 99 | re = new RegExp(mgr0); 100 | if (re.test(fp[1])) { 101 | re = /.$/; 102 | w = w.replace(re,""); 103 | } 104 | } 105 | else if (re2.test(w)) { 106 | var fp = re2.exec(w); 107 | stem = fp[1]; 108 | re2 = new RegExp(s_v); 109 | if (re2.test(stem)) { 110 | w = stem; 111 | re2 = /(at|bl|iz)$/; 112 | re3 = new RegExp("([^aeiouylsz])\\1$"); 113 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 114 | if (re2.test(w)) 115 | w = w + "e"; 116 | else if (re3.test(w)) { 117 | re = /.$/; 118 | w = w.replace(re,""); 119 | } 120 | else if (re4.test(w)) 121 | w = w + "e"; 122 | } 123 | } 124 | 125 | // Step 1c 126 | re = /^(.+?)y$/; 127 | if (re.test(w)) { 128 | var fp = re.exec(w); 129 | stem = fp[1]; 130 | re = new RegExp(s_v); 131 | if (re.test(stem)) 132 | w = stem + "i"; 133 | } 134 | 135 | // Step 2 136 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 137 | if (re.test(w)) { 138 | var fp = re.exec(w); 139 | stem = fp[1]; 140 | suffix = fp[2]; 141 | re = new RegExp(mgr0); 142 | if (re.test(stem)) 143 | w = stem + step2list[suffix]; 144 | } 145 | 146 | // Step 3 147 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 148 | if (re.test(w)) { 149 | var fp = re.exec(w); 150 | stem = fp[1]; 151 | suffix = fp[2]; 152 | re = new RegExp(mgr0); 153 | if (re.test(stem)) 154 | w = stem + step3list[suffix]; 155 | } 156 | 157 | // Step 4 158 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 159 | re2 = /^(.+?)(s|t)(ion)$/; 160 | if (re.test(w)) { 161 | var fp = re.exec(w); 162 | stem = fp[1]; 163 | re = new RegExp(mgr1); 164 | if (re.test(stem)) 165 | w = stem; 166 | } 167 | else if (re2.test(w)) { 168 | var fp = re2.exec(w); 169 | stem = fp[1] + fp[2]; 170 | re2 = new RegExp(mgr1); 171 | if (re2.test(stem)) 172 | w = stem; 173 | } 174 | 175 | // Step 5 176 | re = /^(.+?)e$/; 177 | if (re.test(w)) { 178 | var fp = re.exec(w); 179 | stem = fp[1]; 180 | re = new RegExp(mgr1); 181 | re2 = new RegExp(meq1); 182 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 183 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 184 | w = stem; 185 | } 186 | re = /ll$/; 187 | re2 = new RegExp(mgr1); 188 | if (re.test(w) && re2.test(w)) { 189 | re = /.$/; 190 | w = w.replace(re,""); 191 | } 192 | 193 | // and turn initial Y back to y 194 | if (firstch == "y") 195 | w = firstch.toLowerCase() + w.substr(1); 196 | return w; 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /docs/_build/html/test_trained_agent.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | test_trained_agent module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 68 | 69 |
73 | 74 |
75 |
76 |
77 | 85 |
86 |
87 |
88 |
89 | 90 |
91 |

test_trained_agent module

92 |
93 |
94 | test_trained_agent.closed_loop_simulation_rl()[source]
95 |

Function is used to test trained RL agent (actor network) which is saved in the folder ./data/models/..,

96 |

It saves the states and action in the ./data/test_data/.., and plot in the ./data/test_plots/.. :::

97 |
98 | 99 |
100 | 101 | 102 |
103 |
104 |
108 | 109 |
110 | 111 |
112 |

© Copyright 2023, Vikas Rajpoot.

113 |
114 | 115 | Built with Sphinx using a 116 | theme 117 | provided by Read the Docs. 118 | 119 | 120 |
121 |
122 |
123 |
124 |
125 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /docs/_build/html/_modules/random_sa.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | random_sa — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 50 | 51 |
55 | 56 |
57 |
58 |
59 | 66 |
67 |
68 |
69 |
70 | 71 |

Source code for random_sa

 72 | import random 
 73 | import numpy as np 
 74 | 
 75 | 
[docs]def sample_actions(): 76 | F = 5 + random.random() * 95 77 | Q = -1 * random.random() * 8500 78 | 79 | return np.array([F, Q]).reshape(2, )
80 | 81 | 82 | 83 |
[docs]def sample_states(): 84 | c_a = 0.1 + random.random() * 1.9 85 | c_b = 0.1 + random.random() * 1.9 86 | t_r = 50 + random.random() * 100 87 | t_k = 50 + random.random() * 90 88 | 89 | return np.array([c_a, c_b, t_r, t_k]).reshape(4, )
90 | 91 | 92 |
93 | 94 |
95 |
96 |
97 | 98 |
99 | 100 |
101 |

© Copyright 2023, Vikas Rajpoot.

102 |
103 | 104 | Built with Sphinx using a 105 | theme 106 | provided by Read the Docs. 107 | 108 | 109 |
110 |
111 |
112 |
113 |
114 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /docs/_build/html/simulator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | simulator module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 68 | 69 |
73 | 74 |
75 |
76 |
77 | 85 |
86 |
87 |
88 |
89 | 90 |
91 |

simulator module

92 |
93 |
94 | simulator.cstr_dynamics(ti, tf, y01, y02, y03, y04, F, Q_dot)[source]
95 |
96 | 97 |
98 | 99 | 100 |
101 |
102 |
106 | 107 |
108 | 109 |
110 |

© Copyright 2023, Vikas Rajpoot.

111 |
112 | 113 | Built with Sphinx using a 114 | theme 115 | provided by Read the Docs. 116 | 117 | 118 |
119 |
120 |
121 |
122 |
123 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/_build/html/random_sa.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | random_sa module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 69 | 70 |
74 | 75 |
76 |
77 |
78 | 86 |
87 |
88 |
89 |
90 | 91 |
92 |

random_sa module

93 |
94 |
95 | random_sa.sample_actions()[source]
96 |
97 | 98 |
99 |
100 | random_sa.sample_states()[source]
101 |
102 | 103 |
104 | 105 | 106 |
107 |
108 |
112 | 113 |
114 | 115 |
116 |

© Copyright 2023, Vikas Rajpoot.

117 |
118 | 119 | Built with Sphinx using a 120 | theme 121 | provided by Read the Docs. 122 | 123 | 124 |
125 |
126 |
127 |
128 |
129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Control CSTR using Reinforcement Learning 3 | 4 | ## Overview 5 | 6 | This project implements a Reinforcement Learning (RL) based control system for a Continuous Stirred Tank Reactor (CSTR). The CSTR is a common type of chemical reactor used in industrial processes. The goal of this project is to design an RL agent that can efficiently control the CSTR to achieve desired performance metrics. 7 | 8 | ## Table of Contents 9 | 10 | 1. [Introduction](#introduction) 11 | 2. [Project Structure](#project-structure) 12 | 3. [Installation](#installation) 13 | 4. [Usage](#usage) 14 | 5. [Reinforcement Learning Approach](#reinforcement-learning-approach) 15 | 6. [Environment](#environment) 16 | 7. [Simulation](#simulation) 17 | 8. [Utilities](#utilities) 18 | 9. [Results](#results) 19 | 10. [Documentation](#documentation) 20 | 11. [Contributing](#contributing) 21 | 12. [License](#license) 22 | 13. [Acknowledgements](#acknowledgements) 23 | 24 | ## Introduction 25 | 26 | A Continuous Stirred Tank Reactor (CSTR) is widely used in chemical engineering for its simplicity and ease of operation. However, controlling the CSTR is challenging due to its nonlinear dynamics. This project explores the use of reinforcement learning to develop a control strategy for the CSTR, aiming to maintain the reactor at optimal operating conditions. 27 | 28 | ## Project Structure 29 | 30 | The project is organized into the following directories: 31 | 32 | - `Env/`: Contains the environment code for the CSTR. 33 | - `Simulation/`: Includes the simulator code for running experiments. 34 | - `Utils/`: Utility scripts for metrics, plotting, and other helper functions. 35 | - `docs/`: Documentation files for the project. 36 | - `.git/`: Git version control directory. 37 | 38 | ### Directory and File Descriptions 39 | 40 | #### Env/ 41 | - `env.py`: Defines the environment for the CSTR where the RL agent interacts. 42 | 43 | #### Simulation/ 44 | - `simulator.py`: Contains the simulation logic for the CSTR, integrating the environment and the RL agent. 45 | 46 | #### Utils/ 47 | - `metrics.py`: Provides functions to calculate performance metrics. 48 | - `plotting.py`: Scripts for plotting results and visualizations. 49 | - `random_sa.py`: Random search algorithms for hyperparameter tuning. 50 | - `utils.py`: General utility functions used across the project. 51 | 52 | #### docs/ 53 | - Sphinx-generated documentation for the project. 54 | 55 | ## Installation 56 | 57 | To run this project, you need to have Python installed along with several dependencies. The recommended way to install the dependencies is to use a virtual environment. 58 | 59 | ### Step-by-Step Installation 60 | 61 | 1. **Clone the Repository**: 62 | ```bash 63 | git clone https://github.com/vikash9899/Contorl-CSTR-using-Reinforcement-learning.git 64 | 65 | 66 | 67 | 2. **Create a Virtual Environment**: 68 | ```bash 69 | python3 -m venv venv 70 | source venv/bin/activate # On Windows, use `venv\Scripts\activate` 71 | ``` 72 | 73 | 3. **Install Dependencies**: 74 | ```bash 75 | pip install -r requirements.txt 76 | ``` 77 | 78 | ## Usage 79 | 80 | After installing the dependencies, you can run the simulations and train the RL agent. 81 | 82 | ### Running the Simulation 83 | 84 | 1. **Navigate to the Simulation Directory**: 85 | ```bash 86 | cd Simulation 87 | ``` 88 | 89 | 2. **Run the Simulator**: 90 | ```bash 91 | python simulator.py 92 | ``` 93 | 94 | ## Reinforcement Learning Approach 95 | 96 | The RL approach used in this project involves training an agent to learn the optimal policy for controlling the CSTR. The agent interacts with the environment, receives rewards based on its actions, and updates its policy accordingly. 97 | 98 | ### Key Components 99 | 100 | - **State**: Represents the current condition of the CSTR. 101 | - **Action**: The control input provided by the RL agent. 102 | - **Reward**: A scalar feedback signal used to guide the learning process. 103 | - **Policy**: The strategy used by the agent to decide actions based on states. 104 | 105 | ## Environment 106 | 107 | The environment (`env.py`) defines the interaction between the RL agent and the CSTR. It includes the state space, action space, reward function, and dynamics of the CSTR. 108 | 109 | ### Environment Details 110 | 111 | - **State Space**: Variables representing the current status of the reactor (e.g., concentration, temperature). 112 | - **Action Space**: Possible control actions (e.g., adjusting flow rates, temperature settings). 113 | - **Reward Function**: Designed to encourage desired behaviors such as stability, efficiency, and safety. 114 | 115 | ## Simulation 116 | 117 | The simulation (`simulator.py`) integrates the environment and the RL agent, allowing for training and evaluation. It handles the initialization, execution of episodes, and data collection for analysis. 118 | 119 | ### Key Features 120 | 121 | - **Episode Management**: Running multiple episodes for training and testing. 122 | - **Data Logging**: Collecting data on states, actions, rewards, and performance metrics. 123 | - **Visualization**: Plotting the results for analysis and interpretation. 124 | 125 | ## Utilities 126 | 127 | The `Utils/` directory contains helper functions and scripts to support the main codebase. 128 | 129 | ### Metrics 130 | 131 | `metrics.py` provides functions to evaluate the performance of the RL agent, such as calculating cumulative rewards and stability measures. 132 | 133 | ### Plotting 134 | 135 | `plotting.py` includes scripts to visualize the results, such as state trajectories, reward curves, and action distributions. 136 | 137 | ### Random Search 138 | 139 | `random_sa.py` implements random search algorithms for hyperparameter tuning, helping to find the best settings for the RL agent. 140 | 141 | ### General Utilities 142 | 143 | `utils.py` contains general-purpose functions used throughout the project, such as data normalization, logging, and configuration handling. 144 | 145 | ## Results 146 | 147 | The results of the experiments, including trained models and performance metrics, are stored in the `results/` directory. Key findings and visualizations are documented to provide insights into the effectiveness of the RL-based control strategy. 148 | 149 | ## Documentation 150 | 151 | Comprehensive documentation is provided in the `docs/` directory, generated using Sphinx. It includes detailed descriptions of the project components, installation instructions, usage guides, and API references. 152 | 153 | ### Building the Documentation 154 | 155 | To build the documentation locally, navigate to the `docs/` directory and run: 156 | ```bash 157 | make html 158 | ``` 159 | The generated HTML files will be available in `docs/_build/html/`. 160 | 161 | ## Contributing 162 | 163 | Contributions to the project are welcome! If you have suggestions for improvements or new features, please create an issue or submit a pull request. 164 | 165 | ### Contribution Guidelines 166 | 167 | 1. Fork the repository. 168 | 2. Create a new branch (`git checkout -b feature-branch`). 169 | 3. Commit your changes (`git commit -am 'Add new feature'`). 170 | 4. Push to the branch (`git push origin feature-branch`). 171 | 5. Create a new pull request. 172 | 173 | ## License 174 | 175 | This project is licensed under the MIT License. See the `LICENSE` file for more details. 176 | 177 | ## Acknowledgements 178 | 179 | This project builds upon numerous open-source libraries and research contributions in the fields of reinforcement learning and chemical process control. We extend our gratitude to the contributors and maintainers of these projects. 180 | 181 | 182 | -------------------------------------------------------------------------------- /docs/_build/html/main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | main module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 69 | 70 |
74 | 75 |
76 |
77 |
78 | 86 |
87 |
88 |
89 |
90 | 91 |
92 |

main module

93 |
94 |
95 | main.actor_training(env, policy, batch_size, replay_buffer, start_timesteps, total_ep_training)[source]
96 |
97 | 98 |
99 |
100 | main.run()[source]
101 |
102 | 103 |
104 | 105 | 106 |
107 |
108 |
112 | 113 |
114 | 115 |
116 |

© Copyright 2023, Vikas Rajpoot.

117 |
118 | 119 | Built with Sphinx using a 120 | theme 121 | provided by Read the Docs. 122 | 123 | 124 |
125 |
126 |
127 |
128 |
129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import DDPG.DDPG as dg 3 | import Env.env as e 4 | import Utils.utils as utils 5 | import DDPG.buffer as bf 6 | import time 7 | 8 | np.set_printoptions(formatter={'float': lambda x: "{0:0.5f}".format(x)}) 9 | 10 | 11 | # setting the episode length. 12 | episode_length = 500 13 | 14 | 15 | def actor_training(env, policy, batch_size, replay_buffer, start_timesteps, total_ep_training ): 16 | 17 | global episode_length 18 | 19 | # list to store the episode rewards. 20 | ep_reward_list = [] 21 | 22 | decay_rate = 0.02 23 | 24 | data_listt = [] 25 | 26 | start = time.time() 27 | for ep in range(1, total_ep_training): 28 | 29 | print("\n \n \n episode : ", ep ) 30 | episode_reward = 0 31 | # call the reset function to get the initial state.... 32 | state, info_dic = env.reset() 33 | 34 | # setpoint state and setpoint actions for the current episode 35 | setpoint_state = info_dic['setpoint_state'] 36 | setpoint_action = info_dic['setpoint_action'] 37 | 38 | # decay of the statndard diviation with the episode 39 | decay_std = 1 * 1/(1 + decay_rate * ep) 40 | 41 | std_dev = np.array([decay_std, decay_std], dtype=float) 42 | ep_len = 0 43 | 44 | actions__ = [] 45 | obs__ = [] 46 | 47 | us_obs__ = [] 48 | us_actions__ = [] 49 | 50 | 51 | break_episode = False 52 | counter = 0 53 | while not(break_episode): 54 | counter += 1 55 | 56 | ep_len += 1 57 | 58 | ### selecting the actions random actions for some staring some episodes... 59 | if ep <= start_timesteps: 60 | action = env.action_space.sample() 61 | else: 62 | 63 | noisy_action = policy.select_action(state) + \ 64 | utils.gaussian_noise(mean=np.array([0, 0]) , std=std_dev ) 65 | 66 | action = utils.clip_negative_positive_one(noisy_action) 67 | 68 | ### Perform action 69 | # print("actions : ", action) 70 | 71 | obs__.append(state) 72 | actions__.append(action) 73 | 74 | 75 | t_s = utils.reverse_normalize_minmax_states(state[:4]) 76 | t_e = utils.reverse_normalize_minmax_error(state[4]) 77 | t_ie = utils.reverse_normalize_minmax_ierror(state[5]) 78 | 79 | obsss = np.concatenate([t_s, t_e, t_ie]) 80 | 81 | us_obs__.append(obsss) 82 | 83 | t_a = utils.reverse_normalize_minmax_actions(action) 84 | 85 | us_actions__.append(t_a) 86 | 87 | #### calling the step function which is returning the next_state, reward, termination and trancate.... 88 | next_state, reward, terminated, trancate, _ = env.step(action) 89 | 90 | ### break episode if terminate or trancate is true. 91 | break_episode = terminated or trancate 92 | 93 | done = terminated 94 | 95 | if done: 96 | d = 1 97 | else: 98 | d = 0 99 | 100 | ### Store data in replay buffer 101 | replay_buffer.add(state, action, next_state, reward, d) 102 | 103 | ### Train agent after collecting sufficient data 104 | if ep >= start_timesteps: 105 | policy.train(replay_buffer, batch_size ) 106 | 107 | 108 | if break_episode: 109 | obs__ = np.array(obs__) 110 | actions__ = np.array(actions__) 111 | 112 | 113 | print(" step : ", np.round(setpoint_state, 2)) 114 | print(" state : ", np.round(t_s, 2)) 115 | print(" step a : ", np.round(setpoint_action, 2)) 116 | print(" action : ", np.round(t_a, 2)) 117 | print(" done : ", done) 118 | 119 | print(" _std : ", np.round(decay_std, 3)) 120 | print("episode length : ", counter) 121 | 122 | 123 | dict__n = { 124 | "setpoint_state ": setpoint_state, 125 | "state ":t_s, 126 | "setpoint_action ": setpoint_action, 127 | "action ":t_a, 128 | "ep_reward ":episode_reward, 129 | "reward ":reward, 130 | "done ":done, 131 | "std ":decay_std, 132 | "episode length ":counter 133 | } 134 | 135 | data_listt.append(dict__n) 136 | 137 | 138 | if ep % 500 == 0: 139 | # dir_l = utils.global_dir + '/data' 140 | # policy.save(dir_l, ep) 141 | 142 | # file = utils.global_dir + '/data/mat/reward_list'+ str(ep) +'.csv' 143 | # np.savetxt(file, ep_reward_list, delimiter=',') 144 | pass 145 | 146 | 147 | state = next_state 148 | episode_reward += reward 149 | 150 | ep_reward_list.append(episode_reward) 151 | print("\nEpisode reward : ", round(episode_reward, 2)) 152 | 153 | 154 | end = time.time() 155 | 156 | time_taken_in_seconds = round(end-start, 2) 157 | time_taken_in_minutes = round(time_taken_in_seconds / 60, 2) 158 | time_taken_in_hours = round(time_taken_in_minutes / 60, 2) 159 | 160 | 161 | # saving the time taken to train the Actor agent. 162 | with open('time.txt', 'w') as file: 163 | file.write(str(start)) 164 | file.write('\n') 165 | file.write(str(end)) 166 | file.write("\n"+str(time_taken_in_seconds)+" time taken during training in seconds") 167 | file.write("\n"+str(time_taken_in_minutes)+" time taken during training in minutes") 168 | file.write("\n"+str(time_taken_in_hours)+" time taken during training in hours") 169 | 170 | print() 171 | 172 | file = utils.global_dir + '/data/mat/reward_list.csv' 173 | np.savetxt(file, ep_reward_list, delimiter=',') 174 | 175 | dir_l = utils.global_dir + '/data' 176 | policy.save(dir_l, 17) 177 | 178 | 179 | with open('output_list.txt', 'w') as file: 180 | for dictionary in data_listt: 181 | for key, value in dictionary.items(): 182 | file.write('%s:%s\n' % (key, value)) 183 | file.write('\n') 184 | 185 | 186 | 187 | 188 | def run(): 189 | 190 | ## creating the environment. 191 | cstr = e.cstr_env() 192 | 193 | state_dim_ = cstr.observation_space.shape[0] 194 | action_dim_ = cstr.action_space.shape[0] 195 | 196 | print("state dim : ", state_dim_) 197 | print("action dim : ", action_dim_ ) 198 | 199 | # create the DDPG object. 200 | ddpg = dg.DDPG( 201 | state_dim=state_dim_, 202 | action_dim=action_dim_, 203 | discount=1, 204 | tau=0.001 205 | ) 206 | 207 | ## buffer size 208 | buffer_size = int(1e5) 209 | 210 | # creating the buffer which is used to save the tranistions [s, a, s', r, done] 211 | buffer = bf.ReplayBuffer(state_dim_, action_dim_, buffer_size) 212 | 213 | actor_training( 214 | env= cstr, 215 | policy= ddpg, 216 | # batch size used to update the actor-critic. 217 | batch_size= 256, 218 | replay_buffer= buffer, 219 | # warm-up episodes till 500 episodes there is no update in the actor-critic network. 220 | start_timesteps= 500, 221 | # totoal number of episodes used to train the actor-critic network. 222 | total_ep_training = 3000 223 | ) 224 | 225 | 226 | # buffer.save_buffer() 227 | 228 | 229 | if __name__=="__main__": 230 | run() 231 | 232 | 233 | -------------------------------------------------------------------------------- /docs/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Stable-Baselines3 Docs - Reliable Reinforcement Learning Implementations — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 52 | 53 |
57 | 58 |
59 |
60 |
61 |
    62 |
  • 63 | 64 |
  • 65 | View page source 66 |
  • 67 |
68 |
69 |
70 |
71 |
72 | 73 |
74 |

Stable-Baselines3 Docs - Reliable Reinforcement Learning Implementations

75 |

Stable Baselines3 (SB3) is a set of reliable implementations of reinforcement learning algorithms in PyTorch. 76 | It is the next major version of Stable Baselines.

77 |

Github repository: https://github.com/DLR-RM/stable-baselines3

78 |

Paper: https://jmlr.org/papers/volume22/20-1364/20-1364.pdf

79 |

RL Baselines3 Zoo (training framework for SB3): https://github.com/DLR-RM/rl-baselines3-zoo

80 |

RL Baselines3 Zoo provides a collection of pre-trained agents, scripts for training, evaluating agents, tuning hyperparameters, plotting results and recording videos.

81 |

SB3 Contrib (experimental RL code, latest algorithms): https://github.com/Stable-Baselines-Team/stable-baselines3-contrib

82 |
83 |

Main Features

84 |
    85 |
  • Unified structure for all algorithms

  • 86 |
  • PEP8 compliant (unified code style)

  • 87 |
  • Documented functions and classes

  • 88 |
  • Tests, high code coverage and type hints

  • 89 |
  • Clean code

  • 90 |
  • Tensorboard support

  • 91 |
  • The performance of each algorithm was tested (see Results section in their respective page)

  • 92 |
93 |
94 |

User Guide

95 | 110 |
111 | 116 |
117 |
118 | 119 | 120 |
121 |
122 |
125 | 126 |
127 | 128 |
129 |

© Copyright 2023, Vikas Rajpoot.

130 |
131 | 132 | Built with Sphinx using a 133 | theme 134 | provided by Read the Docs. 135 | 136 | 137 |
138 |
139 |
140 |
141 |
142 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/_build/html/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Python Module Index — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | 57 | 58 |
62 | 63 |
64 |
65 |
66 |
    67 |
  • 68 | 69 |
  • 70 |
  • 71 |
72 |
73 |
74 |
75 |
76 | 77 | 78 |

Python Module Index

79 | 80 |
81 | a | 82 | b | 83 | d | 84 | e | 85 | m | 86 | p | 87 | r | 88 | s | 89 | t | 90 | u 91 |
92 | 93 | 94 | 95 | 97 | 98 | 99 | 102 | 103 | 105 | 106 | 107 | 110 | 111 | 113 | 114 | 115 | 118 | 119 | 121 | 122 | 123 | 126 | 127 | 129 | 130 | 131 | 134 | 135 | 136 | 139 | 140 | 142 | 143 | 144 | 147 | 148 | 150 | 151 | 152 | 155 | 156 | 158 | 159 | 160 | 163 | 164 | 166 | 167 | 168 | 171 | 172 | 174 | 175 | 176 | 179 |
 
96 | a
100 | argparse_actions 101 |
 
104 | b
108 | buffer 109 |
 
112 | d
116 | DDPG 117 |
 
120 | e
124 | env 125 |
 
128 | m
132 | main 133 |
137 | matrics 138 |
 
141 | p
145 | ploting 146 |
 
149 | r
153 | random_sa 154 |
 
157 | s
161 | simulator 162 |
 
165 | t
169 | test_trained_agent 170 |
 
173 | u
177 | utils 178 |
180 | 181 | 182 |
183 |
184 |
185 | 186 |
187 | 188 |
189 |

© Copyright 2023, Vikas Rajpoot.

190 |
191 | 192 | Built with Sphinx using a 193 | theme 194 | provided by Read the Docs. 195 | 196 | 197 |
198 |
199 |
200 |
201 |
202 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /docs/_build/html/matrics.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | matrics module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 69 | 70 |
74 | 75 |
76 |
77 |
78 | 86 |
87 |
88 |
89 |
90 | 91 |
92 |

matrics module

93 |
94 |
95 | matrics.plot_series(series, title, xlabel, ylabel, file)[source]
96 |
97 | 98 |
99 |
100 | matrics.plot_sliding_mean(data, window, titile, xlabel, ylabel, file)[source]
101 |
102 | 103 |
104 | 105 | 106 |
107 |
108 |
112 | 113 |
114 | 115 |
116 |

© Copyright 2023, Vikas Rajpoot.

117 |
118 | 119 | Built with Sphinx using a 120 | theme 121 | provided by Read the Docs. 122 | 123 | 124 |
125 |
126 |
127 |
128 |
129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /Utils/utils.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | """ 4 | .. module:: argparse_actions 5 | 6 | This module is used to scale and rescale the observations and actions of the RL agent --- 7 | """ 8 | 9 | 10 | import numpy as np 11 | import os 12 | 13 | global_dir = os.getcwd() 14 | 15 | 16 | act_range_min = np.array([0.2, 0.4, 50., 50.], dtype=float) 17 | act_range_max = np.array([3, 1.2, 150., 150.], dtype=float) 18 | 19 | 20 | transform_range_min = np.array([-1., -1., -1., -1.], dtype=float) 21 | transform_range_max = np.array([1., 1., 1., 1.], dtype=float) 22 | 23 | 24 | def normalize_minmax_states(X:np.ndarray): 25 | 26 | """ 27 | This function takes four states :math:`[C_A, C_B, T_R, T_K]` as the input and transform each of them to the range [-1 to 1] using minmax-scaling. 28 | 29 | Arguments: 30 | X (list, np.ndarray): Array of four values :math:`[C_A, C_B, T_R, T_K]`. 31 | 32 | Returns: 33 | X_scaled (list, np.ndarray): Scaled values of the array X. 34 | 35 | """ 36 | 37 | global act_range_min, act_range_max, transform_range_min, transform_range_max 38 | 39 | X_std = (X-act_range_min) / (act_range_max - act_range_min) 40 | 41 | X_scaled = X_std * (transform_range_max - transform_range_min) + transform_range_min 42 | 43 | return X_scaled 44 | 45 | 46 | def reverse_normalize_minmax_states(X_scaled:np.ndarray): 47 | 48 | """ 49 | This function four states :math:`[C_A, C_B, T_R, T_K]` as the input and reverse-transform each of them from range [-1 to 1] to their actual range. 50 | 51 | Arguments: 52 | X_scaled (list, np.ndarray): Array of four values :math:`[C_A, C_B, T_R, T_K]`. 53 | 54 | Returns: 55 | X (list, np.ndarray): returns the original values of the array X_scaled. 56 | 57 | """ 58 | 59 | 60 | global act_range_min, act_range_max, transform_range_min, transform_range_max 61 | 62 | X = ( (X_scaled - transform_range_min) / (transform_range_max - transform_range_min) ) * (act_range_max - act_range_min) + act_range_min 63 | 64 | return X 65 | 66 | 67 | action_min_r = np.array([5., -8500.], dtype=float) 68 | action_max_r = np.array([100., 0.], dtype=float) 69 | 70 | 71 | transform_action_min_r = np.array([-1, -1], dtype=float) 72 | transform_action_max_r = np.array([1, 1], dtype=float) 73 | 74 | 75 | 76 | def normalize_minmax_actions(X:np.ndarray): 77 | 78 | """ 79 | This function four states :math:`[F, \dot Q]` as the input and reverse-transform each of them from range [-1 to 1] to their actual range. 80 | 81 | Arguments: 82 | X_scaled (list, np.ndarray): Array of two values :math:`[F, \dot Q]`. 83 | 84 | Returns: 85 | X (list, np.ndarray): returns the original values of the array X_scaled. 86 | 87 | """ 88 | 89 | 90 | global action_min_r, action_max_r, transform_action_min_r, transform_action_max_r 91 | 92 | X_std = (X-action_min_r) / (action_max_r - action_min_r) 93 | 94 | X_scaled = X_std * (transform_action_max_r - transform_action_min_r) + transform_action_min_r 95 | 96 | return X_scaled 97 | 98 | 99 | def reverse_normalize_minmax_actions(X_scaled:np.ndarray): 100 | 101 | """ 102 | 103 | function takes two actions :math:`[F, \dot Q]` as the input and reverse-transform each of them from range [-1 to 1] to their actual range. 104 | 105 | Arguments: 106 | X_scaled (list, np.ndarray): Array of two values :math:`[F, \dot Q]`. 107 | 108 | Returns: 109 | X (list, np.ndarray): returns the original values of the array X_scaled. 110 | 111 | """ 112 | 113 | global action_min_r, action_max_r, transform_action_min_r, transform_action_max_r 114 | 115 | X = ( (X_scaled - transform_action_min_r) / (transform_action_max_r - transform_action_min_r) ) * (action_max_r - action_min_r) + action_min_r 116 | 117 | return X 118 | 119 | 120 | act_range_min_e = np.array([0., 0., 0., 0.], dtype=float) 121 | act_range_max_e = None 122 | 123 | 124 | transform_range_min_e = np.array([-1., -1., -1., -1.], dtype=float) 125 | transform_range_max_e = np.array([ 1., 1., 1., 1.], dtype=float) 126 | 127 | 128 | def normalize_minmax_error(X:np.ndarray): 129 | 130 | """ 131 | This function takes error of four states :math:`[C_A, C_B, T_R, T_K]` as the input and transform each of them to the range [-1 to 1] using minmax-scaling. 132 | 133 | Arguments: 134 | X (list, np.ndarray): Array of four values. 135 | 136 | Returns: 137 | X_scaled (list, np.ndarray): Scaled values of the array X. 138 | 139 | """ 140 | 141 | 142 | global act_range_min_e, act_range_max_e, transform_range_min_e, transform_range_max_e 143 | 144 | X_std = (X-act_range_min_e) / ((act_range_max_e - act_range_min_e) ) 145 | 146 | X_scaled = X_std * (transform_range_max_e - transform_range_min_e) + transform_range_min_e 147 | 148 | return X_scaled 149 | 150 | 151 | def reverse_normalize_minmax_error(X_scaled:np.ndarray): 152 | 153 | """ 154 | This function takes error of four states :math:`[C_A, C_B, T_R, T_K]` as the input and reverse-transform each of them from range [-1 to 1] to their actual range. 155 | 156 | Arguments: 157 | X_scaled (list, np.ndarray): Array of four values`. 158 | 159 | Returns: 160 | X (list, np.ndarray): returns the original values of the array X_scaled. 161 | 162 | """ 163 | 164 | 165 | global act_range_min_e, act_range_max_e, transform_range_min_e, transform_range_max_e 166 | 167 | X = ( (X_scaled - transform_range_min_e) / (transform_range_max_e - transform_range_min_e) ) * (act_range_max_e - act_range_min_e) + act_range_min_e 168 | 169 | return X 170 | 171 | 172 | act_range_min_ie = np.array([0., 0., 0., 0.], dtype=float) 173 | act_range_max_ie = None 174 | 175 | 176 | transform_range_min_ie = np.array([-1., -1., -1., -1.], dtype=float) 177 | transform_range_max_ie = np.array([1., 1., 1., 1.], dtype=float) 178 | 179 | 180 | def normalize_minmax_ierror(X:np.ndarray): 181 | 182 | """ 183 | This function takes integral error of four states :math:`[C_A, C_B, T_R, T_K]` as the input and transform each of them to the range [-1 to 1] using minmax-scaling. 184 | 185 | Arguments: 186 | X (list, np.ndarray): Array of four values. 187 | 188 | Returns: 189 | X_scaled (list, np.ndarray): Scaled values of the array X. 190 | 191 | """ 192 | 193 | global act_range_min_ie, act_range_max_ie, transform_range_min_ie, transform_range_max_ie 194 | 195 | X_std = (X-act_range_min_ie) / (act_range_max_ie - act_range_min_ie) 196 | 197 | X_scaled = X_std * (transform_range_max_ie - transform_range_min_ie) + transform_range_min_ie 198 | 199 | return X_scaled 200 | 201 | 202 | def reverse_normalize_minmax_ierror(X_scaled:np.ndarray): 203 | 204 | 205 | """ 206 | This function takes integral error of four states :math:`[C_A, C_B, T_R, T_K]` as the input and reverse-transform each of them from range [-1 to 1] to their actual range. 207 | 208 | Arguments: 209 | X_scaled (list, np.ndarray): Array of four values`. 210 | 211 | Returns: 212 | X (list, np.ndarray): returns the original values of the array X_scaled. 213 | 214 | """ 215 | 216 | 217 | global act_range_min_ie, act_range_max_ie, transform_range_min_ie, transform_range_max_ie 218 | 219 | X = ( (X_scaled - transform_range_min_ie) / (transform_range_max_ie - transform_range_min_ie) ) * (act_range_max_ie - act_range_min_ie) + act_range_min_ie 220 | 221 | return X 222 | 223 | 224 | 225 | 226 | def clip_negative_positive_one(x): 227 | max1 = np.array([1, 1]) 228 | min1 = np.array([-1, -1]) 229 | x = np.maximum(x, min1) 230 | x = np.minimum(x, max1) 231 | return x 232 | 233 | 234 | def clip_actions(X): 235 | 236 | """ 237 | Function takes the array of actions :math:`[F, \dot Q]` and convert to the given range. 238 | 239 | Arguments: 240 | X_scaled (list, np.ndarray): Array of four values`. 241 | 242 | Returns: 243 | X (list, np.ndarray): returns the original values of the array X_scaled. 244 | 245 | """ 246 | 247 | X = np.clip(X, np.array([5., -8500.]), np.array([100., 0.])) 248 | 249 | return X 250 | 251 | 252 | def gaussian_noise(mean:np.ndarray, std:np.ndarray): 253 | noise = np.random.normal(mean, std) 254 | return noise 255 | 256 | 257 | 258 | -------------------------------------------------------------------------------- /DDPG/DDPG.py: -------------------------------------------------------------------------------- 1 | import copy 2 | import numpy as np 3 | import torch 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | import os 7 | 8 | # selectiong on which GPU code should be run.. 9 | # os.environ['CUDA_VISIBLE_DEVICES'] = '1' 10 | 11 | 12 | # if GPU avilable then use the GPU otherwise use the CPU. 13 | # device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 14 | device = "cpu" 15 | 16 | # if torch.cuda.is_available(): 17 | # print("training on the nvedia GPU........") 18 | 19 | # torch.cuda.empty_cache() 20 | 21 | # Re-tuned version of Deep Deterministic Policy Gradients (DDPG) 22 | # Paper: https://arxiv.org/abs/1509.02971 23 | 24 | 25 | class Actor(nn.Module): 26 | 27 | """ 28 | Actor class define the structure of neural network of the actor part of actor-critic frameworks and doing the forward pass. 29 | Arguments : 30 | state_dim (integer) : number of observation actor observed from the environment. 31 | action_dim (integer) : number of actions actor need to give to the environment. 32 | 33 | Return : 34 | model : return the actor model. 35 | 36 | """ 37 | 38 | def __init__(self, state_dim, action_dim): 39 | 40 | """ 41 | init function is used to initilize the critic network. 42 | 43 | Arguments : 44 | state_dim (integer) : number of observation actor observed from the environment. 45 | action_dim (integer) : number of actions actor need to give to the environment. 46 | 47 | Return : 48 | None 49 | 50 | """ 51 | super(Actor, self).__init__() 52 | 53 | self.l1 = nn.Linear(state_dim, 256) 54 | self.l2 = nn.Linear(256, 256) 55 | self.l3 = nn.Linear(256, action_dim) 56 | 57 | def forward(self, state): 58 | 59 | """ 60 | forward function takes the (state, action) and predict its Q-value. 61 | 62 | Arguements : 63 | state (array) : observations of the actor networks. 64 | action (array) : output array of the actor network. 65 | Return : 66 | model : return the critic model. 67 | """ 68 | 69 | a = F.relu(self.l1(state)) 70 | a = F.relu(self.l2(a)) 71 | 72 | model = torch.tanh(self.l3(a)) 73 | return model 74 | 75 | 76 | class Critic(nn.Module): 77 | 78 | """ 79 | Critic class define the structure of neural network of the critic part of actor-critic frameworks and doing the forward pass. 80 | """ 81 | 82 | def __init__(self, state_dim, action_dim): 83 | super(Critic, self).__init__() 84 | 85 | """ 86 | init function is used to initilize the critic network. 87 | 88 | Arguments : 89 | state_dim (integer) : number of observation actor observed from the environment. 90 | action_dim (integer) : number of actions actor need to give to the environment. 91 | 92 | Return : 93 | None 94 | 95 | """ 96 | self.l1 = nn.Linear(state_dim + action_dim, 256) 97 | self.l2 = nn.Linear(256, 256) 98 | self.l3 = nn.Linear(256, 1) 99 | 100 | 101 | def forward(self, state, action): 102 | 103 | """ 104 | forward function takes the (state, action) and predict its Q-value. 105 | 106 | Arguements : 107 | state (array) : observations of the actor networks. 108 | action (array) : output array of the actor network. 109 | Return : 110 | model : return the critic model. 111 | """ 112 | q = F.relu(self.l1(torch.cat([state, action], 1))) 113 | q = F.relu(self.l2(q)) 114 | return self.l3(q) 115 | 116 | 117 | class DDPG(object): 118 | 119 | """ 120 | DDPG class define the ddpg algorithm 121 | """ 122 | 123 | 124 | def __init__(self, state_dim, action_dim, discount=0.99, tau=0.001): 125 | 126 | """ 127 | init funtion is called when we create the object of the class. 128 | 129 | Argurments : 130 | state_dim (integer) : number of observation actor observed from the environment. 131 | action_dim (integer) : number of actions actor need to give to the environment. 132 | discount (float) : discount factor (gamma) used while updating the Q-value of (state, action). 133 | tau (float) : used to soft update the target actor and critic. 134 | 135 | Return : 136 | None 137 | """ 138 | 139 | self.actor = Actor(state_dim, action_dim).to(device) 140 | self.actor_target = copy.deepcopy(self.actor) 141 | self.actor_optimizer = torch.optim.Adam(self.actor.parameters(), lr=3e-4) 142 | 143 | self.critic = Critic(state_dim, action_dim).to(device) 144 | self.critic_target = copy.deepcopy(self.critic) 145 | self.critic_optimizer = torch.optim.Adam(self.critic.parameters(), lr=3e-4) 146 | 147 | self.discount = discount 148 | self.tau = tau 149 | 150 | self.actor_loss_list = [] 151 | self.critic_loss_list = [] 152 | 153 | 154 | def select_action(self, state): 155 | 156 | """ 157 | This function take the state as input and return action taken by the agent on this state. 158 | Arguments : 159 | state (array) : state on which we need to take the action. 160 | Return : 161 | action (array) : action taken by the actor on this state. 162 | 163 | """ 164 | 165 | state = torch.FloatTensor(state.reshape(1, -1)).to(device) 166 | return self.actor(state).cpu().data.numpy().flatten() 167 | 168 | 169 | def train(self, replay_buffer, batch_size=256): 170 | 171 | """ 172 | Train function is used to update the actor and critic network using the sampled data from the replay buffer. 173 | 174 | Arguments : 175 | replay_buffer (object) : replay_buffer takes the object of the buffer.ReplayBuffer() class where the (interaction) data is stored. 176 | batch_size (integer) : the number of samples we randomly select to update the actor and critic network from the replay_buffer. 177 | default value of the replay buffer is 256. 178 | """ 179 | 180 | ### Sample replay buffer 181 | state, action, next_state, reward, not_done = replay_buffer.sample(batch_size) 182 | 183 | ### Compute the target Q value 184 | target_Q = self.critic_target(next_state, self.actor_target(next_state)) 185 | target_Q = reward + (not_done * self.discount * target_Q).detach() 186 | 187 | ### Get current Q estimate 188 | current_Q = self.critic(state, action) 189 | 190 | ### Compute critic loss 191 | critic_loss = F.mse_loss(current_Q, target_Q) 192 | 193 | ### Append the critic loss to the critic_loss_list 194 | self.critic_loss_list.append(critic_loss.cpu().data.numpy()) 195 | 196 | ### Optimize the critic 197 | self.critic_optimizer.zero_grad() 198 | critic_loss.backward() 199 | self.critic_optimizer.step() 200 | 201 | ### Compute actor loss 202 | actor_loss = -self.critic(state, self.actor(state)).mean() 203 | 204 | ### Append the actor loss to the actor_loss_list. 205 | self.actor_loss_list.append(actor_loss.cpu().data.numpy()) 206 | 207 | ### Optimize the actor 208 | self.actor_optimizer.zero_grad() 209 | actor_loss.backward() 210 | self.actor_optimizer.step() 211 | 212 | ### Update the frozen target models 213 | for param, target_param in zip(self.critic.parameters(), self.critic_target.parameters()): 214 | target_param.data.copy_(self.tau * param.data + (1 - self.tau) * target_param.data) 215 | 216 | for param, target_param in zip(self.actor.parameters(), self.actor_target.parameters()): 217 | target_param.data.copy_(self.tau * param.data + (1 - self.tau) * target_param.data) 218 | 219 | 220 | def save(self, dir, ep): 221 | 222 | """ 223 | save function is used to save the actor, critic losses and models. 224 | Arguments : 225 | dir (str) : directory where we need to save the actor, critic losses and models. 226 | ep (integer) : episode number at which we are saving the data. 227 | Return : 228 | None 229 | """ 230 | 231 | torch.save(self.critic.state_dict(), dir + "/model/_critic" + str(ep)) 232 | torch.save(self.critic_optimizer.state_dict(), dir + "/model/_critic_optimizer" + str(ep)) 233 | 234 | torch.save(self.actor.state_dict(), dir + "/model/_actor" + str(ep)) 235 | torch.save(self.actor_optimizer.state_dict(), dir + "/model/_actor_optimizer"+ str(ep)) 236 | 237 | ac_loss = np.asarray(self.actor_loss_list) 238 | c_loss = np.asarray(self.critic_loss_list) 239 | 240 | np.savetxt(dir + "/mat/actor_loss "+ str(ep) + ".csv", ac_loss, delimiter=',') 241 | np.savetxt(dir + "/mat/critic_loss"+ str(ep) +".csv", c_loss, delimiter=',') 242 | 243 | 244 | def load(self, dir, ep): 245 | 246 | """ 247 | save function is used to save the actor, critic losses and models. 248 | Arguments : 249 | dir (str) : directory where we need to save the actor, critic losses and models. 250 | ep (integer) : episode number at which we are saving the data. 251 | Return : 252 | None 253 | """ 254 | 255 | self.critic.load_state_dict(torch.load(dir + "/model/_critic" + str(ep) )) 256 | self.critic_optimizer.load_state_dict(torch.load(dir + "/model/_critic_optimizer" + str(ep) )) 257 | self.critic_target = copy.deepcopy(self.critic) 258 | 259 | self.actor.load_state_dict(torch.load(dir + "/model/_actor" + str(ep) )) 260 | self.actor_optimizer.load_state_dict(torch.load(dir + "/model/_actor_optimizer" + str(ep) )) 261 | self.actor_target = copy.deepcopy(self.actor) 262 | 263 | 264 | 265 | -------------------------------------------------------------------------------- /docs/_build/html/buffer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | buffer module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 73 | 74 |
78 | 79 |
80 |
81 |
82 | 90 |
91 |
92 |
93 |
94 | 95 |
96 |

buffer module

97 |
98 |
99 | class buffer.ReplayBuffer(state_dim, action_dim, max_size=1000000)[source]
100 |

Bases: object

101 |
102 |
103 | add(state, action, next_state, reward, done)[source]
104 |
105 | 106 |
107 |
108 | sample(batch_size)[source]
109 |
110 | 111 |
112 |
113 | save_buffer()[source]
114 |
115 | 116 |
117 | 118 |
119 | 120 | 121 |
122 |
123 |
127 | 128 |
129 | 130 |
131 |

© Copyright 2023, Vikas Rajpoot.

132 |
133 | 134 | Built with Sphinx using a 135 | theme 136 | provided by Read the Docs. 137 | 138 | 139 |
140 |
141 |
142 |
143 |
144 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /docs/_build/html/ploting.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ploting module — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 71 | 72 |
76 | 77 |
78 |
79 |
80 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

ploting module

95 |
96 |
97 | ploting.plot_mpc_rl_comparision(rl_xk, rl_uk, mpc_xk, mpc_uk, itr, file)[source]
98 |

Function plot_xu is used to plots the four states \([C_A, C_B, T_R, T_K]\) and two action \([F, \dot Q]\).

99 |
100 |
Arguments :

rl_xk (np.ndarray) : rl_xk is the numpy array contents the four states (closed loop simulation by the reinforcement learning) \([C_A, C_B, T_R, T_K]\).

101 |

rl_uk (np.ndarray) : rl_uk is the numpy array contents the two actions \([F, \dot Q]\).

102 |

mpc_xk (np.ndarray) : mpc_xk is the numpy array contents the four states of closed loop simulation by the MPC controller \([C_A, C_B, T_R, T_K]\).

103 |

mpc_uk (np.ndarray) : mpc_xk is the numpy array contents the four actions of closed loop simulation by the MPC controller. \([F, \dot Q]\).

104 |

itr (integer) : itr is unique key given to the figure.

105 |

file (str, path) : path where figure need to be saved.

106 |
107 |
Return :

None

108 |
109 |
110 |
111 | 112 |
113 |
114 | ploting.plot_rl_comparision(rl_xk, rl_uk, itr, file)[source]
115 |

Function plot_xu is used to plots the four states \([C_A, C_B, T_R, T_K]\) and two action \([F, \dot Q]\).

116 |
117 |
Arguments :

rl_xk (np.ndarray) : S is the numpy array contents the four states \([C_A, C_B, T_R, T_K]\).

118 |

rl_uk (np.ndarray) : I is the numpy array contents the two actions \([F, \dot Q]\).

119 |

itr (integer) : itr is unique key given to the figure.

120 |

file (str, path) : path where figure need to be saved.

121 |
122 |
Return :

None

123 |
124 |
125 |
126 | 127 |
128 |
129 | ploting.plot_xu(S, I, file)[source]
130 |

Function plot_xu is used to plots the four states \([C_A, C_B, T_R, T_K]\) and two action \([F, \dot Q]\).

131 |
132 |
Arguments :

S (np.ndarray) : S is the numpy array contents the four states \([C_A, C_B, T_R, T_K]\).

133 |

I (np.ndarray) : I is the numpy array contents the two actions \([F, \dot Q]\).

134 |

file (str, path) : path where figure need to be saved.

135 |
136 |
Return :

None

137 |
138 |
139 |
140 | 141 |
142 | 143 | 144 |
145 |
146 |
150 | 151 |
152 | 153 |
154 |

© Copyright 2023, Vikas Rajpoot.

155 |
156 | 157 | Built with Sphinx using a 158 | theme 159 | provided by Read the Docs. 160 | 161 | 162 |
163 |
164 |
165 |
166 |
167 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /docs/_build/html/_modules/matrics.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | matrics — Reinforcement learning agent to control the CSTR process. 1.0.0 documentation 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 50 | 51 |
55 | 56 |
57 |
58 |
59 | 66 |
67 |
68 |
69 |
70 | 71 |

Source code for matrics

 72 | import utils 
 73 | import numpy as np 
 74 | import matplotlib.pyplot as plt
 75 | 
 76 | 
[docs]def plot_series(series, title, xlabel, ylabel, file): 77 | """ 78 | """ 79 | x = list(range(len(series))) 80 | plt.figure(figsize=(10, 6)) 81 | plt.xticks(fontsize=16) 82 | plt.yticks(fontsize=16) 83 | plt.title(title, fontsize=24) 84 | plt.xlabel(xlabel, fontsize=24) 85 | plt.ylabel(ylabel, fontsize=24) 86 | plt.plot(x, series) 87 | plt.savefig(file) 88 | plt.close()
89 | 90 | 91 |
[docs]def plot_sliding_mean(data, window, titile, xlabel, ylabel, file): 92 | 93 | m_cl = [] 94 | for i in range(0, len(data)-window): 95 | # print(i) 96 | me = sum(data[i:i+window])/window 97 | m_cl.append(me) 98 | 99 | 100 | plot_series(m_cl, titile, xlabel, ylabel, file)
101 | 102 | 103 | if __name__=="__main__": 104 | 105 | file1 = utils.global_dir + '/data/mat/reward_list.csv' 106 | file2 = utils.global_dir + '/data/mat/actor_loss 17.csv' 107 | file3 = utils.global_dir + '/data/mat/critic_loss17.csv' 108 | # file4 = utils.global_dir + '/data/mat/ep_len.csv' 109 | 110 | reward = np.loadtxt(file1, delimiter=',') 111 | actor_loss = np.loadtxt(file2, delimiter=',') 112 | critic_loss = np.loadtxt(file3, delimiter=',') 113 | # ep_len = np.loadtxt(file4, delimiter=',') 114 | 115 | # critic_loss = critic_loss[100:] 116 | file1 = utils.global_dir + '/data/mat/reward_list.png' 117 | file2 = utils.global_dir + '/data/mat/actor_loss.png' 118 | file3 = utils.global_dir + '/data/mat/critic_loss.png' 119 | # file4 = utils.global_dir + '/data/mat/ep_len.png' 120 | 121 | plot_series(reward, 'Reward', 'episode ', 'reward', file1) 122 | plot_series(actor_loss, 'Actor loss', 'number of updates ', 'actor loss', file2) 123 | plot_series(critic_loss, 'critic loss', 'number of updates ', 'critic loss', file3) 124 | # # plot_series(ep_len, 'ep length', 'episode ', 'ep length', file4) 125 | 126 | # window = 10 127 | # plot_sliding_mean(reward, window, 'Reward', 'episode ', 'reward', file1) 128 | # plot_sliding_mean(actor_loss, window, 'Actor loss', 'episode ', 'actor loss', file2) 129 | 130 | # window = 500 131 | # plot_sliding_mean(critic_loss, window, 'critic loss', 'episode ', 'critic loss', file3) 132 | 133 | 134 | 135 | 136 | 137 |
138 | 139 |
140 |
141 |
142 | 143 |
144 | 145 |
146 |

© Copyright 2023, Vikas Rajpoot.

147 |
148 | 149 | Built with Sphinx using a 150 | theme 151 | provided by Read the Docs. 152 | 153 | 154 |
155 |
156 |
157 |
158 |
159 | 164 | 165 | 166 | --------------------------------------------------------------------------------