/MultiArmedBandits

Multiarmed Bandit Repository for Lecture

Primary LanguagePythonMIT LicenseMIT

pipeline status coverage report codestyle Latest Release

Multiarmed Bandits

Main Features

Features Multiarmedbandits
Documentation ✔️
Custom environments ✔️
Custom policies ✔️
Common interface ✔️
Ipython / Notebook friendly ✔️
PEP8 code style ✔️
High code coverage ✔️
Type hints ✔️

Description

Overview

This package contains

  1. functionalities and modules to write algorithms for multi-armed bandits,
  2. write environments for multi-armed bandits,
  3. test algorithms and compare them with each other.

In addition, some experiments are provided to analyse existing algorithms.

Installation

First Steps

Run

poetry install

in your working directory.

Usage

Tests

Git pre-commits

Git pre-commits are a type of hook in Git that allows you to run custom scripts or commands automatically before making a commit. Pre-commit hooks provide a way to enforce certain checks, validations, or actions before allowing a commit to be made, helping to maintain code quality and consistency in a project.

When you run git commit, Git triggers the pre-commit hook, which executes the defined script or command. The hook script can perform various tasks, such as running tests, code linting, formatting checks, static analysis, or any other custom validations specific to your project's requirements.

The pre-commit hook can examine the changes being committed, access the staged files, and even reject the commit if the script fails or returns a non-zero exit code. This allows you to enforce rules or standards on the committed code and prevent potentially problematic changes from being added to the repository.

  1. Create a git pre-commit hook by creating a pre-commit bash script by running the following lines of code inside your repository:

    touch .git/hooks/pre-commit
  2. Then add code to the bash script by running:

    open .git/hooks/pre-commit
  3. Add the following code to the file

    #!/bin/zsh
    
    # Activate the virtual environment
    source .venv/bin/activate
    
    echo "Running Pytest..."
    pytest tests/
    
    if [ $? -ne 0 ]; then
      echo "Pytest failed. Aborting commit."
      exit 1
    fi
    echo "Check Codestyle..."
    make check-codestyle
    
    if [ $? -ne 0 ]; then
      echo "Codestyle check failed. Aborting commit."
      exit 1
    fi
  4. The last step is to make the file executable by running:

    chmod +x .git/hooks/pre-commit

Now when a git commit is started, pytest is run beforehand. If a test is not successful, the commit is aborted.

Contributing

License