{"id":2501,"date":"2019-01-05T14:19:49","date_gmt":"2019-01-05T14:19:49","guid":{"rendered":"http:\/\/intelligentonlinetools.com\/blog\/?page_id=2501"},"modified":"2019-01-07T15:25:15","modified_gmt":"2019-01-07T15:25:15","slug":"reinforcement-learning-dqn-run-planning","status":"publish","type":"page","link":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","title":{"rendered":"Reinforcement Learning DQN Run Planning"},"content":{"rendered":"<p>This is the python source code of run_planning_RL_DQN.py for post <a href=\"http:\/\/intelligentonlinetools.com\/blog\/2019\/01\/02\/reinforcement-learning-python-dqn-application-resource-allocation\/\" target=\"_blank\">Reinforcement Learning Python DQN Application for Resource Allocation<\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&quot;&quot;&quot;\r\nSimplest model-based RL, DQN\r\nRewards 3, 10 are specified in env script in the following\r\nThe first column is the goal to achieve - for example number of time units to complete.\r\nGoal_completion_criteria_and_rewards = [\r\n                        [2,3],\r\n                        [3,10]\r\n                        ]              \r\n\r\nThis script is the main part which controls the update method of this example.\r\nThe RL is in RL_brainDQN.py.\r\nagent = &quot;RANDOM_AGENT&quot;   or &quot;&quot;\r\nactions 0 , 1\r\ngoals  ML project,   RL project  \r\n\r\nstate positions\r\nnumber of hours(steps) for each goal   [4,8]  example\r\ninitial [0,0]    for each episode\r\n&quot;&quot;&quot;\r\n\r\nfrom planning_envDQN import Maze\r\nfrom RL_brainDQN import DeepQNetwork   \r\n\r\n\r\noutput_data=[]\r\nindexes=[]\r\ndef update():\r\n   \r\n    counter=0\r\n    sum=0\r\n    step=0\r\n  \r\n    for episode in range(2000):    \r\n        \r\n        env.reset()\r\n        print (&quot;episode=&quot; + str(episode))\r\n      \r\n        s_position=[0,0]    \r\n       \r\n        while True:\r\n            \r\n            a = RL.choose_action((s_position))\r\n            print (&quot;Action :&quot;)\r\n            print (a)\r\n      \r\n\r\n                    \r\n            s_next_position, r, done = env.step(a)\r\n     \r\n            RL.store_transition(s_position, a, r, s_next_position)\r\n         \r\n          \r\n            step=step+1\r\n            if (step &gt; 200) and (step % 5 == 0):\r\n                 RL.learn()\r\n         \r\n            s_position = s_next_position.copy()\r\n\r\n            if done:\r\n              \r\n                sum=sum+r\r\n                if episode % 50 == 0:\r\n                    output_data.append (sum \/ 50)\r\n                    sum=0\r\n                    indexes.append ( episode)\r\n                    counter=counter+1\r\n                \r\n                             \r\n                break\r\n\r\n   \r\n    print('episodes over')\r\n   \r\n\r\nif __name__ == &quot;__main__&quot;:\r\n    env = Maze()\r\n  \r\n    RL = DeepQNetwork(env.n_actions, env.n_features,\r\n                      learning_rate=0.0045,\r\n                      reward_decay=0.9,\r\n                      e_greedy=0.9,\r\n                      replace_target_iter=400,\r\n                      memory_size=2000,\r\n                    \r\n                      )\r\n\r\n    update()\r\n  \r\n    import matplotlib.pyplot as plt\r\n\r\n    plt.figure(1)\r\n    plt.plot(indexes, output_data, label='RL')\r\n    plt.ylabel('Reward')\r\n    plt.xlabel('training steps')\r\n    plt.show()\r\n    \r\n    RL.plot_cost()\r\n\r\n&quot;&quot;&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is the python source code of run_planning_RL_DQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reinforcement Learning DQN Run Planning - Machine Learning Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reinforcement Learning DQN Run Planning - Machine Learning Applications\" \/>\n<meta property=\"og:description\" content=\"This is the python source code of run_planning_RL_DQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation\" \/>\n<meta property=\"og:url\" content=\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/\" \/>\n<meta property=\"og:site_name\" content=\"Machine Learning Applications\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-07T15:25:15+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/\",\"name\":\"Reinforcement Learning DQN Run Planning - Machine Learning Applications\",\"isPartOf\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\"},\"datePublished\":\"2019-01-05T14:19:49+00:00\",\"dateModified\":\"2019-01-07T15:25:15+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/intelligentonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reinforcement Learning DQN Run Planning\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/\",\"name\":\"Machine Learning Applications\",\"description\":\"Artificial intelligence, data mining and machine learning for building web based tools and services.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reinforcement Learning DQN Run Planning - Machine Learning Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","og_locale":"en_US","og_type":"article","og_title":"Reinforcement Learning DQN Run Planning - Machine Learning Applications","og_description":"This is the python source code of run_planning_RL_DQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation","og_url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","og_site_name":"Machine Learning Applications","article_modified_time":"2019-01-07T15:25:15+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/","name":"Reinforcement Learning DQN Run Planning - Machine Learning Applications","isPartOf":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#website"},"datePublished":"2019-01-05T14:19:49+00:00","dateModified":"2019-01-07T15:25:15+00:00","breadcrumb":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-run-planning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/intelligentonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Reinforcement Learning DQN Run Planning"}]},{"@type":"WebSite","@id":"http:\/\/intelligentonlinetools.com\/blog\/#website","url":"http:\/\/intelligentonlinetools.com\/blog\/","name":"Machine Learning Applications","description":"Artificial intelligence, data mining and machine learning for building web based tools and services.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P7h1IJ-El","jetpack-related-posts":[{"id":2495,"url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn-planning-environment\/","url_meta":{"origin":2501,"position":0},"title":"Reinforcement Learning DQN Planning Environment","date":"January 5, 2019","format":false,"excerpt":"This is the python source code of planning_envDQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2364,"url":"http:\/\/intelligentonlinetools.com\/blog\/rl-dyna-q-run-planning-rl\/","url_meta":{"origin":2501,"position":1},"title":"Reinforcement Learning Dyna-Q Run Planning","date":"November 3, 2018","format":false,"excerpt":"This is the python source code of run_planning_RL.py for post Reinforcement Learning Example for Planning Tasks Using Q Learning and Dyna-Q","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2366,"url":"http:\/\/intelligentonlinetools.com\/blog\/rl-dyna-q\/","url_meta":{"origin":2501,"position":2},"title":"Reinforcement Learning Dyna-Q","date":"November 3, 2018","format":false,"excerpt":"This is the python source code of RL_brain.py for post Reinforcement Learning Example for Planning Tasks Using Q Learning and Dyna-Q","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2499,"url":"http:\/\/intelligentonlinetools.com\/blog\/reinforcement-learning-dqn\/","url_meta":{"origin":2501,"position":3},"title":"Reinforcement Learning DQN","date":"January 5, 2019","format":false,"excerpt":"This is the python source code of RL_brainDQN.py for post Reinforcement Learning Python DQN Application for Resource Allocation","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2368,"url":"http:\/\/intelligentonlinetools.com\/blog\/rl-dyna-q-planning-env\/","url_meta":{"origin":2501,"position":4},"title":"Reinforcement Learning Dyna-Q Planning Environment","date":"November 3, 2018","format":false,"excerpt":"This is the python source code of planning_env.py for post Reinforcement Learning Example for Planning Tasks Using Q Learning and Dyna-Q","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1820,"url":"http:\/\/intelligentonlinetools.com\/blog\/site-map\/","url_meta":{"origin":2501,"position":5},"title":"Sitemap","date":"January 25, 2018","format":false,"excerpt":"Time Series and Stock Data Prediction Python Source Code Machine Learning Stock Prediction with LSTM and Keras Notes - Machine Learning Stock Prediction with LSTM and Keras Time Series Prediction with LSTM and Keras for Multiple Steps Ahead Prediction Data Stock Prices with Prophet Time Series Analysis with Python and\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2501"}],"collection":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=2501"}],"version-history":[{"count":4,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2501\/revisions"}],"predecessor-version":[{"id":2518,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/pages\/2501\/revisions\/2518"}],"wp:attachment":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=2501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}