AI Wiki中文/EN

竞争智能体:利用对手,而不让自己被利用

Competitive agents

把对立利益建模为零和博弈,让虚拟对局分别对抗固定、会适应和自博弈的对手,并测量“赢过某个对手”与“对所有对手都安全”之间的差距。

本页目录直觉理解数学与方法代码实现局限与误解实验与练习研究脉络

一个先赢、后来每轮都输的石头剪刀布程序

设想一场假想的程序石头剪刀布比赛。你的程序观察对手,统计它出过哪些手势,然后总是出能克制对手最可能下一手的那一招。面对一个一半时间出石头的随意对手,它稳定获胜。随后它遇到一个读过你程序源代码的对手。那个对手能精确预测你的每一手并出克制招。你的程序于是每一轮都输。

这正是竞争智能体(competitive agents)的核心张力:智能体之间利益对立,一方所得即另一方所失。智能体可以设法利用眼前实际遇到的对手,也可以设法对任何可能遇到的对手都不可被利用。这两个目标方向不同,而且智能体适应得越多,泄露的信息可能越多。本文用一个完全脚本化的小实验梳理这种权衡,再看一个有意设计竞争的例子:训练两个智能体辩论,让较弱的裁判也能判断谁是对的。

博弈的解概念、纳什均衡的定义与计算,以及深度自博弈强化学习各有专文。这里关注的是会适应的智能体彼此对抗时的行为,以及如何评估它们。

对立利益、对对手的信念与可利用度

在两人零和博弈中,任一联合行动下两位玩家的收益之和为零:

u1(a1,a2)=−u2(a1,a2)u_1(a_1,a_2)=-u_2(a_1,a_2)

石头剪刀布是标准例子。按石头、布、剪刀排列行动,行玩家的收益矩阵为

A=(0−1110−1−110)A=\begin{pmatrix}0&-1&1\\1&0&-1\\-1&1&0\end{pmatrix}

列玩家得到其相反数。若对手以概率y混合石头、布、剪刀,行玩家采取行动a的期望收益为(Ay)_a,任何使其最大的行动都是最佳响应。若y=(0.5, 0.3, 0.2),出布得0.5×1+0.3×0+0.2×(−1)=0.3,是可得的最高值。

虚拟对局(fictitious play)是智能体适应对手的最古老方法之一。Shoham与Leyton-Brown把它描述为基于模型的学习规则:智能体认为对手在使用一个固定的混合策略,其概率等于对手过去行动的经验频率;它对这一信念做最佳响应,观察对手的实际行动并更新计数。虚拟对局 设w_t(b)为对手出过b的次数(加上任何先验计数):

σ^−it(b)=wt(b)∑b′wt(b′),ait+1∈arg⁡max⁡a∑bσ^−it(b) ui(a,b)\hat\sigma_{-i}^{t}(b)=\frac{w_t(b)}{\sum_{b'}w_t(b')},\qquad a_i^{t+1}\in\arg\max_{a}\sum_b\hat\sigma_{-i}^t(b)\,u_i(a,b)

书中指出,这一规则最初是作为计算零和博弈均衡的迭代方法提出的,而不是学习模型;它对初始信念非常敏感;先验计数不能全为零,因为那样无法定义分布。它的结论针对的是对局的经验频率:如果这些频率收敛,就收敛到纳什均衡,而在零和博弈中它们确实收敛。实际出招未必稳定下来,收益也可能令人失望:在书中的反协调博弈例子里,双方频率都达到混合均衡,但由于出招总是错配,实际收益始终为0。收敛结论与反例

两个事实解释了开头的故事。第一,给定历史,虚拟对局是确定性的。知道规则的对手可以算出它的下一手并每次都赢。第二,在石头剪刀布中纯行动最容易被利用:无论你固定出哪一招,总有一种回应让你得到−1。均匀随机化保证对每一个对手的期望收益都是0,但也放弃了对付随意对手时可得的0.3。

衡量一对策略离“安全”有多远的标准方法是可利用度(exploitability):两位玩家各自改用最佳响应所能获得的收益之和。在零和博弈中,对行玩家的混合策略x和列玩家的混合策略y,

ε(x,y)=max⁡a (Ay)a−min⁡b (x⊤A)b\varepsilon(x,y)=\max_{a}\,(Ay)_a-\min_{b}\,(x^{\top}A)_b

第一项是行玩家针对y的最佳响应收益;第二项连同其符号是列玩家的。在石头剪刀布中博弈值为0,所以ε≥0,当且仅当(x,y)是均衡时取等号;这里只有均匀策略对满足。

Shoham与Leyton-Brown还强调了两点,与评估直接相关。学习与教导不可分:在重复的胆小鬼博弈中,面对会学习做最佳响应的对手,一个智能体可以始终选择“冒进”,从而“教会”对方退让,并因此获益。而且没有哪种学习程序能对所有可能的对手都最优;可以用自博弈来评判学习者,也可以看它对其他类型智能体的表现,或看哪些学习规则彼此构成均衡。为什么多智能体学习很复杂

竞争也可以被有意地设计进系统。Irving、Christiano与Amodei提出通过零和辩论博弈的自博弈来训练智能体:两个智能体看到同一个问题,各自给出答案,轮流发表简短陈述,再由裁判判断谁提供了最真实、最有用的信息。这一方法依赖一个明确陈述的论断——在辩论中说谎比驳倒谎言更难——作者把它当作经验问题。在他们的MNIST实验中,智能体每轮向一个固定的稀疏像素分类器(充当裁判)揭示一个像素,其中一方被预先指定为诚实者、另一方为说谎者。揭示6个像素时,裁判准确率从随机像素下的59.4%提高到88.9%,后者是由诚实者与必须预先承诺其主张的说谎者选择像素时的结果(对哪一方先行取平均);揭示4个像素时从48.2%提高到85.2%。辩论博弈与MNIST实验 这些是作者在以训练好的分类器为裁判的图像任务上报告的结果,不能作为关于人类裁判或语言辩论的证据。

石头剪刀布中的固定、适应与自博弈对手

程序实现了使用均匀先验计数的虚拟对局,并让它对抗三类脚本化对手:一个有偏随机玩家(石头0.5、布0.3、剪刀0.2);一个模拟虚拟对局规则、总出克制其预测的反制智能体;以及另一个虚拟对局智能体(自博弈,先验分别为(1,0,0)和(0,1,0),使两者起点不同)。作为不适应的基线,均匀随机玩家面对同样的对手。每场比赛5,000轮,用三个种子;自博弈在至多100,000轮的若干检查点报告经验频率、可利用度和平均收益。不使用任何学习库、网络或模型。

"""Original repeated rock-paper-scissors study with scripted competitive agents.
Fixed seeds; no learning library, network or LLM is used."""
import random

ACTIONS = ('R', 'P', 'S')
PAYOFF = [[0, -1, 1], [1, 0, -1], [-1, 1, 0]]  # row player's payoff; column player gets the negative


def expected(row_mix, col_mix):
    return sum(row_mix[a] * col_mix[b] * PAYOFF[a][b] for a in range(3) for b in range(3))


def best_response(col_mix):
    values = [sum(col_mix[b] * PAYOFF[a][b] for b in range(3)) for a in range(3)]
    return values.index(max(values)), max(values)


def exploitability(row_mix, col_mix):
    """Sum of both players' best-response gains; zero exactly at an equilibrium of this game."""
    row_gain = best_response(col_mix)[1]
    col_gain = max(-sum(row_mix[a] * PAYOFF[a][b] for a in range(3)) for b in range(3))
    return row_gain + col_gain


class FictitiousPlay:
    """Best response to the empirical frequency of the opponent's past actions."""

    def __init__(self, prior=(1.0, 1.0, 1.0)):
        self.counts = list(prior)

    def act(self):
        total = sum(self.counts)
        return best_response([c / total for c in self.counts])[0]

    def observe(self, opponent_action):
        self.counts[opponent_action] += 1


def biased(rng, weights=(0.5, 0.3, 0.2)):
    return rng.choices(range(3), weights=weights)[0]


def play(rounds, seed):
    rng = random.Random(seed)
    results = {}
    learner, total = FictitiousPlay(), 0
    for _ in range(rounds):
        a, b = learner.act(), biased(rng)
        total += PAYOFF[a][b]
        learner.observe(b)
    results['fp_vs_biased'] = total / rounds
    total = sum(PAYOFF[rng.randrange(3)][biased(rng)] for _ in range(rounds))
    results['uniform_vs_biased'] = total / rounds
    # The counter-agent knows the fictitious-play rule, predicts its next action and beats it.
    learner, total = FictitiousPlay(), 0
    for _ in range(rounds):
        a = learner.act()
        b = (a + 1) % 3
        total += PAYOFF[a][b]
        learner.observe(b)
    results['fp_vs_counter'] = total / rounds
    total = 0
    for _ in range(rounds):
        a = rng.randrange(3)
        guess = FictitiousPlay().act()  # the counter cannot predict an unrevealed random draw
        total += PAYOFF[a][(guess + 1) % 3]
    results['uniform_vs_counter'] = total / rounds
    return results


def self_play(checkpoints):
    one, two = FictitiousPlay((1.0, 0.0, 0.0)), FictitiousPlay((0.0, 1.0, 0.0))
    freq_one, freq_two, total, rows = [0, 0, 0], [0, 0, 0], 0, []
    for t in range(1, max(checkpoints) + 1):
        a, b = one.act(), two.act()
        total += PAYOFF[a][b]
        one.observe(b)
        two.observe(a)
        freq_one[a] += 1
        freq_two[b] += 1
        if t in checkpoints:
            x, y = [c / t for c in freq_one], [c / t for c in freq_two]
            rows.append((t, [round(v, 4) for v in x], round(exploitability(x, y), 4), round(total / t, 4)))
    return rows


if __name__ == '__main__':
    target = (0.5, 0.3, 0.2)
    action, value = best_response(target)
    print('best response to biased opponent', ACTIONS[action], 'expected payoff', round(value, 4))
    print('uniform against anyone', round(expected((1 / 3,) * 3, target), 4))
    for name, mix in (('pure Paper', (0, 1, 0)), ('biased mix', target), ('uniform', (1 / 3,) * 3)):
        print('worst-case payoff of', name, round(min(expected(mix, [int(b == j) for j in range(3)]) for b in range(3)), 4))
    for seed in (0, 1, 2):
        print('seed', seed, {k: round(v, 4) for k, v in play(5000, seed).items()})
    for row in self_play({10, 100, 1000, 10000, 100000}):
        print('self-play t=%d freq1=%s exploitability=%s mean_payoff_1=%s' % row)
记录的输出
best response to biased opponent P expected payoff 0.3
uniform against anyone 0.0
worst-case payoff of pure Paper -1
worst-case payoff of biased mix -0.3
worst-case payoff of uniform 0.0
seed 0 {'fp_vs_biased': 0.2898, 'uniform_vs_biased': -0.0078, 'fp_vs_counter': -1.0, 'uniform_vs_counter': -0.0024}
seed 1 {'fp_vs_biased': 0.2884, 'uniform_vs_biased': 0.0134, 'fp_vs_counter': -1.0, 'uniform_vs_counter': -0.0066}
seed 2 {'fp_vs_biased': 0.2998, 'uniform_vs_biased': -0.0104, 'fp_vs_counter': -1.0, 'uniform_vs_counter': 0.0008}
self-play t=10 freq1=[0.3, 0.1, 0.6] exploitability=0.7 mean_payoff_1=-0.2
self-play t=100 freq1=[0.38, 0.27, 0.35] exploitability=0.23 mean_payoff_1=0.02
self-play t=1000 freq1=[0.351, 0.338, 0.311] exploitability=0.065 mean_payoff_1=-0.008
self-play t=10000 freq1=[0.331, 0.3301, 0.3389] exploitability=0.0201 mean_payoff_1=0.0012
self-play t=100000 freq1=[0.3312, 0.3349, 0.3338] exploitability=0.0064 mean_payoff_1=-0.0004

对有偏玩家,虚拟对局在三个种子下每轮分别得0.2898、0.2884和0.2998,接近最佳响应值0.3;均匀玩家得−0.0078、0.0134和−0.0104,与其0的保证一致。对反制智能体,虚拟对局每轮恰好得−1.0,而均匀玩家的结果(−0.0024、−0.0066、0.0008)保持在0附近,因为反制者无法预测尚未揭示的随机抽取。最坏情况那几行以静态方式说明同一点:固定出布每轮可能输1,有偏混合本身可能输0.3(输给布),均匀混合在期望上不输。

自博弈中,玩家1的经验频率从10轮后的(0.3, 0.1, 0.6)变为100,000轮后的(0.3312, 0.3349, 0.3338)。经验策略对的可利用度从0.7降到0.23、0.065、0.0201和0.0064——在这次运行中轮数每增加十倍大约下降为三分之一——平均收益在0附近徘徊。这是零和收敛结论的缩影。它对逐轮的出招序列什么也没说,那个序列仍在循环;在任何单独一步,反制智能体仍能利用任一玩家。

每轮从计数计算最佳响应的代价为O(|A|²),所以T轮为O(T|A|²);在检查点计算可利用度再需O(|A|²)。

赢下一场比赛不等于强大

石头剪刀布只有三个行动、收益矩阵已知,对手的出招完全可观测。真实的竞争情形——市场、安全、含隐藏信息的博弈——行动空间巨大、收益未知、对手不断变化。此时精确计算可利用度不可行,评估只能退而求其次,例如对一个固定对手池的表现,而这可能掩盖新对手会发现的弱点。

虚拟对局的收敛结论是有限的。书中的例子表明,在某些一般和博弈中,例如Shapley修改过的石头剪刀布,经验频率永不收敛;即使收敛,实际收益也可能达不到均衡收益。不收敛与错配 实验中的反制智能体也是理想化的:它精确知道学习者的规则和先验。真实的对手必须推断这些,需要时间和数据。

设计出来的竞争有其自身风险。辩论所期望的保证取决于核心论断对真实裁判是否成立、揭示的证据是否无法伪造,以及训练能否找到接近均衡的策略。作者称核心论断是一个经验问题,指出只有当揭示的上下文不可能是谎言时辩论才有效,并把通过自博弈找到均衡表述为一种期望而非已有结果。辩论的开放问题 如果裁判可以被愚弄,竞争性的训练信号也可能奖励说服力而不是真实性。

练习

  1. 为什么一个确定性的适应型智能体总能被知道其规则的对手击败,即使它学得很快?

    答案:它的下一个行动是公开历史和已知先验的函数,所以对手可以在出手前算出这个行动,并选择克制它的回应。学习速度无济于事;只有私有的随机性,或对手无法重建的规则,才能消除这一弱点。

  2. 对手出石头0.2、布0.5、剪刀0.3。计算每个纯回应的期望收益,并指出最佳响应。

    答案:按矩阵各行:石头得0.2×0−0.5+0.3=−0.2;布得0.2−0+(−0.3)=−0.1;剪刀得−0.2+0.5+0=0.3。剪刀是最佳响应,期望收益0.3。

  3. 自博弈中,两个虚拟对局智能体的经验频率都趋近(1/3, 1/3, 1/3)。这是否意味着每个智能体在每一轮都在使用不可被利用的策略?

    答案:不是。频率描述的是长期平均,而每一轮的出招仍是对计数的确定性最佳响应。模拟该规则的对手仍能每轮获胜。在书中的反协调例子里,频率收敛到混合均衡,实际收益却始终为0,这是平均值掩盖实际序列的又一例。

  4. 你要在部署前评估一个新的交易智能体。开发者报告它击败了训练时对抗的三个智能体。你还会要求哪些评估?

    答案:要求它在未参与训练的对手面前的结果,包括专门为利用它而构造的对抗性对手;对最坏情况损失的估计,而不仅是平均胜率;对手在运行中会适应的测试;以及它的行为泄露了哪些信息的分析。击败固定对手池只说明它能利用这个池,不能说明它对新对手是安全的。

阅读来源

Shoham与Leyton-Brown的第7章简明地讲述了多智能体学习;7.1节解释了为何博弈中学习的目标本身就有争议,7.2节用带算例的表格和收敛定理介绍虚拟对局。Multiagent Systems,第7章 Irving、Christiano与Amodei的论文(arXiv v2,2018年10月)是一份附带小实验的提案;最值得读的是辩论博弈的结构、它的核心论断,以及它把该论断当作经验问题的态度。本文未阅读其后讨论乐观理由与担忧的章节。AI safety via debate

开放问题包括:如何针对开放的对手群体评估智能体,实践中如何在利用对手与稳健性之间权衡,以及有意设计的竞争——辩论、对抗训练、红队测试——何时能让系统更真实,而不只是更有说服力。

先判断,再看解释

为什么知道规则的反制对手能让虚拟对局每轮都输?

选择一个答案

学习目标

  • 在零和博弈中计算最佳响应与可利用度,区分利用特定对手与对所有对手安全。
  • 解释虚拟对局的经验频率收敛与逐轮可被利用之间的差别,并评价辩论等有意设计的竞争。

先修与延伸

查看知识关联图 →

参考文献

  1. Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations — scoped free PDF, revision 1.1
    Yoav Shoham; Kevin Leyton-Brown · 2009
  2. AI safety via debate — scoped arXiv v2
    Geoffrey Irving; Paul Christiano; Dario Amodei · 2018

版本1 · 编写状态: 已完成记录中的技术复核

查看技术检查记录(AI)

Claude · 2026-12-02 · Independent AI check (Claude subagent, not the author; not a human or expert review). Ran example.py with python3 (0.3 s) and diffed it against example.stdout.txt (identical); confirmed byte-identical code blocks and identical display equations. Re-derived the best response 0.3 to (0.5, 0.3, 0.2), the worst-case payoffs −1, −0.3 and 0, the exploitability formula against the code, the self-play decay ratios, and exercise 2 (−0.2, −0.1, 0.3). Re-read the sources myself via pdftotext: Shoham–Leyton-Brown pp. 202–204 and 206–210, and Irving–Christiano–Amodei arXiv v2 pp. 1, 3, 7–8 including Table 2. Compared zh and en section by section and checked data.json IDs. Did not read the debate paper's complexity proofs, human experiments or Sections 4–5, and did not render the MDX.

  • 代码输出一致,最佳响应、最坏情况收益、可利用度与练习答案均复核无误。
  • 虚拟对局来源、先验敏感、收敛定理、反协调与Shapley反例均与教材一致;未使用表7.3。
  • 辩论MNIST数字与摘要及表2一致(预先承诺、对先手取平均),并明确作为作者报告的结果呈现。
  • 中英文逐节对应。

核对的来源位置:

  • Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations — scoped free PDF, revision 1.1 · Free PDF rev. 1.1 via pdftotext (533 PDF pages): contents; Introduction pp. xiii–xvi (e-commerce agent example; loose definition 'diverging information or diverging interests, or both'; chapter overview and blocks); ch.1 p.1 (cooperative distributed problem solving, central-designer remark, sensor networks); §2.3.1 pp.28–30 (contract nets as framework; marginal-cost bids; existence of optimal contract sequence; money-losing single-task contracts; cluster/swap/multiagent contracts; anytime; bidding/clearing/information rules; no claim for adversarial settings); §7.1.3 pp.202–204 (Chicken teaching example, descriptive vs prescriptive, self-play, no procedure optimal vs all opponents); §7.2 pp.206–210 (fictitious play rule, prior sensitivity, Matching Pennies table, Thms 7.2.2–7.2.5, anti-coordination miscorrelation, Shapley game non-convergence). NOT read: other chapters, ABT details, proofs. Note: another 015k writer registered this same PDF as mas-ch3-normal-form-scoped-015k for chapter 3; scopes differ. Checker re-read via pdftotext on 2026-12-02: pp. 202–204 (Chicken: always daring is optimal against a best-responding learner; self-play; no learning procedure optimal against all opponents; rules in equilibrium with each other) and pp. 206–210 (fictitious play originally an iterative method for zero-sum equilibria; sensitivity to priors; priors cannot be all zero; Thm 7.2.4 converged empirical distribution is Nash; anti-coordination payoff 0 from miscorrelation; Shapley's almost-RPS 'not constant sum', never converges; Thm 7.2.5 zero-sum sufficient for convergence). Table 7.3 values are not used in the article.
  • AI safety via debate — scoped arXiv v2 · arXiv v2 PDF via pdftotext: p.1 (abstract incl. 59.4%→88.9% given 6 pixels and 48.2%→85.2% given 4; v2 date 22 Oct 2018; introduction start), p.3 (Section 2 debate game steps 1–5, zero sum, central claim 'harder to lie than to refute a lie', hoped-for Nash equilibrium claims, self-play), p.7 (generalizations list incl. revealed context cannot be a lie; Sec. 3 empirical question; prespecified honest vs liar), p.8 (Fig. 2 and Table 2: 6-pixel judge 59.4% random, precommit mean 88.9%; 4-pixel 48.2%, precommit mean 85.2%; fixed sparse-pixel judge). NOT read: Sec. 2.2 complexity proofs, human experiments (Sec. 3.2+), Sec. 4–5 reasons for optimism/worry. Checker re-read pp. 1, 3, 7–8 via pdftotext on 2026-12-02: abstract numbers; central claim and 'whether this claim is true ... is empirical'; hoped-for Nash/self-play claims; 'debate only works if this revealed context cannot be a lie'; Table 2 (precommit honest win rate, mean over first player: 88.9% with 6 pixels vs 59.4% judge; 85.2% with 4 vs 48.2%). The article now presents these strictly as the authors' reported results and no longer claims the paper 'lists' failure modes, since Sections 4–5 were not read.

相关主题

没有匹配结果,试试英文名或缩写。

已显示 0 条结果

将整个查询放入双引号,可按短语匹配。