Table of Contents

T-720-ATAI-2021 Main

ATAI-21 Reykjavik University



Engineering Assignment 1:

Learning


Aim: This assignment is meant to give you a better insight into deep reinforcement learning and its difference to cumulative and life-long learning on the example of human learning.

Summary: In this first exercise you are asked to evaluate a given Deep-Reinforcement Learner (an actor-critic learner, to be specific; for further information see Konda & Tsitsiklis 2000) in different task-environments, coded in Python. The task-environment (or just task, really) is the well-known cart-pole task: Balancing a pole on a moving platform, in 1-D (left and right movements).

Additionally you are supposed to get a better idea on cumulative learning by example of a human learner - i.e. yourself. Furthermore, this assignment will highlight the importance of perception for learning and task solving. You are given Python code with an implementation of the same cart-pole task as the RL designed as a game for a human to play. For this, 4 different conditions have been implemented, giving you the chance to experience the importance of the presentation of data for yourself.


cart-pole-task.jpg
The cart-pole task.

Setup

Install python3 on your computer (https://www.python.org/downloads/).
Download the attached zip file and extract it to some location and cd into the folder.
Install the included requirements.txt file:

$ pip install -r requirements.txt

Run the code:

$ python main.py

For the first task (Deep-Reinforcement-Learning) you will need to install pytorch. Since this is different depending on which OS you use and whether you have a GPU which supports CUDA (Nvidia GPUs only) you should follow the installation instructions here.

Zip Files:
Assignment 1 Reinforcement Learning
Assignment 1 Reinforcement Learning Updated env.py file to correctly apply action noise
Assignment 1 Human Learning

Assignment 1.1: Deep Reinforcement Learning

Your task:

  1. Plain Vanilla. Evaluate the actor-critic’s performance on the cart-pole task given to you as python code:
    1. Run the learner repeatedly; collect the data. Stop each run when either 1000 epochs are reached or the agent manages to get more than 200 iterations in average per epoch over at least 100 continuous epochs (this is usually the case at around 400-500 epochs).
    2. Plot its improvement in performance over time.
  2. Modified Version. Evaluate the learner’s performance on a modified version of the cart-pole task. For this you should evaluate at least two of the following modifications of the environments and compare them to the results from 1.:
    1. Noise on observation and action.
    2. Hide each variable once (x, v, theta, omega) and run the setup with only three observables.
    3. Introduce extremely high noise on one observable for all four observables (three normal, one noisy variables).
    4. Change the task after a certain amount of epochs. Think of at least three different changes, one is given as an example in the code.
    5. Change the discreteness of time/ observables increasing or decreasing the variable resolution.
  3. Calculate the average score, median score, maximum score, and standard deviation of each task.


Further information

In the file “ac_learner.py” you can find the source code of an actor critic learner.

In the file “cart_pole_env.py” you can find the source code for the task environment. In order to evaluate the learner on the different environment settings the following methods are of importance:

apply_observation_noise:

Apply noise only to the observations received by the agent, NOT the internal environment variables

apply_action_noise:

Apply noise to the force applied to the cart-pole

apply_environment_noise:

Apply noise to the dynamics of the environment, but not to the observations of the agent

adjust_task:

Change the task in a chosen manner

apply_discretization:

discretize the data passed to the agent

In each of these methods you can implement a different method to adjust the task or the information passed to or from the agent. In “env.py” a helper class for noise is included, which you can use.

After the agent runs for the defined max number of epochs a plot is created of iterations per epoch. Use this to evaluate the learning performance of the learner. Extend the plots to include whatever information you deem to be important.

HINT You are allowed to change any parts of the learner or the environment, just make sure to document all changes and explain how and why they influence the learning performance of the agent.




Assignment 1.2: Human Learning

The Game

Condition 1: SYMBOLIC
You are presented with an alphanumeric display of a continuously updated state of observable variables relevant to the task (e.g. x, v, theta, and omega). With the arrow keys you can apply a force of -10 (left) or +10 (right) Newton to the cart. Your task is to keep the pole upright for as long as possible. In the top-right you can see your current score (the total reward you achieved in this epoch (+1 for each successful iteration)), in the center are the values of the observables. You can set the environment to run synchronous or async, meaning that, if sync is not set the environment updates automatically after 100 ms. Further, you can invert the forces by pressing the i key on your keyboard.

Condition 1 - symbolic



Condition 2: COLOR CODING
You are presented with colors for each of the variables as well as an arrow indicating if the value is negative (pointing to the left) or positive (pointing to the right). Green means a value around 0, the redder it becomes the closer to either edge you are. For v and omega (both not in the solution space restriction) red implies a high value, green a low value. Other things are the same as in Condition 1.

Condition 2 - color coding



Condition 3: COLORS & LINES
In the setting colors_lines the same colors are used as in Level 2; however, additionally a line is drawn on the bar giving you additional information of the current state of the observables. Otherwise things are the same as in Conditions 1 and 2.

Condition 3 - colors and lines



Condition 4: ANIMATION
In the animation setting an animation of the cart-pole is presented to you, including the cart (rectangle), the pole (line to the top of the image), the velocity (line inside the cart to the left or right), and the angular velocity (line at the top of the pole) indicating the current position and velocity of the cart. Otherwise this is the same as in Conditions 1.

Condition 4 - animation



Your task:

IMPORTANT: Read the full instructions before beginning.

  1. Your task is to get good at performing the task in all 4 Levels. Record the data for your training in each condition.
  2. Apply the following settings to the environment (If you downloaded and use the provided environment this should be the case already):
    1. All variables (x, v, theta, omega) are observables.
    2. Apply noise (all of them at the same time) to the environment with a mean of 0 and a standard deviation of
      1. x: 0.2 m
      2. v: 0.2 m/s
      3. theta: 1.0 deg
      4. omega: 0.2 rad/s
    3. Set the environment to run asynchronous
  3. Play the game on Conditions 1, 2, 3, and 4 in that order for at least 10 epochs (or better phrased: until you are confident in playing in the condition, but for at least 10 epochs) each and note for each condition your
    1. highest score,
    2. average score and standard deviation,
    3. median score.
  4. From now on only play on the two conditions in which you performed worst
  5. Invert the forces by pressing the “i” key on your keyboard during a run (after 5-10 restarts/ fails) and continue for another 5-10 episodes. Do this in the two conditions in which you performed worst earlier in the same order as previously. (Redo instruction 3 with this inversion). What can you say about your learning speed with force inversion?
  6. Reset the settings back to the ones from the beginning and replay the game (as described in the third instruction) on the two conditions you performed worst in the first tries.
  7. Compare your results from the first tries from number 3 to the others. What can you conclude about the possibilities of cumulative, life-long learning?


Further information

Try to not only do what you are asked, but rather investigate learning further by yourself (if you have the time to do so, of course). Some of the things you could to:

  1. Change dt, make it faster or slower.
  2. Try out the synchronous environment - this is actually, how reinforcement learners would play the game.
  3. Try the things you changed in the reinforcement learning part of this assignment for the RL now on yourself, for example changing the task in the middle of a run.
  4. Try even more (things the RL could not do, for example change the observation state during a run (e.g. after 100 iterations)).
  5. What else can you think of?
  6. You can adjust the plot_iterations function in the env.py file to plot additional information like mean, std_dev etc.
  7. Generally speaking: Feel free to add and/or remove anything you like. This is an assignment where you should reflect on your own learning abilities. Whatever you think might help you to get a better insight into your own learning is more than welcome. Please add all changes you have done to the report!

Try to make a point on the advantages and disadvantages of cumulative/ human learning.

Assignment 1.3: Report

  1. Report. Write a 4-5 page report where you describe your results. Draw some insights in relation to learning in general and try to make some generalizations based on them, and discuss, e.g.:
    1. Regarding RL:
      1. When does the actor-critic learner fail?
      2. Which changes will be impossible for the actor-critic to adjust to (try this out yourself from what you know of neural networks; hint: input and output layers of ANNs).
      3. What is your opinion of the generality and adaptability of the actor-critic learner with respect to novelty (novel task-environments)?
    2. Regarding human learning:
      1. Discuss the advantages, and disadvantages of human learning (and human nature).
      2. This might include (but is not restricted to):
        1. Previously acquired knowledge used in this game.
        2. Cumulative learning.
        3. Transfer learning.
        4. Boredom.
    3. Is RL in any way similar to how humans learn? If 'yes', how? If 'no', what's different, and why?
    4. Compare the RL to human learning.


Set up the conditions:
For most of the tasks given to you all you need is to change parts in the main.py or cart_pole_env.py, I hope it is self explaining, if any questions arise please ask!