@@ -16,12 +16,19 @@ module OpenGames.Engine.Diagnostics
16
16
generateOutputStr ,
17
17
generateIsEq ,
18
18
showDiagnosticInfoL ,
19
+ nextState ,
20
+ nextContinuation ,
21
+ equilibriumMap ,
22
+ toEquilibrium
19
23
)
20
24
where
21
25
22
26
import OpenGames.Engine.OpticClass
23
27
import OpenGames.Engine.TLL
24
28
29
+ import qualified Control.Monad.Trans.State.Strict as ST hiding (state )
30
+ import qualified Control.Monad.Trans as ST (lift )
31
+
25
32
--------------------------------------------------------
26
33
-- Diagnosticinformation and processesing of information
27
34
-- for standard game-theoretic analysis
@@ -113,6 +120,24 @@ data Concat = Concat
113
120
instance Apply Concat String (String -> String ) where
114
121
apply _ x = \ y -> x ++ " \n NEWGAME: \n " ++ y
115
122
123
+ -- for apply output of equilibrium function
124
+ data Equilibrium = Equilibrium
125
+
126
+ instance Apply Equilibrium [DiagnosticInfoBayesian x y ] Bool where
127
+ apply _ x = equilibriumMap x
128
+
129
+ data And = And
130
+
131
+ instance Apply And Bool (Bool -> Bool ) where
132
+ apply _ x = \ y -> y && x
133
+
134
+ -- map diagnostics to equilibrium
135
+ toEquilibrium :: DiagnosticInfoBayesian x y -> Bool
136
+ toEquilibrium = equilibrium
137
+
138
+ equilibriumMap :: [DiagnosticInfoBayesian x y ] -> Bool
139
+ equilibriumMap = and . fmap toEquilibrium
140
+
116
141
---------------------
117
142
-- main functionality
118
143
@@ -148,3 +173,31 @@ generateIsEq ::
148
173
generateIsEq hlist =
149
174
putStrLn $
150
175
" ----Analytics begin----" ++ (foldrL Concat " " $ mapL @ _ @ _ @ (ConstMap String xs ) PrintIsEq hlist) ++ " ----Analytics end----\n "
176
+
177
+ -- give equilibrium value for further use
178
+ generateEquilibrium :: forall xs .
179
+ ( MapL Equilibrium xs (ConstMap Bool xs )
180
+ , FoldrL And Bool (ConstMap Bool xs )
181
+ ) => List xs -> Bool
182
+ generateEquilibrium hlist = foldrL And True $ mapL @ _ @ _ @ (ConstMap Bool xs ) Equilibrium hlist
183
+
184
+
185
+ ---------------------------------------
186
+ -- Helper functionality for play output
187
+
188
+ -- Transform the optic into the next state given some input
189
+ nextState ::
190
+ StochasticStatefulOptic s t a b ->
191
+ s ->
192
+ Stochastic a
193
+ nextState (StochasticStatefulOptic v _) x = do
194
+ (z, a) <- v x
195
+ pure a
196
+
197
+ nextContinuation
198
+ :: StochasticStatefulOptic s t a ()
199
+ -> s
200
+ -> ST. StateT Vector Stochastic t
201
+ nextContinuation (StochasticStatefulOptic v u) x = do
202
+ (z,a) <- ST. lift (v x)
203
+ u z ()
0 commit comments