def test_choose_rank(self): model = rl_client.live_model(self.config) model.init() event_id = "event_id" context = '{"_multi":[{},{}]}' model.choose_rank(event_id, context)
def main(): config = load_config_from_json("client.json") test_cb = my_error_callback() model = rl_client.live_model(config, test_cb) model.init() event_id = "event_id" context = '{"User":{"id":"a","major":"eng","hobby":"hiking"},"_multi":[{"N1":{"F1":"V1"},"N2":{"F2":"V2"}},{"N3":{"F1":"V3"}}]}' model_id, chosen_action_id, action_probabilities = model.choose_rank( event_id, context) print("event_id: " + event_id) print("model_id: " + model_id) print("chosen action id: " + str(chosen_action_id)) print("all action probabilities " + str(action_probabilities)) model_id, chosen_action_id, action_probabilities, event_id = model.choose_rank( context) print("event_id: " + event_id) print("model_id: " + model_id) print("chosen action id: " + str(chosen_action_id)) print("all action probabilities " + str(action_probabilities)) outcome = 1.0 model.report_outcome(event_id, outcome)
def test_choose_rank_invalid_event_id(self): model = rl_client.live_model(self.config) model.init() invalid_event_id = "" context = '{"_multi":[{},{}]}' self.assertRaises(Exception, model.choose_rank, invalid_event_id, context)
def test_choose_rank_invalid_context(self): model = rl_client.live_model(self.config) model.init() event_id = "event_id" invalid_context = "" self.assertRaises(Exception, model.choose_rank, event_id, invalid_context)
def test_report_outcome(self): model = rl_client.live_model(self.config) model.init() event_id = "event_id" context = '{"_multi":[{},{}]}' model.choose_rank(event_id, context) model.report_outcome(event_id, 1.0) model.report_outcome(event_id, "{'result':'res'}")
def __init__(self, args): self._options = args self.config = load_config_from_json(self._options.json_config) self._rl_client = rl_client.live_model(self.config, my_error_callback()) self._rl_client.init() tp1 = {'HerbGarden': 0.3, "MachineLearning": 0.2 } tp2 = {'HerbGarden': 0.1, "MachineLearning": 0.4 } self._actions = ['HerbGarden', 'MachineLearning'] self._people = [ person('rnc', 'engineering', 'hiking', 'spock', tp1), person('mk', 'psychology', 'kids', '7of9', tp2)]
def main(args): options = process_cmd_line(args) config = load_config_from_json(options.json_config) model = rl_client.live_model(config, my_error_callback()) model.init() with open(options.log_file) as fp: for count, line in enumerate(fp): current_example = json.loads(line) context_json = json.dumps(current_example["c"]) model_id, chosen_action_id, actions_probabilities = model.choose_rank( current_example["EventId"], context_json) if ("o" in current_example): for observation in current_example["o"]: outcome = observation["v"] if isinstance( observation["v"], numbers.Real) else json.dumps( observation["v"]) model.report_outcome(observation["EventId"], outcome)