Many of the Discrete and Continuous samplers use internal classes to select the best algorithm. The outer class is then a simple wrapper for the inner class implementation. All samplers have a very simple public API with a sample method and the ability to create a new instance (SharedStateSampler<R> interface):
This can be encapsulated in a new pair of interfaces:
All distribution samplers should implement one of these new interfaces. This simplifies the implementation of the SharedStateSampler<R> interface and allows to move to a factory constructor code model. Each sampler would have a factory method to create a sampler. The factory method is free to choose the optimal implementation.
All current released classes must maintain their public constructors. All unreleased classes should remove public constructors and have factory methods to create a sampler. The suggested factory method is of. E.g.
In the case of classes with existing factory methods these can be moved to inner classes allowing:
Overall the proposal is to:
- Create SharedStateDiscreteSampler and SharedStateContinuousSampler
- Simplify the implementation of SharedStateSampler<R> for Discrete and Continuous samplers
- Move to factory constructors for unreleased samplers
- Add factory constructors to existing samplers to return optimised
Note: Removal of existing public constructors cannot be done until the next major release. Addition of factory constructors for these classes will allow optimal samplers to be constructed.
TBD - Documentation/Deprecated of public constructors
A note should be added to the public constructor when the factory method will create a more optimal sampler, for example in the case of the PoissonSampler which wraps a specialised Small/LargeMeanPoissonSampler.
An alternative would be the same message within a deprecated tag.