Zum Inhalt

Strategies

Participation Strategy

Bases: Protocol

Source code in src/agents/strategies.py
 9
10
class ParticipationStrategy(Protocol):
    def decide_participation(self, agent: Any, area: Any) -> bool: ...

Voting Strategy

Bases: Protocol

Build a ballot as raw oppose-scores over options.

Contract: - Returns np.ndarray shape (num_options,) - Values are in [0,1] - Lower = better - No normalization (do not force sum==1)

IMPORTANT: must not mutate/reshuffle agent knowledge sampling. agent.known_cells is assumed to have been populated by Area._tally_votes().

Source code in src/agents/strategies.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class VotingStrategy(Protocol):
    """Build a ballot as raw oppose-scores over options.

    Contract:
    - Returns np.ndarray shape (num_options,)
    - Values are in [0,1]
    - Lower = better
    - No normalization (do not force sum==1)

    IMPORTANT: must not mutate/reshuffle agent knowledge sampling.
    `agent.known_cells` is assumed to have been populated by Area._tally_votes().
    """

    def score_options(self, agent: Any, area: Any, options: np.ndarray) -> np.ndarray: ...

Default Participation Strategy

Adaptive probabilistic participation using agent.q_participation.

Source code in src/agents/strategies.py
29
30
31
32
33
34
35
36
@dataclass(frozen=True)
class DefaultParticipationStrategy:
    """Adaptive probabilistic participation using agent.q_participation."""

    def decide_participation(self, agent: Any, area: Any) -> bool:
        p = agent.participation_probability()
        # determinism + stream isolation: participation has its own RNG stream.
        return bool(agent.model.participation_rng.random() < p)

Default Voting Strategy

Two-mode ballot scoring with altruism_factor as mode probability.

  • self-regarding mode: return agent-held precomputed self_regarding_oppose_scores
  • altruistic mode: estimate reality -> ordering -> option oppose-scores
Source code in src/agents/strategies.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@dataclass(frozen=True)
class DefaultVotingStrategy:
    """Two-mode ballot scoring with altruism_factor as mode probability.

    - self-regarding mode: return agent-held precomputed `self_regarding_oppose_scores`
    - altruistic mode: estimate reality -> ordering -> option oppose-scores
    """

    def score_options(self, agent: Any, area: Any, options: np.ndarray) -> np.ndarray:
        altruism_factor = float(np.clip(agent.altruism_factor, 0.0, 1.0))
        # Dedicated voting stream (already isolated from participation RNG).
        if agent.model.voting_rng.random() < altruism_factor:
            # Assumes Area._tally_votes already populated agent.known_cells for this election.
            est_real_dist, _conf = agent.estimate_real_distribution(area)
            target_ordering = ordering_from_distribution(
                np.asarray(est_real_dist, dtype=np.float32),
                rng=agent.model.voting_rng,
            )
            agent.voted_altruistically = True
            return agent.model.get_altruistic_oppose_scores_for_ordering(target_ordering)

        agent.voted_altruistically = False
        return np.asarray(agent.self_regarding_oppose_scores, dtype=np.float32)