<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ 博弈论 - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ freeCodeCamp 是一个免费学习编程的开发者社区，涵盖 Python、HTML、CSS、React、Vue、BootStrap、JSON 教程等，还有活跃的技术论坛和丰富的社区活动，在你学习编程和找工作时为你提供建议和帮助。 ]]>
        </description>
        <link>https://www.freecodecamp.org/chinese/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ 博弈论 - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/chinese/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 30 May 2026 13:56:40 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/chinese/news/tag/game-theory/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ 演化博弈论简介 ]]>
                </title>
                <description>
                    <![CDATA[ 长期以来，合作社会行为的演化一直吸引着演化生物学家。 数学领域里的博弈论有助于阐明它是如何出现的。 博弈论是“之于理性决策者之间战略互动的数学模型的研究”（来自于维基百科 [https://en.wikipedia.org/wiki/Game_theory]）。 博弈论适用于各种各样的“博弈”，比如说经济学、政治学、国际象棋和井字游戏。在每种博弈下，都会有一些规则，一些“参与者”或“代理者”，以及一套可供他们使用的策略。 每个玩家都有一个叫作“效用”的概念——一种“货币”，并且他们会试图通过各种策略来实现“货币”的最大化。 在演化中，这种货币是适应度 [https://www.nature.com/scitable/blog/accumulating-glitches/the_meaning_of_fitness/] 。 适应度是个体的基因能在后代中出现的机会。也就是说，能使个体更可能存活到成年的基因和性状更容易被遗传给下一代。所以说，携带了这些基因和性状的个体会有更高的适应度。 演化博弈论采用了博弈论里的概念，并且将它们用于了演化背景中。 一个演化博弈论的模型可以让你了 ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/introduction-to-evolutionary-game-theory/</link>
                <guid isPermaLink="false">641d2114e32a7606487d55ab</guid>
                
                    <category>
                        <![CDATA[ 博弈论 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ John Cheng ]]>
                </dc:creator>
                <pubDate>Fri, 24 Mar 2023 04:07:08 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2023/03/605de4899618b008528a7b69.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>原文：</strong> <a href="https://www.freecodecamp.org/news/introduction-to-evolutionary-game-theory/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">Introduction to Evolutionary Game Theory</a>
      </p><!--kg-card-begin: markdown--><p>长期以来，合作社会行为的演化一直吸引着演化生物学家。</p>
<p>数学领域里的博弈论有助于阐明它是如何出现的。 博弈论是“之于理性决策者之间战略互动的数学模型的研究”（来自于<a href="https://en.wikipedia.org/wiki/Game_theory">维基百科</a>）。</p>
<p>博弈论适用于各种各样的“博弈”，比如说经济学、政治学、国际象棋和井字游戏。在每种博弈下，都会有一些规则，一些“参与者”或“代理者”，以及一套可供他们使用的策略。</p>
<p>每个玩家都有一个叫作“效用”的概念——一种“货币”，并且他们会试图通过各种策略来实现“货币”的最大化。</p>
<p>在演化中，这种货币是<a href="https://www.nature.com/scitable/blog/accumulating-glitches/the_meaning_of_fitness/">适应度</a>。</p>
<p>适应度是个体的基因能在后代中出现的机会。也就是说，能使个体更可能存活到成年的基因和性状更容易被遗传给下一代。所以说，携带了这些基因和性状的个体会有更高的适应度。</p>
<p>演化博弈论采用了博弈论里的概念，并且将它们用于了演化背景中。</p>
<p>一个演化博弈论的模型可以让你了解哪些策略能够占上风，以及哪些策略可以共存。如果多种策略能共存的话，它们共存的频率是多少呢？</p>
<h2 id="">复制器动力学</h2>
<p>演化博弈论中的博弈能延续很多代。</p>
<p>每轮博弈会改变参与者的效用（也就是适应度）。参与者总体的适应度越高，他们生产的下一代越多。</p>
<p>这种设定被叫作“复制器动力学”。不难通过建模来模拟和探索各种不同的演化博弈论模型。</p>
<p>演化博弈论的经典模型是约翰·梅纳德·史密斯在20世纪70年代推广的“鹰-鸽”博弈。</p>
<p>在这个博弈中，有一群动物争夺有限的资源（例如食物）。一个个体赢得的资源越多，他的适应度就越高。</p>
<p>每个动物可以使用以下两种策略中的一种：</p>
<ul>
<li><strong>鹰派</strong>具有进攻性，他们会不惜一切代价来争抢某个资源。</li>
<li><strong>鸽派</strong>比较和平，他们会分享某个资源而不是争抢。</li>
</ul>
<p>它们都是一种动物，也就是说“鹰派”和“鸽派”只是描述它们的行为。</p>
<p>有三种可能存在的竞争：</p>
<p><strong>鹰派 vs 鹰派</strong></p>
<ul>
<li>如果两个鹰派竞争，它们会进行五五开的战斗来赢取资源。这是一个赢者通吃的情况——赢家得到所有的资源。受伤的输家付出代价，并减少相当一部分的适应度。</li>
</ul>
<p><strong>鹰派 vs 鸽派</strong></p>
<ul>
<li>如果一个鹰派遇到了一个鸽派，鸽派会很快退缩。鹰派会赢得所有的资源，而鸽派会空手而归。但是任何一方都不会付出代价。</li>
</ul>
<p><strong>鸽派 vs 鸽派</strong></p>
<ul>
<li>当两个鸽派相遇时，它们会同意平分资源。没人会受伤。</li>
</ul>
<p>我们可以通过数学来模拟这种博弈。通过建模，我们可以更好地了解这些策略是否能共存（或者说某种策略占上风）。</p>
<h3 id="">复制器动力学背后的数学</h3>
<p>设 <em>V</em> 为赢得比赛的价值，<em>C</em> 为比赛中受伤的代价。</p>
<p>将鹰派在种群中的频率表示为 <em>p</em>，鸽派的频率则为 <em>1-p</em>。</p>
<p>现在，定义两个函数F（H）和F（D），这两个函数分别定义了鹰派策略和鸽派策略的期望适合度。</p>
<p>鹰派策略意味着参加一场频率为 <em>p</em> 的鹰派对鹰派竞赛。这样做的期望效用被理解为平均结果。一半的时间某个鹰派赢得 <em>V</em>，一半的时间它损失 <em>C</em>。</p>
<p>在剩下的比赛中，这个鹰派将对阵鸽派。这保证了它能轻松赢得 <em>V</em>。</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8b5ac2e8-fdfb-4ffc-8abe-15d0d014f580_544x112.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F8b5ac2e8-fdfb-4ffc-8abe-15d0d014f580_544x112" width="544" height="112" loading="lazy"></p>
<p>用鸽派策略对阵鹰派毫无益处。但是一只鸽派会以 <em>1-p</em> 的频率遇到另一只鸽子。在这种情况下，它的预期效用是分到的资源，价值为 <em>V/2</em>。</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F6303e0b2-d6ab-434d-b7ec-cad18a82d154_508x110.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F6303e0b2-d6ab-434d-b7ec-cad18a82d154_508x110" width="508" height="110" loading="lazy"></p>
<p>现在，设 <em>F（H）</em> 等于 <em>F（D）</em> ，并求解 <em>p</em>。</p>
<p>解出的频率_p_会使得鹰派策略和鸽派策略拥有相同适应度。</p>
<p>在这种频率下，任何一种策略都没有优势，因此这是两种策略可以共存的平衡。</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F77be89c1-0286-4673-867f-1c8e1a038cb7_516x104.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F77be89c1-0286-4673-867f-1c8e1a038cb7_516x104" width="516" height="104" loading="lazy"></p>
<p>通过代数运算，我们能得到以下结果：</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fca77237e-29a4-4826-af4a-2fbb390d3572_404x108.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fca77237e-29a4-4826-af4a-2fbb390d3572_404x108" width="404" height="108" loading="lazy"></p>
<p>这个结果揭示了在平衡中，鹰派和鸽派的比例。</p>
<p>通过一些代数排列，我们能得到在平衡中 <em>p</em> 的值：</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb812b56c-8387-4a47-902e-61aaa87cf317_342x98.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb812b56c-8387-4a47-902e-61aaa87cf317_342x98" width="342" height="98" loading="lazy"></p>
<p>通过这个表达式的性质，可以发现两件事：</p>
<ul>
<li>
<p>每当输掉比赛的成本 <em>C</em> 小于或等于获胜的价值 <em>V</em> 时，鹰派策略就会占据主导地位。这两种策略无法共存。</p>
</li>
<li>
<p>如果成本 <em>C</em> 大于价值 <em>V</em>，则策略将会在平衡里共存。</p>
</li>
</ul>
<p>代入 <em>V</em>=4和 <em>C</em>=6，我们发现当2/3的种群使用鹰策略时，出现了平衡。</p>
<p>你可以通过在 Python 里模拟模型来测试这一点。</p>
<h3 id="">代码</h3>
<p>在叫作 bird.py 的文件里：</p>
<pre><code class="language-Python">import random

class Bird:
    def __init__(self, strategy):
        """
        Each bird has a strategy type (hawk or dove)
        And a small starting fitness
        """
        self.strategy = strategy
        self.fitness = 10

    def contest(self, opponent, v, c):
       """
       Simulate the outcomes depending on the strategies
       """
        
        # both hawks --&gt; 50:50 battle

        if self.strategy == opponent.strategy == "hawk":
            if random.randint(0, 1) == 1:
                self.fitness = self.fitness + v
                opponent.fitness = opponent.fitness - c
            else:
                self.fitness = self.fitness - c
                opponent.fitness = opponent.fitness + v

        # hawk meets dove

        elif self.strategy == "hawk" != opponent.strategy:
            self.fitness = self.fitness + v
            opponent.fitness = opponent.fitness
        elif self.strategy == "dove" != opponent.strategy:
            self.fitness = self.fitness
            opponent.fitness = opponent.fitness + v

        # both doves --&gt; share the resource

        else:
            self.fitness = self.fitness + v/2
            opponent.fitness = opponent.fitness + v/2

    def spawn(self):
        """
        Allow a small chance of mutation to flip strategy
        Otherwise, return offspring of the same type
        """

        mutation = random.randint(0, 1000) &gt; 999
        if mutation:
            if self.strategy == "dove":
                return Bird("hawk")
            else:
                return Bird("dove")
        else:
            return Bird(self.strategy)
</code></pre>
<p>下一个文件叫作 simulation.py：</p>
<ol>
<li>初始化鸽派的种群</li>
<li>定义一个时间步长函数来模拟随机竞赛</li>
<li>根据它们相对适应度，同比例生成下一代</li>
<li>打乱并重复一千次，然后将输出保存为图表</li>
</ol>
<pre><code class="language-Python">from bird import Bird
import random
import numpy as np
import pandas as pd
import matplotlib


def initialise():
    """
    Create a population of birds - all dove to begin
    """

    birds = []

    for _ in range(1000):
        birds.append(Bird("dove"))

    return (birds)


def timestep(birds, value, cost):
    """
    Pair up the birds, make them compete
    Then produce next generation, weighted by fitness
    """

    next_generation = []

    random.shuffle(birds)

    for _ in range(1000):

        # pair up random birds to contest
        a, b = random.sample(birds, 2)
        a.contest(b, value, cost)

    # generate next generation
    fitnesses = [bird.fitness for bird in birds]

    draw = random.choices(birds, k=1000, weights=fitnesses)
    next_generation = [bird.spawn() for bird in draw]

    return next_generation


def main():

    birds = initialise()

    rows = []

    V = 4 ; C = 6

    for _ in range(1000):
        
        # add the counts to a new row
        strategy = [bird.strategy for bird in birds]
        n_hawks = strategy.count("hawk")
        n_doves =  strategy.count("dove")
        row = {'n_hawks': n_hawks, 'n_doves': n_doves}
        rows.append(row)

        # run the timestep function
        birds = timestep(birds, V, C)


    # create dataframe and save output

    df = pd.DataFrame(rows)
    df.to_csv('simulation.csv')
    fig = df.plot(y=["n_hawks", "n_doves"]).get_figure()
    fig.savefig('simulation.pdf')

if __name__ == "__main__":
    main()
</code></pre>
<p>看，这是个 <em>V</em>=4，<em>C</em>=6 的例子：</p>
<p><img src="https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F44100a89-d377-435e-bf11-97b046db5f32_1438x1048.png" alt="https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F44100a89-d377-435e-bf11-97b046db5f32_1438x1048" width="1438" height="1048" loading="lazy"></p>
<p>这和之前的理论预测得一样。</p>
<h2 id="">结语</h2>
<p>复杂系统的演化是一个令人着迷的研究领域。在过去几十年的生物科学研究里，一个主要的领域是了解自然力量和竞争压力如何塑造个体层面的特征。这些特征产生了复杂的社会行为。</p>
<p>相对简单的数学模型准确预测动态系统结果的能力也是这些研究带给我们至关重要的一点。</p>
<p>在这种情况下，反馈循环的存在导致了两种策略能达到平衡。当种群中使用该策略个体的数量不同，这两种策略所赋予的优势也会有所不同。</p>
<p>换句话说，当更多个体是“鸽派”时，“鹰派”就有优势。然而，随着越来越多的个体是“鹰派”，“鸽派”的期望值也会有所增加。</p>
<p>最后，编程工具和软件让我们可以通过模拟来测试理论预测。</p>
<p>如果你觉得这篇文章很有趣，你可能也会觉得<a href="https://www.freecodecamp.org/news/how-to-model-an-epidemic-with-r/">《如何用 R 建模流行病》</a>值得一看。</p>
<p>你可以在 <a href="https://gleeson.substack.com/">gleeson.substack.com</a> 里关注我的更多文章。</p>
<!--kg-card-end: markdown--> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
