Bandit test support api.
Logics are from Bandit Algorithms for Website Optimization
- epsilon-greedy
- softmax
- ucb1
$ npm install -g bandit-api
- write your config (default is here)
$ bandit-cmd -c /path/to/config
or runs as default$ bandit-cmd
$ bandit-cmd --help
Usage: bandit-cmd [options]
Options:
-h, --help output usage information
-V, --version output the version number
-c, --config <path> set config path
yourhost:13579/
(13579 is default port)
- All request should have
Content-type: application/json
header - All request parameters must embed on request body
- All response has
200
(success) or400
(fail) status - All response has json body
Creates new bandit model.
parameter | type | required | description |
---|---|---|---|
algorithm | string | true | algorithm name epsilon_greedy , softmax or ucb_1 |
arm_names | string[] | either arm_names or num_arms required |
name of arm(s) |
num_arms | integer | either arm_names or num_arms required |
arm counts |
settings | object | true | algorithm depended settings |
settings.epsilon | number | required in epsilon_greedy |
value of epsilon. (0<=epsilon<=1) |
settings.tau | number | required in softmax |
tau parameter value(annealing templature) (0<=tau) |
Response body contains created model. Your application must coordinate arm_ids and your options.
{
"algorithm": "EpsilonGreedy",
"model_id": "558d81548bacc82746f2ca6a",
"arms": [
{
"name": "alice",
"arm_id": "558d81548bacc82746f2ca6f",
"value": 0
},
{
"name": "bob",
"arm_id": "558d81548bacc82746f2ca6e",
"value": 0
}
],
"settings": {
"epsilon": 0.4
}
}
$ curl -H "Content-type: application/json" -X POST -d '{"algorithm": "epsilon_greedy","arm_names":["alice", "bob"],"settings":{"epsilon":0.8}}' localhost:13579/create
$ curl -H "Content-type: application/json" -X POST -d '{"algorithm": "epsilon_greedy","num_arms":5,"settings":{"epsilon":0.8}}' localhost:13579/create
Get status of current bandit model.
parameter | type | required | description |
---|---|---|---|
model_id | string | true | model's id returned from create api |
It is same format of create's response.
{
"model_id": "558d81548bacc82746f2ca6a",
"algorithm": "EpsilonGreedy",
"arms": [
{
"name": "alice",
"arm_id": "558d81548bacc82746f2ca6f",
"value": 0
},
{
"name": "bob",
"arm_id": "558d81548bacc82746f2ca6e",
"value": 1.388
}
],
"settings": {
"epsilon": 0.4
}
}
$ curl -H "Content-type: application/json" -X GET -d '{"model_id":"558bae466b1296aa733176f6"}' localhost:13579/status
Get arm's id that your application should test.
parameter | type | required | description |
---|---|---|---|
model_id | string | true | model's id returned from create api |
{
"name": "alice",
"arm_id": "558d81548bacc82746f2ca6f"
}
$ curl -H "Content-type: application/json" -X GET -d '{"model_id":"558bae466b1296aa733176f6"}' localhost:13579/get
Insert a test result to your bandit model.
parameter | type | required | description |
---|---|---|---|
model_id | string | true | model's id returned from create api |
arm_id | string | true | arm's id returned from get api |
reward | number | true | testing result value. ucb_1 has a limitation 0 <= reward <= 1 |
Empty response.
{}
$ curl -H "Content-type: application/json" -X POST -d '{"model_id":"558bae466b1296aa733176f6", "arm_id":"558bae466b1296aa733176f9","reward":3}' localhost:13579/insert
Delete your bandit test model.
parameter | type | required | description |
---|---|---|---|
model_id | string | true | model's id returned from create api |
Empty response.
{}
$ curl -H "Content-type: application/json" -X DELETE -d '{"model_id":"558bae466b1296aa733176f6"}' localhost:13579/delete
- Add new algorithm: exp3
- Add new api for arm maneuvering (add/delete/add name/update name)
- Add request result field to response object