@@ -205,8 +205,8 @@ flipR r = do
205
205
-- Finds the probability that a machine, run on a given input, outputs a given bit.
206
206
-- Basically does binary refinement using the oracle.
207
207
-- Generates a series of nested intervals.
208
- getProb :: POM m => [ Bit ] -> Machine -> Bit -> Real m
209
- getProb bits m bit = if bit == One then prob1 else oneMinus prob1 where
208
+ getProb :: POM m => Bit -> [ Bit ] -> Machine -> Real m
209
+ getProb bit bits m = if bit == One then prob1 else oneMinus prob1 where
210
210
prob1 = makeStream restrictInterval (pure (1 , 0 ))
211
211
restrictInterval pbounds = do
212
212
(hi, lo) <- pbounds
@@ -216,7 +216,7 @@ getProb bits m bit = if bit == One then prob1 else oneMinus prob1 where
216
216
217
217
-- Finds the probability that a machine would have output a given bit sequence.
218
218
getStringProb :: POM m => [Bit ] -> Machine -> Real m
219
- getStringProb bits m = realProduct [getProb prev m bit | (prev, bit) <- events bits]
219
+ getStringProb bits m = realProduct [getProb bit prev m | (prev, bit) <- events bits]
220
220
221
221
-- Given a measure of how likely each machine is to accept x (in some abstract
222
222
-- fashion) and x, this function generates the generic probability (over all
@@ -255,8 +255,7 @@ sampleMachine bias = do
255
255
-- predicts the behavior of each machine in proportion to its posterior
256
256
-- probability given the bits seen so far.
257
257
solomonoffInduction :: POM m => [Bit ] -> m Bit
258
- solomonoffInduction bs = pick >>= \ m -> flipR (getProb bs m One ) where
259
- pick = sampleMachine $ getStringProb bs
258
+ solomonoffInduction bs = flipR . getProb One bs =<< sampleMachine (getStringProb bs)
260
259
261
260
-- Actions and Observations are bitstrings.
262
261
-- You must use a prefix-free encoding.
@@ -329,7 +328,7 @@ events xs = [(take n xs, xs !! n) | n <- [0 .. pred $ length xs]]
329
328
-- Given a machine and a list of OA pairs, compute the probability that that
330
329
-- machine would have produced those observations (given those actions).
331
330
getHistProb :: POM m => History -> Machine -> Real m
332
- getHistProb rhist m = realProduct [getProb bs m b | (bs, b) <- bitEvents] where
331
+ getHistProb rhist m = realProduct [getProb b bs m | (bs, b) <- bitEvents] where
333
332
obsEvents = second fst <$> events (reverse rhist)
334
333
bitEvents = concatMap (uncurry o2b) obsEvents
335
334
o2b h o = first (histStr h ++ ) <$> events o
@@ -347,14 +346,14 @@ envInductor :: POM m => EnvHistory -> m (Machine, Bit)
347
346
envInductor (EnvHistory bits mm hist) = getM >>= \ m -> (m,) <$> predict m where
348
347
-- Note that if we need to sample a new machine, bits must be [].
349
348
getM = maybe (sampleMachine $ getHistProb hist) return mm
350
- predict m = flipR ( getProb (histStr hist ++ bits) m One )
349
+ predict = flipR . getProb One (histStr hist ++ bits)
351
350
352
351
-- Runs the interaction of an agent with an environment, starting with an
353
352
-- environment (which may be partway through outputting an observation).
354
353
interactE :: POM m => Agent m -> Environment m -> EnvHistory -> m (Stream OA )
355
354
interactE agent env hist = if isObservation $ partialO hist then a else e where
356
355
a = interactA agent env newAhist
357
- e = env hist >>= ( interactE agent env . newEhist)
356
+ e = env hist >>= interactE agent env . newEhist
358
357
newAhist = AgentHistory [] (partialO hist) (prevHistE hist)
359
358
newEhist (m, bit) = hist{partialO = bit : partialO hist, currentM = Just m}
360
359
@@ -363,7 +362,7 @@ interactE agent env hist = if isObservation $ partialO hist then a else e where
363
362
interactA :: POM m => Agent m -> Environment m -> AgentHistory -> m (Stream OA )
364
363
interactA agent env hist = if isAction $ partialA hist then e else a where
365
364
e = ((currentO hist, partialA hist):! ) <$> interactE agent env newEhist
366
- a = agent hist >>= ( interactA agent env . newAhist)
365
+ a = agent hist >>= interactA agent env . newAhist
367
366
newEhist = EnvHistory [] Nothing $ (currentO hist, partialA hist) : prevHistA hist
368
367
newAhist bit = hist{partialA = bit : partialA hist}
369
368
0 commit comments