We should think/talk about MCMC algorithm API and tfp interop.
@marcrasi says:
As a direct translation of the Python API, the current API looks right to me. If you want to go this direction, then that sounds good to me!
The "Swifty" way can make some things a lot nicer so I'll describe a "Swifty" idea here to tempt you :)
The TransitionKernel looks like an infinite Sequence. So there's no need to define a protocol TransitionKernel -- you can conform things to Sequence instead.
For example, RandomWalkMetropolis would be something like:
struct RandomWalkMetropolis<State>: Sequence, IteratorProtocol {
var previousLogProb: Double
var currentState: State
let target_log_prob_fn: (State) -> Double
let new_state_fn : (State)->State
init(_ target_log_prob_fn: @escaping (State) -> Double, _ new_state_fn : @escaping (State)->State, _ initialState: State) {
...
}
mutating func next() -> State {
let result = currentState
// update `currentState` and `previousLogProb` according to metropolis rules
...
return result
}
}
This is nice because it allows us to use all the Sequence algorithms. For example, sampleChain becomes something like:
We should think/talk about MCMC algorithm API and tfp interop.
@marcrasi says:
As a direct translation of the Python API, the current API looks right to me. If you want to go this direction, then that sounds good to me!
The "Swifty" way can make some things a lot nicer so I'll describe a "Swifty" idea here to tempt you :)
The
TransitionKernel
looks like an infinite Sequence. So there's no need to define aprotocol TransitionKernel
-- you can conform things toSequence
instead.For example,
RandomWalkMetropolis
would be something like:This is nice because it allows us to use all the
Sequence
algorithms. For example,sampleChain
becomes something like:Originally posted by @marcrasi in https://github.com/borglab/SwiftFusion/pull/95/files