Swifty MCMC and python iterop
- Dominant language
- Swift
- Stars
- 118
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
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](https://developer.apple.com/documentation/swift/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:
```swift
struct RandomWalkMetropolis: 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:
```swift
Array(sequence.dropFirst(num_burnin_steps).prefix(num_results))
```
_Originally posted by @marcrasi in https://github.com/borglab/SwiftFusion/pull/95/files_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading PR #95 and the current TransitionKernel and sampleChain API described in this issue. Compare the proposed Sequence and IteratorProtocol design with the stated TensorFlow Probability interoperability goal. Done means the project has a decided API direction and a clear implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend-api-design, machine-learning
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100