Code Monkey home page Code Monkey logo

flaprl's Introduction

doubleDQN for Flappy-bird env

HUST CS Reinforcement Learning 2023 Fall (Master course)

Environment

The environment is flappy-bird, which is a famous game. You need to keep the bird alive by touching the screen in proper time. Otherwise the bird hit ground or the pipe, game is over.

The game can be divided into three levels of difficulty by the gap size between upper pipe and lower pipe. On easy difficulty, the gap size is 200, middle is 150, hard is 100.

Alt text Fig 1. Different difficulty in game (left to right: easy, middle, hard)

Improvement

  1. From DQN to doubleDQN

    a. training in DQN: $y_j=r_j+\gamma\max_{a'} \hat Q(\phi_{j+1},a',\theta^-)$

    $v_j=Q(\phi_{j+1},a_j,\theta)$

    $loss=avg(\Vert v-y\Vert^2)$

    b. training in doubleDQN: $y_j=r_j+\gamma\hat Q(\phi_{j+1},argmax_{ a'}Q(\phi_{j+1}, a',\theta),\theta^-)$

    $v_j=Q(\phi_{j+1},a_j,\theta)$

    $loss=avg(\Vert v-y\Vert^2)$

  2. Modified state space

    Use distance (x&y) to the next pipe and y_velocity.

    Also add bird's distance to next next pipe when the bird is in the pipe. (Borrow the idea from this blog)

    So the final state space is dist_x (to next pipe), dist_y (to next pipe), y_vel , dist_y' (to next next pipe when bird is in the pipe).

  3. Model design Use Gaussian RBF kernel to embed the scalar feature to vector. And use transformerEncoder layer to interact between data. Alt text Fig 2. Model architecture

  4. Post-process reward on episode Will post-process the reward on the episode according to the cause of death. When the bird fly too high, algorithm will give penalty to the last flap frame. Similarly, when the bird fly too low, algorithm will give penalty to the last flap frame and random frame between death frame and the last flap frame. And under all situation, give penalty to last two frame before death. (The penalty for upper pipe is borrowed from this blog too, while the penalty for lower pipe is my own idea) Alt text Fig 3. Post-process algorithm (Arrow symbol is the flap frame, while checkmark is the frame to give penalty)

Result

Alt text Fig 4. Train result under middle and hard difficulty. (Get one score when the bird pass one pipe)

Reference

flaprl's People

Contributors

taivu1998 avatar polowitty avatar zhou-ay avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.