File size: 62,456 Bytes
382424a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "W5ut4-Uo_wFL"
},
"source": [
"# Deep Deterministic Policy Gradient (DDPG)\n",
"\n",
"**Author:** [amifunny](https://github.com/amifunny)<br>\n",
"**Date created:** 2020/06/04<br>\n",
"**Last modified:** 2020/09/21<br>\n",
"**Description:** Implementing DDPG algorithm on the Inverted Pendulum Problem."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "1eX-gAYp_wFP"
},
"source": [
"## Introduction\n",
"\n",
"**Deep Deterministic Policy Gradient (DDPG)** is a model-free off-policy algorithm for\n",
"learning continous actions.\n",
"\n",
"It combines ideas from DPG (Deterministic Policy Gradient) and DQN (Deep Q-Network).\n",
"It uses Experience Replay and slow-learning target networks from DQN, and it is based on\n",
"DPG,\n",
"which can operate over continuous action spaces.\n",
"\n",
"This tutorial closely follow this paper -\n",
"[Continuous control with deep reinforcement learning](https://arxiv.org/pdf/1509.02971.pdf)\n",
"\n",
"## Problem\n",
"\n",
"We are trying to solve the classic **Inverted Pendulum** control problem.\n",
"In this setting, we can take only two actions: swing left or swing right.\n",
"\n",
"What make this problem challenging for Q-Learning Algorithms is that actions\n",
"are **continuous** instead of being **discrete**. That is, instead of using two\n",
"discrete actions like `-1` or `+1`, we have to select from infinite actions\n",
"ranging from `-2` to `+2`.\n",
"\n",
"## Quick theory\n",
"\n",
"Just like the Actor-Critic method, we have two networks:\n",
"\n",
"1. Actor - It proposes an action given a state.\n",
"2. Critic - It predicts if the action is good (positive value) or bad (negative value)\n",
"given a state and an action.\n",
"\n",
"DDPG uses two more techniques not present in the original DQN:\n",
"\n",
"**First, it uses two Target networks.**\n",
"\n",
"**Why?** Because it add stability to training. In short, we are learning from estimated\n",
"targets and Target networks are updated slowly, hence keeping our estimated targets\n",
"stable.\n",
"\n",
"Conceptually, this is like saying, \"I have an idea of how to play this well,\n",
"I'm going to try it out for a bit until I find something better\",\n",
"as opposed to saying \"I'm going to re-learn how to play this entire game after every\n",
"move\".\n",
"See this [StackOverflow answer](https://stackoverflow.com/a/54238556/13475679).\n",
"\n",
"**Second, it uses Experience Replay.**\n",
"\n",
"We store list of tuples `(state, action, reward, next_state)`, and instead of\n",
"learning only from recent experience, we learn from sampling all of our experience\n",
"accumulated so far.\n",
"\n",
"Now, let's see how is it implemented."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "EhtEA5C1_wFR"
},
"outputs": [],
"source": [
"import gym\n",
"import tensorflow as tf\n",
"from tensorflow.keras import layers\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vvhqTnJ8_wFT"
},
"source": [
"We use [OpenAIGym](http://gym.openai.com/docs) to create the environment.\n",
"We will use the `upper_bound` parameter to scale our actions later."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "6limWVE-_wFU",
"outputId": "8d672186-664b-40c5-ce82-e3450bf42221",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Size of State Space -> 3\n",
"Size of Action Space -> 1\n",
"Max Value of Action -> 2.0\n",
"Min Value of Action -> -2.0\n"
]
}
],
"source": [
"problem = \"Pendulum-v0\"\n",
"env = gym.make(problem)\n",
"\n",
"num_states = env.observation_space.shape[0]\n",
"print(\"Size of State Space -> {}\".format(num_states))\n",
"num_actions = env.action_space.shape[0]\n",
"print(\"Size of Action Space -> {}\".format(num_actions))\n",
"\n",
"upper_bound = env.action_space.high[0]\n",
"lower_bound = env.action_space.low[0]\n",
"\n",
"print(\"Max Value of Action -> {}\".format(upper_bound))\n",
"print(\"Min Value of Action -> {}\".format(lower_bound))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "SxQKZi35_wFU"
},
"source": [
"To implement better exploration by the Actor network, we use noisy perturbations,\n",
"specifically\n",
"an **Ornstein-Uhlenbeck process** for generating noise, as described in the paper.\n",
"It samples noise from a correlated normal distribution."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "0u9tVI2J_wFV"
},
"outputs": [],
"source": [
"\n",
"class OUActionNoise:\n",
" def __init__(self, mean, std_deviation, theta=0.15, dt=1e-2, x_initial=None):\n",
" self.theta = theta\n",
" self.mean = mean\n",
" self.std_dev = std_deviation\n",
" self.dt = dt\n",
" self.x_initial = x_initial\n",
" self.reset()\n",
"\n",
" def __call__(self):\n",
" # Formula taken from https://www.wikipedia.org/wiki/Ornstein-Uhlenbeck_process.\n",
" x = (\n",
" self.x_prev\n",
" + self.theta * (self.mean - self.x_prev) * self.dt\n",
" + self.std_dev * np.sqrt(self.dt) * np.random.normal(size=self.mean.shape)\n",
" )\n",
" # Store x into x_prev\n",
" # Makes next noise dependent on current one\n",
" self.x_prev = x\n",
" return x\n",
"\n",
" def reset(self):\n",
" if self.x_initial is not None:\n",
" self.x_prev = self.x_initial\n",
" else:\n",
" self.x_prev = np.zeros_like(self.mean)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aiaIXtYc_wFW"
},
"source": [
"The `Buffer` class implements Experience Replay.\n",
"\n",
"---\n",
"\n",
"---\n",
"\n",
"\n",
"**Critic loss** - Mean Squared Error of `y - Q(s, a)`\n",
"where `y` is the expected return as seen by the Target network,\n",
"and `Q(s, a)` is action value predicted by the Critic network. `y` is a moving target\n",
"that the critic model tries to achieve; we make this target\n",
"stable by updating the Target model slowly.\n",
"\n",
"**Actor loss** - This is computed using the mean of the value given by the Critic network\n",
"for the actions taken by the Actor network. We seek to maximize this quantity.\n",
"\n",
"Hence we update the Actor network so that it produces actions that get\n",
"the maximum predicted value as seen by the Critic, for a given state."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "HmrqnrR3_wFX"
},
"outputs": [],
"source": [
"\n",
"class Buffer:\n",
" def __init__(self, buffer_capacity=100000, batch_size=64):\n",
" # Number of \"experiences\" to store at max\n",
" self.buffer_capacity = buffer_capacity\n",
" # Num of tuples to train on.\n",
" self.batch_size = batch_size\n",
"\n",
" # Its tells us num of times record() was called.\n",
" self.buffer_counter = 0\n",
"\n",
" # Instead of list of tuples as the exp.replay concept go\n",
" # We use different np.arrays for each tuple element\n",
" self.state_buffer = np.zeros((self.buffer_capacity, num_states))\n",
" self.action_buffer = np.zeros((self.buffer_capacity, num_actions))\n",
" self.reward_buffer = np.zeros((self.buffer_capacity, 1))\n",
" self.next_state_buffer = np.zeros((self.buffer_capacity, num_states))\n",
"\n",
" # Takes (s,a,r,s') obervation tuple as input\n",
" def record(self, obs_tuple):\n",
" # Set index to zero if buffer_capacity is exceeded,\n",
" # replacing old records\n",
" index = self.buffer_counter % self.buffer_capacity\n",
"\n",
" self.state_buffer[index] = obs_tuple[0]\n",
" self.action_buffer[index] = obs_tuple[1]\n",
" self.reward_buffer[index] = obs_tuple[2]\n",
" self.next_state_buffer[index] = obs_tuple[3]\n",
"\n",
" self.buffer_counter += 1\n",
"\n",
" # Eager execution is turned on by default in TensorFlow 2. Decorating with tf.function allows\n",
" # TensorFlow to build a static graph out of the logic and computations in our function.\n",
" # This provides a large speed up for blocks of code that contain many small TensorFlow operations such as this one.\n",
" @tf.function\n",
" def update(\n",
" self, state_batch, action_batch, reward_batch, next_state_batch,\n",
" ):\n",
" # Training and updating Actor & Critic networks.\n",
" # See Pseudo Code.\n",
" with tf.GradientTape() as tape:\n",
" target_actions = target_actor(next_state_batch, training=True)\n",
" y = reward_batch + gamma * target_critic(\n",
" [next_state_batch, target_actions], training=True\n",
" )\n",
" critic_value = critic_model([state_batch, action_batch], training=True)\n",
" critic_loss = tf.math.reduce_mean(tf.math.square(y - critic_value))\n",
"\n",
" critic_grad = tape.gradient(critic_loss, critic_model.trainable_variables)\n",
" critic_optimizer.apply_gradients(\n",
" zip(critic_grad, critic_model.trainable_variables)\n",
" )\n",
"\n",
" with tf.GradientTape() as tape:\n",
" actions = actor_model(state_batch, training=True)\n",
" critic_value = critic_model([state_batch, actions], training=True)\n",
" # Used `-value` as we want to maximize the value given\n",
" # by the critic for our actions\n",
" actor_loss = -tf.math.reduce_mean(critic_value)\n",
"\n",
" actor_grad = tape.gradient(actor_loss, actor_model.trainable_variables)\n",
" actor_optimizer.apply_gradients(\n",
" zip(actor_grad, actor_model.trainable_variables)\n",
" )\n",
"\n",
" # We compute the loss and update parameters\n",
" def learn(self):\n",
" # Get sampling range\n",
" record_range = min(self.buffer_counter, self.buffer_capacity)\n",
" # Randomly sample indices\n",
" batch_indices = np.random.choice(record_range, self.batch_size)\n",
"\n",
" # Convert to tensors\n",
" state_batch = tf.convert_to_tensor(self.state_buffer[batch_indices])\n",
" action_batch = tf.convert_to_tensor(self.action_buffer[batch_indices])\n",
" reward_batch = tf.convert_to_tensor(self.reward_buffer[batch_indices])\n",
" reward_batch = tf.cast(reward_batch, dtype=tf.float32)\n",
" next_state_batch = tf.convert_to_tensor(self.next_state_buffer[batch_indices])\n",
"\n",
" self.update(state_batch, action_batch, reward_batch, next_state_batch)\n",
"\n",
"\n",
"# This update target parameters slowly\n",
"# Based on rate `tau`, which is much less than one.\n",
"@tf.function\n",
"def update_target(target_weights, weights, tau):\n",
" for (a, b) in zip(target_weights, weights):\n",
" a.assign(b * tau + a * (1 - tau))\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yuatLEJ3_wFY"
},
"source": [
"Here we define the Actor and Critic networks. These are basic Dense models\n",
"with `ReLU` activation.\n",
"\n",
"Note: We need the initialization for last layer of the Actor to be between\n",
"`-0.003` and `0.003` as this prevents us from getting `1` or `-1` output values in\n",
"the initial stages, which would squash our gradients to zero,\n",
"as we use the `tanh` activation."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "OCCV2VAQ_wFY"
},
"outputs": [],
"source": [
"\n",
"def get_actor():\n",
" # Initialize weights between -3e-3 and 3-e3\n",
" last_init = tf.random_uniform_initializer(minval=-0.003, maxval=0.003)\n",
"\n",
" inputs = layers.Input(shape=(num_states,))\n",
" out = layers.Dense(256, activation=\"relu\")(inputs)\n",
" out = layers.Dense(256, activation=\"relu\")(out)\n",
" outputs = layers.Dense(1, activation=\"tanh\", kernel_initializer=last_init)(out)\n",
"\n",
" # Our upper bound is 2.0 for Pendulum.\n",
" outputs = outputs * upper_bound\n",
" model = tf.keras.Model(inputs, outputs)\n",
" return model\n",
"\n",
"\n",
"def get_critic():\n",
" # State as input\n",
" state_input = layers.Input(shape=(num_states))\n",
" state_out = layers.Dense(16, activation=\"relu\")(state_input)\n",
" state_out = layers.Dense(32, activation=\"relu\")(state_out)\n",
"\n",
" # Action as input\n",
" action_input = layers.Input(shape=(num_actions))\n",
" action_out = layers.Dense(32, activation=\"relu\")(action_input)\n",
"\n",
" # Both are passed through seperate layer before concatenating\n",
" concat = layers.Concatenate()([state_out, action_out])\n",
"\n",
" out = layers.Dense(256, activation=\"relu\")(concat)\n",
" out = layers.Dense(256, activation=\"relu\")(out)\n",
" outputs = layers.Dense(1)(out)\n",
"\n",
" # Outputs single value for give state-action\n",
" model = tf.keras.Model([state_input, action_input], outputs)\n",
"\n",
" return model\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gkg29m65_wFZ"
},
"source": [
"`policy()` returns an action sampled from our Actor network plus some noise for\n",
"exploration."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"id": "KmHbyy8l_wFZ"
},
"outputs": [],
"source": [
"\n",
"def policy(state, noise_object):\n",
" sampled_actions = tf.squeeze(actor_model(state))\n",
" noise = noise_object()\n",
" # Adding noise to action\n",
" sampled_actions = sampled_actions.numpy() + noise\n",
"\n",
" # We make sure action is within bounds\n",
" legal_action = np.clip(sampled_actions, lower_bound, upper_bound)\n",
"\n",
" return [np.squeeze(legal_action)]\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "r2EUVRZA_wFa"
},
"source": [
"## Training hyperparameters"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "8FELtxWr_wFa"
},
"outputs": [],
"source": [
"std_dev = 0.2\n",
"ou_noise = OUActionNoise(mean=np.zeros(1), std_deviation=float(std_dev) * np.ones(1))\n",
"\n",
"actor_model = get_actor()\n",
"critic_model = get_critic()\n",
"\n",
"target_actor = get_actor()\n",
"target_critic = get_critic()\n",
"\n",
"# Making the weights equal initially\n",
"target_actor.set_weights(actor_model.get_weights())\n",
"target_critic.set_weights(critic_model.get_weights())\n",
"\n",
"# Learning rate for actor-critic models\n",
"critic_lr = 0.002\n",
"actor_lr = 0.001\n",
"\n",
"critic_optimizer = tf.keras.optimizers.Adam(critic_lr)\n",
"actor_optimizer = tf.keras.optimizers.Adam(actor_lr)\n",
"\n",
"total_episodes = 100\n",
"# Discount factor for future rewards\n",
"gamma = 0.99\n",
"# Used to update target networks\n",
"tau = 0.005\n",
"\n",
"buffer = Buffer(50000, 64)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4RDsrs-U_wFa"
},
"source": [
"Now we implement our main training loop, and iterate over episodes.\n",
"We sample actions using `policy()` and train with `learn()` at each time step,\n",
"along with updating the Target networks at a rate `tau`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"id": "ytHAvwkZ_wFb",
"outputId": "3bb12bba-bd57-4e17-d456-f3812dbab54c",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Episode * 0 * Avg Reward is ==> -1562.2726156328647\n",
"Episode * 1 * Avg Reward is ==> -1483.9644029814049\n",
"Episode * 2 * Avg Reward is ==> -1505.4752484518995\n",
"Episode * 3 * Avg Reward is ==> -1502.139312848798\n",
"Episode * 4 * Avg Reward is ==> -1499.098591143217\n",
"Episode * 5 * Avg Reward is ==> -1498.9744436801384\n",
"Episode * 6 * Avg Reward is ==> -1513.1644515271164\n",
"Episode * 7 * Avg Reward is ==> -1468.1716524312988\n",
"Episode * 8 * Avg Reward is ==> -1427.4514428693592\n",
"Episode * 9 * Avg Reward is ==> -1386.0628554198065\n",
"Episode * 10 * Avg Reward is ==> -1330.6460640495982\n",
"Episode * 11 * Avg Reward is ==> -1296.9259472439123\n",
"Episode * 12 * Avg Reward is ==> -1266.648683865007\n",
"Episode * 13 * Avg Reward is ==> -1217.2723090173156\n",
"Episode * 14 * Avg Reward is ==> -1163.0702894847986\n",
"Episode * 15 * Avg Reward is ==> -1105.9657062118963\n",
"Episode * 16 * Avg Reward is ==> -1056.4251588131688\n",
"Episode * 17 * Avg Reward is ==> -1004.7175789706645\n",
"Episode * 18 * Avg Reward is ==> -958.4439292235802\n",
"Episode * 19 * Avg Reward is ==> -916.8559819842148\n",
"Episode * 20 * Avg Reward is ==> -879.2971938851208\n",
"Episode * 21 * Avg Reward is ==> -839.4309276948444\n",
"Episode * 22 * Avg Reward is ==> -813.1273589718702\n",
"Episode * 23 * Avg Reward is ==> -784.5041398737862\n",
"Episode * 24 * Avg Reward is ==> -765.0508430770639\n",
"Episode * 25 * Avg Reward is ==> -740.464676744745\n",
"Episode * 26 * Avg Reward is ==> -721.947957211692\n",
"Episode * 27 * Avg Reward is ==> -705.225509729946\n",
"Episode * 28 * Avg Reward is ==> -685.144228863127\n",
"Episode * 29 * Avg Reward is ==> -670.6879188788478\n",
"Episode * 30 * Avg Reward is ==> -653.0154864082411\n",
"Episode * 31 * Avg Reward is ==> -643.4128610660125\n",
"Episode * 32 * Avg Reward is ==> -635.5798183939222\n",
"Episode * 33 * Avg Reward is ==> -623.9639787229108\n",
"Episode * 34 * Avg Reward is ==> -616.205090622738\n",
"Episode * 35 * Avg Reward is ==> -606.1140412258295\n",
"Episode * 36 * Avg Reward is ==> -603.6670876160974\n",
"Episode * 37 * Avg Reward is ==> -600.9921602699909\n",
"Episode * 38 * Avg Reward is ==> -591.8512444239832\n",
"Episode * 39 * Avg Reward is ==> -580.1600306375576\n",
"Episode * 40 * Avg Reward is ==> -553.821931002297\n",
"Episode * 41 * Avg Reward is ==> -521.7188034600143\n",
"Episode * 42 * Avg Reward is ==> -486.36319375176225\n",
"Episode * 43 * Avg Reward is ==> -453.6710442310697\n",
"Episode * 44 * Avg Reward is ==> -425.8450281985057\n",
"Episode * 45 * Avg Reward is ==> -400.74408779723456\n",
"Episode * 46 * Avg Reward is ==> -366.61738270546164\n",
"Episode * 47 * Avg Reward is ==> -345.13626004307355\n",
"Episode * 48 * Avg Reward is ==> -323.61757746366766\n",
"Episode * 49 * Avg Reward is ==> -301.23857698979566\n",
"Episode * 50 * Avg Reward is ==> -284.8999331286917\n",
"Episode * 51 * Avg Reward is ==> -264.84457621322116\n",
"Episode * 52 * Avg Reward is ==> -248.26764695916563\n",
"Episode * 53 * Avg Reward is ==> -237.25723863370771\n",
"Episode * 54 * Avg Reward is ==> -230.53260988021324\n",
"Episode * 55 * Avg Reward is ==> -236.8247039675385\n",
"Episode * 56 * Avg Reward is ==> -242.88089725188564\n",
"Episode * 57 * Avg Reward is ==> -249.99625421933737\n",
"Episode * 58 * Avg Reward is ==> -256.24104876179\n",
"Episode * 59 * Avg Reward is ==> -259.44539205532294\n",
"Episode * 60 * Avg Reward is ==> -259.771282922727\n",
"Episode * 61 * Avg Reward is ==> -266.78264262398795\n",
"Episode * 62 * Avg Reward is ==> -264.49970490719676\n",
"Episode * 63 * Avg Reward is ==> -264.7907401035075\n",
"Episode * 64 * Avg Reward is ==> -263.65884770574297\n",
"Episode * 65 * Avg Reward is ==> -263.8187150138804\n",
"Episode * 66 * Avg Reward is ==> -263.88096070288253\n",
"Episode * 67 * Avg Reward is ==> -263.68977140982696\n",
"Episode * 68 * Avg Reward is ==> -272.91279743733804\n",
"Episode * 69 * Avg Reward is ==> -272.777443352942\n",
"Episode * 70 * Avg Reward is ==> -283.87400325047287\n",
"Episode * 71 * Avg Reward is ==> -278.45777238816385\n",
"Episode * 72 * Avg Reward is ==> -272.09964609736335\n",
"Episode * 73 * Avg Reward is ==> -269.45733302243724\n",
"Episode * 74 * Avg Reward is ==> -263.91679852075515\n",
"Episode * 75 * Avg Reward is ==> -264.0434345954452\n",
"Episode * 76 * Avg Reward is ==> -260.102765623681\n",
"Episode * 77 * Avg Reward is ==> -253.51808301808424\n",
"Episode * 78 * Avg Reward is ==> -250.83738958549662\n",
"Episode * 79 * Avg Reward is ==> -254.1812329126542\n",
"Episode * 80 * Avg Reward is ==> -250.125238569467\n",
"Episode * 81 * Avg Reward is ==> -250.27037014579363\n",
"Episode * 82 * Avg Reward is ==> -250.1389180516676\n",
"Episode * 83 * Avg Reward is ==> -245.8142236436616\n",
"Episode * 84 * Avg Reward is ==> -245.1797777642314\n",
"Episode * 85 * Avg Reward is ==> -236.02398746977263\n",
"Episode * 86 * Avg Reward is ==> -239.18889403843315\n",
"Episode * 87 * Avg Reward is ==> -247.41187644346664\n",
"Episode * 88 * Avg Reward is ==> -247.82499330593242\n",
"Episode * 89 * Avg Reward is ==> -250.9072749126738\n",
"Episode * 90 * Avg Reward is ==> -263.1470922715929\n",
"Episode * 91 * Avg Reward is ==> -278.58573644976707\n",
"Episode * 92 * Avg Reward is ==> -280.6476742795351\n",
"Episode * 93 * Avg Reward is ==> -280.70748492063154\n",
"Episode * 94 * Avg Reward is ==> -280.565226725522\n",
"Episode * 95 * Avg Reward is ==> -268.37926234836465\n",
"Episode * 96 * Avg Reward is ==> -256.03979865280746\n",
"Episode * 97 * Avg Reward is ==> -255.01505149822543\n",
"Episode * 98 * Avg Reward is ==> -245.98157845584518\n",
"Episode * 99 * Avg Reward is ==> -245.54148137920984\n"
]
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZMAAAEGCAYAAACgt3iRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmU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z5rBD0h3wh8nMzibatp4KTHH334QcUo0zs+OBD4DFfNl/8BOi/SbPAj2ITt9/ibsf3LlX65nZycCt7n6umfUhWlNpCywArnL3gjDjq2lmNpLooIOGwGrgGqI/NOvstTazXwCXEh25uAD4NtH+gTp1rc3s38DJRKea3wrcBbxEOdc2SKwPEG3y2w9c4+6ZMX+WkomIiFSXmrlERKTalExERKTalExERKTalExERKTalExERKTalExEaoiZlZjZwjKPSidHNLMbzGxSDXzuWjNrX933EakODQ0WqSFmts/dm4fwuWuJzoC7PdGfLVJKNROROAtqDvea2WIzm2tm/YLyu83s1uD5LcH6MYvMbGpQ1tbMXgrK5pjZiKC8nZm9GazH8TBgZT7rquAzFprZP4JlE0TiTslEpOY0OaiZ69Iy+3LdfTjRO4z/Us5rbwdGufsI4Iag7BfAgqDsJ8ATQfldwIfuPhR4keidzJjZYKJ3dR/n7iOBEuDKmj1FkfKlHfoQEYnRgeBLvDz/LvP3z+XsXwT8y8xeIjrdBcDxwEUA7v5OUCNpSXT9kQuD8ulmtis4/jRgDPBpdGYMmlC3JmiUJKZkIpIYXsHzUucQTRLnAXea2fAqfIYBj7v7HVV4rUi1qJlLJDEuLfN3dtkdZpYCdHf3d4HbgFZAc6KTbV4ZHHMysD1YV2YWcEVQfhZQuj7728BEM+sY7GtrZj3jeE4i/6WaiUjNaWJmC8tsv+HupcOD25jZIqAAuPyg16UCTwVL6Bpwv7vvNrO7gSnB6/bz5bThvwD+bWZLgY+JTqmOuy8zs58CbwYJqgi4iejMsCJxpaHBInGmobtSH6iZS0REqk01ExERqTbVTEREpNqUTEREpNqUTEREpNqUTEREpNqUTEREpNr+PzuwM5S9NvHoAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"# To store reward history of each episode\n",
"ep_reward_list = []\n",
"# To store average reward history of last few episodes\n",
"avg_reward_list = []\n",
"\n",
"# Takes about 4 min to train\n",
"for ep in range(total_episodes):\n",
"\n",
" prev_state = env.reset()\n",
" episodic_reward = 0\n",
"\n",
" while True:\n",
" # Uncomment this to see the Actor in action\n",
" # But not in a python notebook.\n",
" # env.render()\n",
"\n",
" tf_prev_state = tf.expand_dims(tf.convert_to_tensor(prev_state), 0)\n",
"\n",
" action = policy(tf_prev_state, ou_noise)\n",
" # Recieve state and reward from environment.\n",
" state, reward, done, info = env.step(action)\n",
"\n",
" buffer.record((prev_state, action, reward, state))\n",
" episodic_reward += reward\n",
"\n",
" buffer.learn()\n",
" update_target(target_actor.variables, actor_model.variables, tau)\n",
" update_target(target_critic.variables, critic_model.variables, tau)\n",
"\n",
" # End this episode when `done` is True\n",
" if done:\n",
" break\n",
"\n",
" prev_state = state\n",
"\n",
" ep_reward_list.append(episodic_reward)\n",
"\n",
" # Mean of last 40 episodes\n",
" avg_reward = np.mean(ep_reward_list[-40:])\n",
" print(\"Episode * {} * Avg Reward is ==> {}\".format(ep, avg_reward))\n",
" avg_reward_list.append(avg_reward)\n",
"\n",
"# Plotting graph\n",
"# Episodes versus Avg. Rewards\n",
"plt.plot(avg_reward_list)\n",
"plt.xlabel(\"Episode\")\n",
"plt.ylabel(\"Avg. Epsiodic Reward\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XY85n6_l_wFb"
},
"source": [
"If training proceeds correctly, the average episodic reward will increase with time.\n",
"\n",
"Feel free to try different learning rates, `tau` values, and architectures for the\n",
"Actor and Critic networks.\n",
"\n",
"The Inverted Pendulum problem has low complexity, but DDPG work great on many other\n",
"problems.\n",
"\n",
"Another great environment to try this on is `LunarLandingContinuous-v2`, but it will take\n",
"more episodes to obtain good results."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "fDayimW0_wFb"
},
"outputs": [],
"source": [
"# Save the weights\n",
"actor_model.save_weights(\"pendulum_actor.h5\")\n",
"critic_model.save_weights(\"pendulum_critic.h5\")\n",
"\n",
"target_actor.save_weights(\"pendulum_target_actor.h5\")\n",
"target_critic.save_weights(\"pendulum_target_critic.h5\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hYiCdLyE_wFb"
},
"source": [
"Before Training:\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "D1lklgTJ_wFc"
},
"source": [
"After 100 episodes:\n",
"\n",
""
]
},
{
"cell_type": "code",
"source": [
"!pip install huggingface-hub\n",
"!curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash\n",
"!sudo apt-get install git-lfs\n",
"!git-lfs install"
],
"metadata": {
"id": "c6Ao1vi4_zwE",
"outputId": "a2aa4ade-a162-432f-92d3-1d1358c2ead6",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting huggingface-hub\n",
" Downloading huggingface_hub-0.2.1-py3-none-any.whl (61 kB)\n",
"\u001b[?25l\r\u001b[K |ββββββ | 10 kB 21.9 MB/s eta 0:00:01\r\u001b[K |βββββββββββ | 20 kB 14.7 MB/s eta 0:00:01\r\u001b[K |ββββββββββββββββ | 30 kB 11.1 MB/s eta 0:00:01\r\u001b[K |ββββββββββββββββββββββ | 40 kB 9.7 MB/s eta 0:00:01\r\u001b[K |βββββββββββββββββββββββββββ | 51 kB 5.2 MB/s eta 0:00:01\r\u001b[K |ββββββββββββββββββββββββββββββββ| 61 kB 5.8 MB/s eta 0:00:01\r\u001b[K |ββββββββββββββββββββββββββββββββ| 61 kB 446 kB/s \n",
"\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (3.4.0)\n",
"Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (21.3)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (3.13)\n",
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (3.10.0.2)\n",
"Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (4.8.2)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (4.62.3)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from huggingface-hub) (2.23.0)\n",
"Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging>=20.9->huggingface-hub) (3.0.6)\n",
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->huggingface-hub) (3.6.0)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->huggingface-hub) (2021.10.8)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->huggingface-hub) (2.10)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->huggingface-hub) (3.0.4)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->huggingface-hub) (1.24.3)\n",
"Installing collected packages: huggingface-hub\n",
"Successfully installed huggingface-hub-0.2.1\n",
"Detected operating system as Ubuntu/bionic.\n",
"Checking for curl...\n",
"Detected curl...\n",
"Checking for gpg...\n",
"Detected gpg...\n",
"Running apt-get update... done.\n",
"Installing apt-transport-https... done.\n",
"Installing /etc/apt/sources.list.d/github_git-lfs.list...done.\n",
"Importing packagecloud gpg key... done.\n",
"Running apt-get update... done.\n",
"\n",
"The repository is setup! You can now install packages.\n",
"Reading package lists... Done\n",
"Building dependency tree \n",
"Reading state information... Done\n",
"The following NEW packages will be installed:\n",
" git-lfs\n",
"0 upgraded, 1 newly installed, 0 to remove and 67 not upgraded.\n",
"Need to get 6,526 kB of archives.\n",
"After this operation, 14.7 MB of additional disk space will be used.\n",
"Get:1 https://packagecloud.io/github/git-lfs/ubuntu bionic/main amd64 git-lfs amd64 3.0.2 [6,526 kB]\n",
"Fetched 6,526 kB in 1s (6,123 kB/s)\n",
"debconf: unable to initialize frontend: Dialog\n",
"debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76, <> line 1.)\n",
"debconf: falling back to frontend: Readline\n",
"debconf: unable to initialize frontend: Readline\n",
"debconf: (This frontend requires a controlling tty.)\n",
"debconf: falling back to frontend: Teletype\n",
"dpkg-preconfigure: unable to re-open stdin: \n",
"Selecting previously unselected package git-lfs.\n",
"(Reading database ... 155226 files and directories currently installed.)\n",
"Preparing to unpack .../git-lfs_3.0.2_amd64.deb ...\n",
"Unpacking git-lfs (3.0.2) ...\n",
"Setting up git-lfs (3.0.2) ...\n",
"Git LFS initialized.\n",
"Processing triggers for man-db (2.8.3-2ubuntu0.1) ...\n",
"Git LFS initialized.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!huggingface-cli login"
],
"metadata": {
"id": "mBqbC9OLBIzY",
"outputId": "e213d779-fd78-49d6-affd-cfb0869e5624",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\n",
" _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|\n",
" _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
" _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|\n",
" _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
" _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|\n",
"\n",
" To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/token.\n",
" (Deprecated, will be removed in v0.3.0) To login with username and password instead, interrupt with Ctrl+C.\n",
" \n",
"Token: \n",
"Login successful\n",
"Your token has been saved to /root/.huggingface/token\n",
"\u001b[1m\u001b[31mAuthenticated through git-credential store but this isn't the helper defined on your machine.\n",
"You might have to re-authenticate when pushing to the Hugging Face Hub. Run the following command in your terminal in case you want to set this credential helper as the default\n",
"\n",
"git config --global credential.helper store\u001b[0m\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"\n",
"from huggingface_hub.keras_mixin import push_to_hub_keras\n",
"push_to_hub_keras(model = actor_model, repo_url = \"https://huggingface.co/keras-io/deep-deterministic-policy-gradient\", organization = \"keras-io\")"
],
"metadata": {
"id": "B6pop1vc_4yZ",
"outputId": "f1635dd0-ac6c-4375-8054-3c873f259ef5",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 141
}
},
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Cloning https://huggingface.co/keras-io/deep-deterministic-policy-gradient into local empty directory.\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n",
"INFO:tensorflow:Assets written to: deep-deterministic-policy-gradient/assets\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"To https://huggingface.co/keras-io/deep-deterministic-policy-gradient\n",
" 0e015ab..e37f692 main -> main\n",
"\n"
]
},
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'https://huggingface.co/keras-io/deep-deterministic-policy-gradient/commit/e37f69227324cae395ac0075b8bee416685d2c54'"
]
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "code",
"source": [
"push_to_hub_keras(model = critic_model, repo_url = \"https://huggingface.co/keras-io/deep-deterministic-policy-gradient\", organization = \"keras-io\")"
],
"metadata": {
"id": "89Cj-m50BQKv",
"outputId": "56899efb-3dda-4ca6-8656-f9060741b9b3",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 161
}
},
"execution_count": 13,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/content/deep-deterministic-policy-gradient is already a clone of https://huggingface.co/keras-io/deep-deterministic-policy-gradient. Make sure you pull the latest changes with `repo.git_pull()`.\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n",
"INFO:tensorflow:Assets written to: deep-deterministic-policy-gradient/assets\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"To https://huggingface.co/keras-io/deep-deterministic-policy-gradient\n",
" e37f692..fc4c3b0 main -> main\n",
"\n"
]
},
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'https://huggingface.co/keras-io/deep-deterministic-policy-gradient/commit/fc4c3b0eadf2d9d2e6ff7a59f4e1f99763d973fe'"
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"source": [
"push_to_hub_keras(model = target_actor, repo_url = \"https://huggingface.co/keras-io/deep-deterministic-policy-gradient\", organization = \"keras-io\")"
],
"metadata": {
"id": "wv-epAixBYAJ",
"outputId": "9c62ad0a-1523-4ba3-ced9-b6d8d3e1cbdc",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 161
}
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/content/deep-deterministic-policy-gradient is already a clone of https://huggingface.co/keras-io/deep-deterministic-policy-gradient. Make sure you pull the latest changes with `repo.git_pull()`.\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n",
"INFO:tensorflow:Assets written to: deep-deterministic-policy-gradient/assets\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"To https://huggingface.co/keras-io/deep-deterministic-policy-gradient\n",
" fc4c3b0..e34067a main -> main\n",
"\n"
]
},
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'https://huggingface.co/keras-io/deep-deterministic-policy-gradient/commit/e34067a57c76c29bf60d924f352e7d72708bec82'"
]
},
"metadata": {},
"execution_count": 14
}
]
},
{
"cell_type": "code",
"source": [
"push_to_hub_keras(model = target_critic, repo_url = \"https://huggingface.co/keras-io/deep-deterministic-policy-gradient\", organization = \"keras-io\")"
],
"metadata": {
"id": "3LVvvq2hBcfv",
"outputId": "c9b37d03-3f98-46d3-ee91-37e271bb5fbe",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 161
}
},
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/content/deep-deterministic-policy-gradient is already a clone of https://huggingface.co/keras-io/deep-deterministic-policy-gradient. Make sure you pull the latest changes with `repo.git_pull()`.\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n",
"INFO:tensorflow:Assets written to: deep-deterministic-policy-gradient/assets\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"To https://huggingface.co/keras-io/deep-deterministic-policy-gradient\n",
" e34067a..10b396f main -> main\n",
"\n"
]
},
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'https://huggingface.co/keras-io/deep-deterministic-policy-gradient/commit/10b396f3c297b2359d5b5e96f2b78a03943ec833'"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "yzwDvkqZBfFJ"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "ddpg_pendulum",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
} |