You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many monads defined in monad-bayes are known transformers. For example:
--| Collection of random variables sampler during the program's execution.dataTracea=Trace{--| Sequence of random variables sampler during the program's execution.variables:: [Double],
--output::a,
--| The probability of observing this particular sequence.density::LogDouble}
This is isomorphic to:
--| Collection of random variables sampler during the program's execution.dataTraceData=TraceData{--| Sequence of random variables sampler during the program's execution.variables:: [Double],
--| The probability of observing this particular sequence.density::LogDouble}deriving (Semigroup, Monoid)
newtypeTracea=Trace{getTrace::WriterTraceDataa}
The advantage is that one gets correct and efficient Functor, Monad,... instances that way, and saves code. (It's notoriously difficult to get a performant Writer, so it's a good idea to use existing code instead of reimplementing it.)
Similarly:
--| Tracing monad that records random choices made in the program.dataTracedma=Traced{--| Run the program with a modified trace.model::Weighted (FreeSamplerIdentity) a,
--| Record trace and output.traceDist::m (Tracea)
}
This is the same as promoting Trace to a transformer and taking the product:
newtypeTraceTma=TraceT{getTrace::WriterTTraceDatama}--| Tracing monad that records random choices made in the program.newtypeTracedma=Traced{getTraced::Product (Weighted (FreeSamplerIdentity)) (TraceTm) }
Again one gets all the instances for free now. The haddocks of the record fields can be moved to a custom constructor function:
traced::--| Run the program with a modified trace.Weighted (FreeSamplerIdentity) a->--| Record trace and output.m (Tracea) ->Tracedma
traced =...
The text was updated successfully, but these errors were encountered:
Many monads defined in monad-bayes are known transformers. For example:
This is isomorphic to:
The advantage is that one gets correct and efficient
Functor
,Monad
,... instances that way, and saves code. (It's notoriously difficult to get a performantWriter
, so it's a good idea to use existing code instead of reimplementing it.)Similarly:
This is the same as promoting
Trace
to a transformer and taking the product:Again one gets all the instances for free now. The haddocks of the record fields can be moved to a custom constructor function:
The text was updated successfully, but these errors were encountered: