コード例 #1
0
def master(true_utilities, strategy_name="titration-0.05"):
    user = User(
        ufun=MappingUtilityFunction(
            dict(zip([(_,) for _ in range(n_outcomes)], true_utilities)),
            reserved_value=0.0,
        ),
        cost=cost,
    )
    strategy = EStrategy(strategy=strategy_name)
    return user, strategy
コード例 #2
0
 def test_elicit_until(self, neg):
     for s in ("bisection", "titration+0.05", "titration-0.05", "pingpong"):
         user = User(ufun=ufun, cost=cost)
         stretegy = EStrategy(strategy=s, resolution=1e-3)
         stretegy.on_enter(neg.ami)
         outcome, query, qcost = next_query(
             strategy=stretegy, outcome=(0,), user=user
         )[0]
         stretegy.until(
             user=user, outcome=(0,), dist=query.answers[1].constraint.marginal((0,))
         )
コード例 #3
0
 def test_countable_outcomes_user_can_return_next_queries(self, neg):
     for s in (
         "exact",
         "bisection",
         "titration+0.05",
         "titration-0.5",
         "dtitration+0.5",
         "dtitration-0.05",
     ):
         strategy = EStrategy(strategy=s)
         user = User(ufun=ufun, cost=cost)
         strategy.on_enter(neg.ami)
         q = next_query(strategy=strategy, user=user)
         # print(f'{strategy} Strategy:\n---------------')
         # pprint.pprint(q)
         assert len(q) > 0, "returns some queries"
コード例 #4
0
 def test_elicitor_can_run_from_genius_domain(self, data_folder):
     domain, agents_info, issues = load_genius_domain_from_folder(
         os.path.join(data_folder, "Laptop"),
         force_single_issue=True,
         keep_issue_names=False,
         keep_value_names=False,
     )
     domain.add(LimitedOutcomesNegotiator(), ufun=agents_info[0]["ufun"])
     # domain.n_steps = 10
     user = User(ufun=agents_info[0]["ufun"], cost=0.2)
     strategy = EStrategy(strategy="titration-0.5")
     strategy.on_enter(ami=domain.ami)
     elicitor = PandoraElicitor(strategy=strategy, user=user)
     domain.add(elicitor)
     front, _ = domain.pareto_frontier()
     domain.run()
     assert len(domain.history) > 0
コード例 #5
0
 def test_countable_outcomes_user_can_return_all_queries(self, neg):
     for s in (
             "exact",
             "bisection",
             "titration+0.05",
             "titration-0.5",
             "dtitration+0.5",
             "dtitration-0.05",
             "pingpong0.5",
             "dpingpong0.5",
     ):
         user = User(ufun=ufun, cost=cost)
         strategy = EStrategy(strategy=s)
         strategy.on_enter(neg.ami)
         q = possible_queries(ami=neg.ami, strategy=strategy, user=user)
         assert (len(q) > 0 and s != "exact"
                 or len(q) == 0 and s == "exact"), "returns some queries"
コード例 #6
0
 def test_elicitor_can_get_frontier(self, data_folder):
     domain, agents_info, issues = load_genius_domain_from_folder(
         os.path.join(data_folder, "Laptop"),
         force_single_issue=True,
         keep_issue_names=False,
         keep_value_names=False,
         normalize_utilities=True,
     )
     assert len(issues) == 1
     assert len(agents_info) == 2
     domain.add(LimitedOutcomesNegotiator(), ufun=agents_info[0]["ufun"])
     user = User(ufun=agents_info[0]["ufun"], cost=cost)
     strategy = EStrategy(strategy="titration-0.5")
     strategy.on_enter(ami=domain.ami)
     elicitor = FullKnowledgeElicitor(strategy=strategy, user=user)
     domain.add(elicitor)
     front, _ = domain.pareto_frontier()
     assert front == [(1.0, 1.0)]
コード例 #7
0
 def test_countable_outcmoes_user_initializable(self):
     user = User(ufun=ufun, cost=cost)
     assert user.total_cost == 0.0, "total cost is not initialized to zero"
コード例 #8
0
def user() -> User:
    return User(ufun=ufun, cost=cost)
コード例 #9
0
 def test_pareto_frontier_2(self):
     n_outcomes = 10
     strategy = "titration-0.5"
     cost = 0.01
     reserved_value = 0.1
     outcomes = [(_,) for _ in range(n_outcomes)]
     accepted = [(2,), (3,), (4,), (5,)]
     elicitor_utilities = [
         0.5337723805661662,
         0.8532272031479199,
         0.4781281413197942,
         0.7242899747791032,
         0.3461879818432919,
         0.2608677043479706,
         0.9419131964655383,
         0.29368079952747694,
         0.6093201983562316,
         0.7066918086398718,
     ]
     # list(np.random.rand(n_outcomes).tolist())
     opponent_utilities = [
         1.0 if (_,) in accepted else 0.0 for _ in range(n_outcomes)
     ]
     frontier, frontier_locs = pareto_frontier(
         [
             MappingUtilityFunction(
                 lambda o: elicitor_utilities[o[0]],
                 reserved_value=reserved_value,
                 outcome_type=tuple,
             ),
             MappingUtilityFunction(
                 lambda o: opponent_utilities[o[0]],
                 reserved_value=reserved_value,
                 outcome_type=tuple,
             ),
         ],
         outcomes=outcomes,
         sort_by_welfare=True,
     )
     welfare = (
         np.asarray(elicitor_utilities) + np.asarray(opponent_utilities)
     ).tolist()
     # print(f'frontier: {frontier}\nmax. welfare: {max(welfare)} at outcome: ({welfare.index(max(welfare))},)')
     # print(f'frontier_locs: frontier_locs')
     neg = SAOMechanism(outcomes=n_outcomes, n_steps=10, outcome_type=tuple)
     opponent = LimitedOutcomesNegotiator(
         acceptable_outcomes=accepted,
         acceptance_probabilities=[1.0] * len(accepted),
     )
     eufun = MappingUtilityFunction(
         dict(zip(outcomes, elicitor_utilities)),
         reserved_value=reserved_value,
         outcome_type=tuple,
     )
     user = User(ufun=eufun, cost=cost)
     strategy = EStrategy(strategy=strategy)
     strategy.on_enter(ami=neg.ami)
     elicitor = FullKnowledgeElicitor(strategy=strategy, user=user)
     neg.add(opponent)
     neg.add(elicitor)
     neg.run()
     f2, f2_outcomes = neg.pareto_frontier(sort_by_welfare=True)
     assert len(frontier) == len(f2)
     assert all([_1 == _2] for _1, _2 in zip(frontier, f2))
     assert [_[0] for _ in f2_outcomes] == frontier_locs