All Projects → jaybutera → tetrisRL

jaybutera / tetrisRL

Licence: MIT License
A Tetris environment to train machine learning agents

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tetrisRL

ml-ai
ML-AI Community | Open Source | Built in Bharat for the World | Data science problem statements and solutions
Stars: ✭ 32 (-27.27%)
Mutual labels:  supervised-learning
zoofs
zoofs is a python library for performing feature selection using a variety of nature-inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics-based to Evolutionary. It's easy to use , flexible and powerful tool to reduce your feature size.
Stars: ✭ 142 (+222.73%)
Mutual labels:  supervised-learning
Chess-Zero
Chess reinforcement learning by AlphaZero methods.
Stars: ✭ 36 (-18.18%)
Mutual labels:  supervised-learning
Deep-Learning-Mahjong---
Reinforcement learning (RL) implementation of imperfect information game Mahjong using markov decision processes to predict future game states
Stars: ✭ 45 (+2.27%)
Mutual labels:  supervised-learning
machine-learning
Programming Assignments and Lectures for Andrew Ng's "Machine Learning" Coursera course
Stars: ✭ 83 (+88.64%)
Mutual labels:  supervised-learning
textlytics
Text processing library for sentiment analysis and related tasks
Stars: ✭ 25 (-43.18%)
Mutual labels:  supervised-learning
wavenet-classifier
Keras Implementation of Deepmind's WaveNet for Supervised Learning Tasks
Stars: ✭ 54 (+22.73%)
Mutual labels:  supervised-learning
cattonum
Encode Categorical Features
Stars: ✭ 31 (-29.55%)
Mutual labels:  supervised-learning
dl-relu
Deep Learning using Rectified Linear Units (ReLU)
Stars: ✭ 20 (-54.55%)
Mutual labels:  supervised-learning
first-neural-network
Simple neural network implemented from scratch in C++.
Stars: ✭ 17 (-61.36%)
Mutual labels:  supervised-learning
machine learning from scratch matlab python
Vectorized Machine Learning in Python 🐍 From Scratch
Stars: ✭ 28 (-36.36%)
Mutual labels:  supervised-learning
omikuji
An efficient implementation of Partitioned Label Trees & its variations for extreme multi-label classification
Stars: ✭ 69 (+56.82%)
Mutual labels:  supervised-learning
machine-learning-course
Machine Learning Course @ Santa Clara University
Stars: ✭ 17 (-61.36%)
Mutual labels:  supervised-learning
SML CV
Using supervised machine learning to build collective variables for accelerated sampling
Stars: ✭ 20 (-54.55%)
Mutual labels:  supervised-learning
Kaio-machine-learning-human-face-detection
Machine Learning project a case study focused on the interaction with digital characters, using a character called "Kaio", which, based on the automatic detection of facial expressions and classification of emotions, interacts with humans by classifying emotions and imitating expressions
Stars: ✭ 18 (-59.09%)
Mutual labels:  supervised-learning
sutton-barto-rl-exercises
📖Learning reinforcement learning by implementing the algorithms from reinforcement learning an introduction
Stars: ✭ 77 (+75%)
Mutual labels:  supervised-learning
robo-vln
Pytorch code for ICRA'21 paper: "Hierarchical Cross-Modal Agent for Robotics Vision-and-Language Navigation"
Stars: ✭ 34 (-22.73%)
Mutual labels:  supervised-learning
RAMS
Official TensorFlow code for paper "Multi-Image Super Resolution of Remotely Sensed Images Using Residual Attention Deep Neural Networks".
Stars: ✭ 55 (+25%)
Mutual labels:  supervised-learning
Edge2Guard
Code for PerCom Workshop paper title 'Edge2Guard: Botnet Attacks Detecting Offline Models for Resource-Constrained IoT Devices'
Stars: ✭ 16 (-63.64%)
Mutual labels:  supervised-learning
Hand-Gesture-Recognition-Using-Background-Elllimination-and-Convolution-Neural-Network
Hand Gesture Recognition using Convolution Neural Network built using Tensorflow, OpenCV and python
Stars: ✭ 120 (+172.73%)
Mutual labels:  supervised-learning

TETRIS RL

PyPI version

Installation

You need to have pytorch pre-installed. Easy to use download scripts can be found on their website.

$ git clone https://github.com/jaybutera/tetrisRL
$ cd tetrisRL
$ python setup.py install

or

$ pip install tetrisrl

Layout

  • dqn_agent.py - DQN reinforcement learning agent trains on tetris
  • supervised_agent.py - The same convolutional model as DQN trains on a dataset of user playthroughs
  • user_engine.py - Play tetris and accumulate information as a training set
  • run_model.py - Evaluate a saved agent model on a visual game of tetris (i.e.)
$ python run_model.py checkpoint.pth.tar

Usage

Using the Environment

The interface is similar to an OpenAI Gym environment.

Initialize the Tetris RL environment

from engine import TetrisEngine

width, height = 10, 20
env = TetrisEngine(width, height)

Simulation loop

# Reset the environment
obs = env.clear()

while True:
    # Get an action from a theoretical AI agent
    action = agent(obs)

    # Sim step takes action and returns results
    obs, reward, done = env.step(action)

    # Done when game is lost
    if done:
        break

Example Usages

Play Tetris for Training Data

Play games and accumulate a data set for a supervised learning algorithm to trian on. An element of data stores a (state, reward, done, action) tuple for each frame of the game.

You may notice the rules are slightly different than normal Tetris. Specifically, each action you take will result in a corresponding soft drop This is how the AI will play and therefore how the training data must be taken.

To play Tetris:

$ python user_engine.py

Controls:
W: Hard drop (piece falls to the bottom)
A: Shift left
S: Soft drop (piece falls one tile)
D: Shift right
Q: Rotate left
E: Rotate right

At the end of each game, choose whether you want to store the information of that game in the data set. Data accumulates in a local file called 'training_data.npy'.

Example supervised learning agent from data

Run the supervised agent file and specify the standard training data file generated in the previous step as a command line argument.

$ python supervised_agent.py training_data.npy

Example reinforcement learning agent

# Start from a new randomized dqn agent
$ python dqn_agent.py
# Start from a the last recorded dqn checkpoint
$ python dqn_agent.py resume
# Specify a custom checkpoint
$ python dqn_agent.py resume supervised_checkpoint.pth.tar

The DQN agent currently optimizes on a metric of freedom of action. In essence the agent should learn to maximize the entropy of the board. A player in Tetris has the most freedom of action when the area is clear of pieces.

Watch a checkpoint play a game

$ python run_model.py checkpoint.pth.tar
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].