我正在研究博弈论学习的图书馆。在这种情况下,N
代理聚集在一起并与环境交互。每个代理派生一个交互模型。一个代理的模型取决于它的N-1
对手。我编写了代码来确定1
代理和2
代理的模型,并试图对其进行概括。这是我拥有的部分代码:
data System w x a s h h' = System { signaling :: SignalingWXAS w x a s
, dynamic :: DynamicXAS x a s
, strategy :: MockupStrategy x a s h h' }
data JointState w x a s h h' = JointState { worldState :: w
, state :: x
, mockupState :: MockupState a s h h' }
systemToMockup :: ( Bounded w, Ix w, Bounded x, Ix x
, Bounded a, Ix a, Bounded s, Ix s
, Bounded (h a), Ix (h a), Bounded (h' s), Ix (h' s)
, History h, History h'
) => System w x a s h h' -> Mockup a s h h'
systemToMockup syst = mock
where
mock z = norm $ statDist >>=? condit z >>= computeStatesAndAction >>= sig >>=$ extractSignal
statDist = ergodicStationary $ transition syst
condit z = just z . mockupState
sig = uncurryN $ signaling syst
strat = strategy syst
computeStatesAndAction joint = do
let w = worldState joint
let x = state joint
a <- strat x (mockupState joint)
return (w, x, a)
extractSignal (_, s) = s
和
data System2 w x1 a1 s1 h1 h1' x2 a2 s2 h2 h2' = System2 { signaling :: SignalingWXAS2 w x1 a1 s1 x2 a2 s2
, dynamic1 :: DynamicXAS x1 a1 s1
, dynamic2 :: DynamicXAS x2 a2 s2
, strategy1 :: MockupStrategy x1 a1 s1 h1 h1'
, strategy2 :: MockupStrategy x2 a2 s2 h2 h2' }
data JointState2 w x1 a1 s1 h1 h1' x2 a2 s2 h2 h2' = JointState2 { worldState :: w
, state1 :: x1
, mockupState1 :: MockupState a1 s1 h1 h1'
, state2 :: x2
, mockupState2 :: MockupState a2 s2 h2 h2' }
systemToMockups2 syst = (mock1, mock2)
where
mock1 z1 = norm $ statDist >>=? condit1 z1 >>= computeStatesAndActions >>= sig >>=$ extractSignal1
mock2 z2 = norm $ statDist >>=? condit2 z2 >>= computeStatesAndActions >>= sig >>=$ extractSignal2
statDist = ergodicStationary $ transition2 syst
condit1 z1 = just z1 . mockupState1
condit2 z2 = just z2 . mockupState2
sig = uncurryN $ signaling syst
strat1 = strategy1 syst
strat2 = strategy2 syst
computeStatesAndActions joint = do
let w = worldState joint
let x1 = state1 joint
let x2 = state2 joint
a1 <- strat1 x1 (mockupState1 joint)
a2 <- strat2 x2 (mockupState2 joint)
return (w, x1, a1, x2, a2)
extractSignal1 (_, s, _) = s
extractSignal2 (_, _, s) = s
我追求一个systemToMockupN
可以容纳任何有限数量的代理的函数定义。
代理是异构的,因此不能直接使用列表。我不能使用元组,因为我事先不知道大小。我尝试使用curryN
,uncurryN
等,但没有设法对元组的每个元素进行一次操作。我尝试以类似于printf
没有成功的方式构建可变参数函数。
我知道我可以使用模板 haskell,但我想知道是否有更好的解决方案我忽略了。任何指向处理有限但任意数量的异构元素的代码的指针将不胜感激。