项目作者: pm3310

项目描述 :
WIP: A library and AWS sdk for non-contextual and contextual Multi-Armed-Bandit (MAB) algorithms for multiple use cases
高级语言: Python
项目地址: git://github.com/pm3310/pulpo.git
创建时间: 2020-04-02T22:31:19Z
项目社区:https://github.com/pm3310/pulpo

开源协议:MIT License

下载


Build Status

master: Build Status

pulpo

A library and sdk for non-contextual and contextual Multi-Armed-Bandit (MAB) algorithms for multiple use cases. The sdk version enables you to deploy it on AWS.

Installation

Prerequisites

pulpo requires Python 3.6+

Install pulpo

At the command line:

  1. pip install pulpo

How To

Library

Pulpo can be used as a library to instantiate and run online MABs. The core of the library are the bandit implementations under pulpo/badnits module. The super class of them is OnlineBandit if you wish to implement your own MAB implementation.

Currently, the following MAB implementations are available:

  • Epsilon Greedy (EGreedy)

The usage of this library starts from Pulpo class. For example, let’s say that we want to run 1 online bandit with 3 arms using EGreedy, then:

  1. from pulpo.bandits.dataclasses import EpsilonGreedyArm
  2. from pulpo.bandits.epsilon_greedy import EGreedy
  3. from pulpo.pulpo import Pulpo
  4. arm_names = ["article1", "article2", "article3"]
  5. arms = [EpsilonGreedyArm(name, 1, 0) for name in arm_names] # priors for n=1 and sum=0, i.e. steps and total reward so far
  6. bandit = EGreedy("article_recommendation", arms, epsilon=0.9)
  7. pulpo = Pulpo([bandit]) # Instantiate Pulpo
  8. arm_id = pulpo.choose(bandit.bandit_id) # to get an arm decision
  9. # get some feedback for the arm decision and pass it to back
  10. feedback = 1.0
  11. pulpo.update(bandit.bandit_id, arm_id, feedback)

Alternatively, the Pulpo class can be instantiated in the following manner:

  1. import json
  2. from pulpo.pulpo import Pulpo
  3. bandit_id = "article_recommendation"
  4. config = config = [{"bandit_id": bandit_id, "bandit_type": "epsilon_greedy", "arm_ids": ["article1", "article2", "article3"]}]
  5. pulpo = Pulpo.make_from_json(json.dumps(config)) # Instantiate Pulpo
  6. arm_id = pulpo.choose(bandit_id) # to get an arm decision
  7. # get some feedback for the arm decision and pass it to back
  8. feedback = 1.0
  9. pulpo.update(bandit_id, arm_id, feedback)

AWS SDK

Pulpo can be used as an sdk to deploy and run MABs on AWS. Soon…