Skip to content

fabdbt/python_ucb

Repository files navigation

Github Action

Description

A simple HTTP server that handle requests to feed a LinUCB machine learning algorithm

Dependencies

  • Python 3 and requirements.txt file dependencies

How to run it ?

pip3 install -r requirements.txt

python3 src/server.py

Otherwise, you can use docker to run it (see Dockerfile)

Endpoints:

  • GET /thetas : Get current thetas values

  • GET /a : Get current a values

  • GET /b : Get current b values

  • GET /arms : Get arms names

  • GET /stats : Get stats

  • GET /ping : Respond pong if API is running

  • POST /arms : Create arms (n_arms)

  • POST /reward : Send reward (arm, reward, x)

  • POST /tirages : Send tirages (generated random for moment)

  • POST /features : Add n feature(s)

  • DELETE /arms/:n : Delete arm (n)

Example requests :

Get current theta values :

curl -X GET \
  http://127.0.0.01:8080/thetas

Get current a values :

curl -X GET \
  http://127.0.0.01:8080/a

Get current b values :

curl -X GET \
  http://127.0.0.01:8080/b

Pick arm :

curl -X POST \
  http://localhost:8080/tirages \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'n=4&X=%7B%20%22a%22%3A%20%5B100%2C%207%5D%2C%20%22b%22%3A%20%5B10%2C%2044%5D%2C%20%22e%22%3A%20%5B100%2C%2091%5D%2C%20%22f%22%3A%20%5B10%2C%2092%5D%20%7D'

Post reward :

curl -X POST \
  http://localhost:8080/reward \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'arm=e&reward=100&x=0.94327796315973622&x=0.98546216493058936'

Add arm :

curl -X POST \
  http://127.0.0.01:8080/arms \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'arms=e&arms=f'

Delete arm :

curl -X DELETE \
  http://localhost:8080/arms/e

Add feature :

curl -X POST \
  http://127.0.0.01:8080/features \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d n=1

Stats :

curl -X GET \
  http://127.0.0.01:8080/stats

Ping :

curl -X GET \
  http://127.0.0.01:8080/ping

Virtualenv + dependencies commands :

pip install virtualenv
virtualenv venv
source venv/bin/activate
deactivate

pip freeze > requirements.txt
pip install -r requirements.txt

About

Python HTTP API implementation of LinUCB machine learning algorithm

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published