【读书笔记】Algorithms for Decision Making(14)

简介: 本部分将简单游戏扩展到具有多个状态的连续上下文。马尔可夫博弈可以看作是多个具有自己奖励函数的智能体的马尔可夫决策过程。

五、多智能体系统(3)

本部分将简单游戏扩展到具有多个状态的连续上下文。马尔可夫博弈可以看作是多个具有自己奖励函数的智能体的马尔可夫决策过程。


3. 状态不确定

3.1 Partially Observable Markov Games

POMG可以看作是MG到部分可观测性的扩展,也可以看作是POMDP到多个代理的扩展。

struct POMG
    γ # discount factor
    ℐ # agents
    𝒮 # state space
    𝒜 # joint action space
    𝒪 # joint observation space
    T # transition function
    O # joint observation function
    R # joint reward function
end

3.2 策略进化

3.2.1 基于树的条件规划的策略

function lookahead(𝒫::POMG, U, s, a)
    𝒮, 𝒪, T, O, R, γ = 𝒫.𝒮, joint(𝒫.𝒪), 𝒫.T, 𝒫.O, 𝒫.R, 𝒫.γ
    u′ = sum(T(s,a,s′)*sum(O(a,s′,o)*U(o,s′) for o in 𝒪) for s′ in 𝒮)
    return R(s,a) + γ*u′
end

function evaluate_plan(𝒫::POMG, π, s)
    a = Tuple(πi() for πi in π)
    U(o,s′) = evaluate_plan(𝒫, [πi(oi) for (πi, oi) in zip(π,o)], s′)
    return isempty(first(π).subplans) ? 𝒫.R(s,a) : lookahead(𝒫, U, s, a)
end

function utility(𝒫::POMG, b, π)
    u = [evaluate_plan(𝒫, π, s) for s in 𝒫.𝒮]
    return sum(bs * us for (bs, us) in zip(b, u))
end

3.2.2 基于图的控制器的策略

在这里插入图片描述

3.3 Nash 均衡

struct POMGNashEquilibrium
    b # initial belief
    d # depth of conditional plans
end

function create_conditional_plans(𝒫, d)
    ℐ, 𝒜, 𝒪 = 𝒫.ℐ, 𝒫.𝒜, 𝒫.𝒪
    Π = [[ConditionalPlan(ai) for ai in 𝒜[i]] for i in ℐ]
    for t in 1:d
        Π = expand_conditional_plans(𝒫, Π)
    end
    return Π
end

function expand_conditional_plans(𝒫, Π)
    ℐ, 𝒜, 𝒪 = 𝒫.ℐ, 𝒫.𝒜, 𝒫.𝒪
    return [[ConditionalPlan(ai, Dict(oi => πi for oi in 𝒪[i]))
    for πi in Π[i] for ai in 𝒜[i]] for i in ℐ]
end

function solve(M::POMGNashEquilibrium, 𝒫::POMG)
    ℐ, γ, b, d = 𝒫.ℐ, 𝒫.γ, M.b, M.d
    Π = create_conditional_plans(𝒫, d)
    U = Dict(π => utility(𝒫, b, π) for π in joint(Π))
    𝒢 = SimpleGame(γ, ℐ, Π, π -> U[π])
    π = solve(NashEquilibrium(), 𝒢)
    return Tuple(argmax(πi.p) for πi in π)
end

3.4 动态规划

struct POMGDynamicProgramming
    b # initial belief
    d # depth of conditional plans
end

function solve(M::POMGDynamicProgramming, 𝒫::POMG)
    ℐ, 𝒮, 𝒜, R, γ, b, d = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.R, 𝒫.γ, M.b, M.d
    Π = [[ConditionalPlan(ai) for ai in 𝒜[i]] for i in ℐ]
    for t in 1:d
        Π = expand_conditional_plans(𝒫, Π)
        prune_dominated!(Π, 𝒫)
    end
    𝒢 = SimpleGame(γ, ℐ, Π, π -> utility(𝒫, b, π))
    π = solve(NashEquilibrium(), 𝒢)
    return Tuple(argmax(πi.p) for πi in π)
end

function prune_dominated!(Π, 𝒫::POMG)
    done = false
    while !done
        done = true
        for i in shuffle(𝒫.ℐ)
            for πi in shuffle(Π[i])
                if length(Π[i]) > 1 && is_dominated(𝒫, Π, i, πi)
                    filter!(πi′ -> πi′ ≠ πi, Π[i])
                    done = false
                    break
                end
            end
        end
    end
end

function is_dominated(𝒫::POMG, Π, i, πi)
    ℐ, 𝒮 = 𝒫.ℐ, 𝒫.𝒮
    jointΠnoti = joint([Π[j] for j in ℐ if j ≠ i])
    π(πi′, πnoti) = [j==i ? πi′ : πnoti[j>i ? j-1 : j] for j in ℐ]
    Ui = Dict((πi′, πnoti, s) => evaluate_plan(𝒫, π(πi′, πnoti), s)[i]
        for πi′ in Π[i], πnoti in jointΠnoti, s in 𝒮)
    model = Model(Ipopt.Optimizer)
    @variable(model, δ)
    @variable(model, b[jointΠnoti, 𝒮] ≥ 0)        
    @objective(model, Max, δ)
    @constraint(model, [πi′=Π[i]],
        sum(b[πnoti, s] * (Ui[πi′, πnoti, s] - Ui[πi, πnoti, s])
        for πnoti in jointΠnoti for s in 𝒮) ≥ δ)
    @constraint(model, sum(b) == 1)
    optimize!(model)
    return value(δ) ≥ 0
end

4. Decentralized Partially Observable Markov Decision Processes

Dec-POMDP是所有智能体都共享相同目标的POMG。

struct DecPOMDP
    γ # discount factor
    ℐ # agents
    𝒮 # state space
    𝒜 # joint action space
    𝒪 # joint observation space
    T # transition function
    O # joint observation function
    R # reward function
end

4.1 Subclass

在这里插入图片描述

4.2 算法

4.2.1 动态规划

struct DecPOMDPDynamicProgramming
    b # initial belief
    d # depth of conditional plans
end

function solve(M::DecPOMDPDynamicProgramming, 𝒫::DecPOMDP)
    ℐ, 𝒮, 𝒜, 𝒪, T, O, R, γ = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.𝒪, 𝒫.T, 𝒫.O, 𝒫.R, 𝒫.γ
    R′(s, a) = [R(s, a) for i in ℐ]
    𝒫′ = POMG(γ, ℐ, 𝒮, 𝒜, 𝒪, T, O, R′)
    M′ = POMGDynamicProgramming(M.b, M.d)
    return solve(M′, 𝒫′)
end

4.2.2 迭代最佳响应

struct DecPOMDPIteratedBestResponse
    b # initial belief
    d # depth of conditional plans
    k_max # number of iterations
end

function solve(M::DecPOMDPIteratedBestResponse, 𝒫::DecPOMDP)
    ℐ, 𝒮, 𝒜, 𝒪, T, O, R, γ = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.𝒪, 𝒫.T, 𝒫.O, 𝒫.R, 𝒫.γ
    b, d, k_max = M.b, M.d, M.k_max
    R′(s, a) = [R(s, a) for i in ℐ]
    𝒫′ = POMG(γ, ℐ, 𝒮, 𝒜, 𝒪, T, O, R′)
    Π = create_conditional_plans(𝒫, d)
    π = [rand(Π[i]) for i in ℐ]
    for k in 1:k_max
        for i in shuffle(ℐ)
            π′(πi) = Tuple(j == i ? πi : π[j] for j in ℐ)
            Ui(πi) = utility(𝒫′, b, π′(πi))[i]
            π[i] = argmax(Ui, Π[i])
        end
    end
    return Tuple(π)
end

4.2.3 Heuristic Search

struct DecPOMDPHeuristicSearch
    b # initial belief
    d # depth of conditional plans
    π_max # number of policies
end

function solve(M::DecPOMDPHeuristicSearch, 𝒫::DecPOMDP)
    ℐ, 𝒮, 𝒜, 𝒪, T, O, R, γ = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.𝒪, 𝒫.T, 𝒫.O, 𝒫.R, 𝒫.γ
    b, d, π_max = M.b, M.d, M.π_max
    R′(s, a) = [R(s, a) for i in ℐ]
    𝒫′ = POMG(γ, ℐ, 𝒮, 𝒜, 𝒪, T, O, R′)
    Π = [[ConditionalPlan(ai) for ai in 𝒜[i]] for i in ℐ]
    for t in 1:d
        allΠ = expand_conditional_plans(𝒫, Π)
        Π = [[] for i in ℐ]
        for z in 1:π_max
            b′ = explore(M, 𝒫, t)
            π = argmax(π -> first(utility(𝒫′, b′, π)), joint(allΠ))
            for i in ℐ
                push!(Π[i], π[i])
                filter!(πi -> πi != π[i], allΠ[i])
            end
        end
    end
    return argmax(π -> first(utility(𝒫′, b, π)), joint(Π))
end

function explore(M::DecPOMDPHeuristicSearch, 𝒫::DecPOMDP, t)
    ℐ, 𝒮, 𝒜, 𝒪, T, O, R, γ = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.𝒪, 𝒫.T, 𝒫.O, 𝒫.R, 𝒫.γ
    b = copy(M.b)
    b′ = similar(b)
    s = rand(SetCategorical(𝒮, b))
    for τ in 1:t
        a = Tuple(rand(𝒜i) for 𝒜i in 𝒜)
        s′ = rand(SetCategorical(𝒮, [T(s,a,s′) for s′ in 𝒮]))
        o = rand(SetCategorical(joint(𝒪), [O(a,s′,o) for o in joint(𝒪)]))
        for (i′, s′) in enumerate(𝒮)
            po = O(a, s′, o)
            b′[i′] = po*sum(T(s,a,s′)*b[i] for (i,s) in enumerate(𝒮))
        end
        normalize!(b′, 1)
        b, s = b′, s′
    end
    return b′
end

4.2.4 非线性规划

struct DecPOMDPNonlinearProgramming
    b # initial belief
    ℓ # number of nodes for each agent
end

function tensorform(𝒫::DecPOMDP)
    ℐ, 𝒮, 𝒜, 𝒪, R, T, O = 𝒫.ℐ, 𝒫.𝒮, 𝒫.𝒜, 𝒫.𝒪, 𝒫.R, 𝒫.T, 𝒫.O
    ℐ′ = eachindex(ℐ)
    𝒮′ = eachindex(𝒮)
    𝒜′ = [eachindex(𝒜i) for 𝒜i in 𝒜]
    𝒪′ = [eachindex(𝒪i) for 𝒪i in 𝒪]
    R′ = [R(s,a) for s in 𝒮, a in joint(𝒜)]
    T′ = [T(s,a,s′) for s in 𝒮, a in joint(𝒜), s′ in 𝒮]
    O′ = [O(a,s′,o) for a in joint(𝒜), s′ in 𝒮, o in joint(𝒪)]
    return ℐ′, 𝒮′, 𝒜′, 𝒪′, R′, T′, O′
end

function solve(M::DecPOMDPNonlinearProgramming, 𝒫::DecPOMDP)
    𝒫, γ, b = 𝒫, 𝒫.γ, M.b
    ℐ, 𝒮, 𝒜, 𝒪, R, T, O = tensorform(𝒫)
    X = [collect(1:M.ℓ) for i in ℐ]
    jointX, joint𝒜, joint𝒪 = joint(X), joint(𝒜), joint(𝒪)
    x1 = jointX[1]
    model = Model(Ipopt.Optimizer)
    @variable(model, U[jointX,𝒮])
    @variable(model, ψ[i=ℐ,X[i],𝒜[i]] ≥ 0)
    @variable(model, η[i=ℐ,X[i],𝒜[i],𝒪[i],X[i]] ≥ 0)
    @objective(model, Max, b⋅U[x1,:])
    @NLconstraint(model, [x=jointX,s=𝒮],
        U[x,s] == (sum(prod(ψ[i,x[i],a[i]] for i in ℐ)
            *(R[s,y] + γ*sum(T[s,y,s′]*sum(O[y,s′,z]
                *sum(prod(η[i,x[i],a[i],o[i],x′[i]] for i in ℐ)
                    *U[x′,s′] for x′ in jointX)
                for (z, o) in enumerate(joint𝒪)) for s′ in 𝒮))
            for (y, a) in enumerate(joint𝒜))))
    @constraint(model, [i=ℐ,xi=X[i]], sum(ψ[i,xi,ai] for ai in 𝒜[i]) == 1)
    @constraint(model, [i=ℐ,xi=X[i],ai=𝒜[i],oi=𝒪[i]], 
        sum(η[i,xi,ai,oi,xi′] for xi′ in X[i]) == 1)
    optimize!(model)
    ψ′, η′ = value.(ψ), value.(η)
    return [ControllerPolicy(𝒫, X[i],
        Dict((xi,𝒫.𝒜[i][ai]) => ψ′[i,xi,ai] for xi in X[i], ai in 𝒜[i]),
        Dict((xi,𝒫.𝒜[i][ai],𝒫.𝒪[i][oi],xi′) => η′[i,xi,ai,oi,xi′] 
            for xi in X[i], ai in 𝒜[i], oi in 𝒪[i], xi′ in X[i])) for i in ℐ]
end

总结

最后一部分可以看作是一个全文总结的案例,也可以看作是全文内容的升华(从单智能体到多智能体)。

相关文章
|
Windows
Coze开源软件Windows客户端-coze_desk
Coze开源软件Windows客户端-coze_desk
3069 0
|
监控 自动驾驶 数据可视化
GPS 人员定位系统:原理拆解 + 优劣分析 + 避坑指南(一)
本文详解GPS人员定位系统的工作原理,从卫星测距、三角定位到数据解算,解析其实现过程,并介绍实时定位、电子点名、轨迹回溯、智能考勤等核心功能,为后续优劣分析与避坑指南做铺垫。
|
6月前
|
人工智能 弹性计算 Serverless
阿里云最新AI产品优惠权益解析:千问旗舰模型助力AI落地,轻量云2核2G38元起,9.9元快速部署OpenClaw
阿里云2026年最新AI普惠权益,覆盖个人开发者、学生及企业用户。核心权益包括:阿里云百炼Token Plan支持多模型灵活切换,首购低至4.5折,标准/高级/尊享三档套餐满足不同用量需求;视频生成模型HappyHorse限时8折,720P每秒仅0.72元起;高校学生完成认证可领300元无门槛抵扣金;轻量应用服务器2核2G低至38元/年,9.9元可快速部署OpenClaw;另有超30款AI产品及7000万tokens免费试用,AI组合购套餐78元起,以及百炼"先用后返"最高返200元活动,全方位降低AI应用落地门槛。
|
9月前
|
Ubuntu Linux API
2026年阿里云无影云电脑部署OpenClaw保姆级图文指南(Skills集成+API配置+避坑指南)
OpenClaw(原Clawdbot、Moltbot)是一款开源、可自托管的AI智能体工具,核心特性在于以自然语言驱动,支持插件化无限拓展与全场景自动化,既能实现基础的对话交互,也能完成代码调试、接口开发、定时任务执行等复杂操作,通过Skills生态可快速适配各类个性化需求,是个人提效与小型团队办公自动化的实用工具。与传统AI助手不同,OpenClaw支持阿里云无影云电脑部署与本地多系统部署两种模式,阿里云无影云电脑部署可实现多终端远程访问、全天候稳定运行,无需担心本地硬件性能限制;本地部署则能确保数据完全本地化,兼顾隐私安全与自定义灵活度,两种模式均适配Skills集成,满足不同用户的使用需
2088 1
|
8月前
|
人工智能 自然语言处理 前端开发
【SpringAIAlibaba新手村系列】(9)Text to Image 文本生成图像技术
本文介绍 Spring AI 中的文生图能力,围绕 ImageModel、ImagePrompt 与阿里云百炼图像模型展开,演示如何根据文字描述生成图片链接,并结合 Prompt 编写技巧与参数配置,帮助开发者提升生成效果与落地能力。
1330 8
|
9月前
|
Ubuntu Shell 应用服务中间件
Ubuntu 系统命令入门指南
本指南基于Ubuntu默认Bash Shell,系统讲解核心命令:文件目录操作、文本查看编辑、系统信息查询、权限管理、APT软件包管理、find/grep搜索技巧、进程端口管理及SSH/SCP远程操作,助你高效掌握Linux命令行。
1093 1
|
11月前
|
供应链 监控 安全
APT28全球钓鱼风暴突袭海事命脉:一封“船期变更”邮件,竟能瘫痪港口系统?
2025年底,APT28组织发动全球钓鱼攻击, targeting航运、港口与物流企业。通过伪造提单、海关通知等邮件,利用宏病毒与远程模板注入渗透内网,窃取敏感货运数据,甚至威胁关键基础设施安全。攻击横跨欧、美、亚,凸显海事网络安全短板。专家呼吁强化邮件防护、网络隔离与人员意识,构建纵深防御体系,警惕每一封“普通”邮件背后的国家级威胁。
565 4
|
人工智能 Kubernetes Cloud Native
MSE Nacos Controller:为 Kubernetes 生态构建配置管理与服务发现的桥梁
在企业云原生转型过程中,如何实现传统微服务与 Kubernetes 服务的配置统一管理、服务互通及协议转换成为关键挑战。MSE Nacos Controller 应运而生,作为连接 Kubernetes 与 Nacos 的桥梁,支持 ConfigMap 与 Nacos 配置双向同步、服务自动注册发现,并助力 Higress 等 MCP 网关实现 REST API 向 AI 可调用 MCP 服务的转换,全面提升系统治理能力与智能化水平。
1360 32
|
缓存 安全 PHP
攻防世界06-get_post
攻防世界06-get_post
|
人工智能 自然语言处理 数据可视化
阿里云 DeepSeek-R1 满血版解决方案评测
阿里云推出的“零门槛、即刻拥有 DeepSeek-R1 满血版”技术解决方案,为用户提供了便捷的云上调用和部署方式,极大地降低了使用门槛和成本。本文将对这一解决方案进行详细评测。
910 14