Code Monkey home page Code Monkey logo

copt-irl's Introduction

This repository contains the code produced for my master's dissertation, "Learning Shaped Rewards via Adversarial Imitation Learning for Combinatorial Optimisation".

In my dissertation, I produced and analysed a method for learning to route circuits from exploration and demonstration. Unfortunately, I have not yet received permission to share the circuit routing code from the company I worked with, but all of the code on the ML/RL and analysis side is included in this repo.

The model I created is primarily inspired by the Transformer-based model from "Attention, Learn to Solve Routing Problems!" (Kool et al. 2019), while the adversarial training method is inspired by "Learning Robust Rewards with Adversarial Inverse Reinforcement Learning" (Fu et al. 2018).

Further details of the model are included in Section 6 of my dissertation, which I have included in the repo. The structure of the repo is described below.

Model code

  • irlco.pointer_transformer: Specifies the policy and reward-shaping models as PyTorch modules.

  • irlco.pointer_multihead: Modified versions of the multi-head attention modules from the PyTorch library that return attention scores rather than attention weights. This is necessary for the final layer of the decoder in the policy model.

  • irlco.routing.reward: Methods associated with the reward model. Includes a method for computing shaping terms directly from environment states using the reward-shaping net, and a method for calculating rewards from shaping terms.

  • irlco.routing.policy: Methods associated with the policy model. Includes methods for generating action sequences using greedy search, beam search and sampling.

Environment

  • irlco.routing.env: Implements the circuit routing MDP as an OpenAI Gym environment. Also contains a method for calculating terminal rewards from solution measures and successes, and a method for generating problem instances with at least 30 units of clearance between nodes.

Training

  • irlco.routing.train: Script that trains models for the circuit routing problem. Includes configurable parameters for changing model architecture, enabling learning shaped rewards, as well as other training hyperparameters. Also includes remote logging of model configuration and training performance through the Weights & Biases API, and a method for saving and loading expert data from pickle files to decrease startup time.

Data

  • irlco.routing.data.generate_training_data: Methods for generating and saving brute-forced solutions to circuit routing problems. The quantity and type of data to generate can be specified in a YAML config file, which then serves as a manifest for the data after generation. Two example config files are supplied.

  • irlco.routing.data: Implements a class for loading generated data according to a YAML config file, and allows the loaded data to be accessed in batches. In practice, instances of these classes are pickled by the training script after loading for the first time, as parsing the data from text files takes a long time.

Experiments

  • irlco.routing.copt_analysis: Used to find the number of solutions and ranges of measures in Chapter 3. The scripts used to create the plots are in the irlco/routing/copt_analysis folder.

  • irlco.routing.beam_search_experiment: Used to evaluate beam search performance of the trained models in the second experiment.

  • irlco.routing.active_search_experiment: Used to evaluate active search performance in the third experiment.

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.