-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Milestone
Description
This issue documents the work plan to allow for sinn to be used for SMC (Sequential Monte Carlo) applications. Altough the project requiring SMC is currently on ice (and thus also the work on these features), we keep this list for future reference. All points below address at least one of the following:
- Build more efficient computational graphs. For SMC on complex models this is likely not just “nice to have”, but necessary.
- Standardize the constructs to reduce time spent writing interfacing code.
- Simplify the constructs to reduce time spent relearning how to instantiate them.
- Standardize conventions before I incur more technical debt.
DynArray updates
-
sampling_shape: Number of samples. Might as well allow for multiple sampling dimensions (same effort). Can be used for multiple batches, particle filter. Use empty tuple if there are no sampling dimensions.
Make History inherit from DynArray
-
Historyshould no longer define the following functionality, but inherit them fromDynArray:-
update_function()->compute() - Indexing functions (and have them use to
DiscreteAxis) - locking function and attributes (incl.
observed) - access (
[]) and evaluation (()) -
compute()(renamed from_compute_up_to())
This method is subclass-specific and takes care of caching.
Different data structures will use cache differently. For example, aSerieshistory stores the result of every calculation, will aLagSeriesstores only the last few values.
-
History updates
- Implement new types
These types should fix, or at least greatly alleviate my memory issues. They should also translate into less a convoluted Theano, which is good for a) execution & compilation time and b) putting code on GPU.-
LagFreeSeries: Stores only the most recently computed time.- Test: Caching works with single times, slices and arrays of times.
-
LagSeries: Stores only the lastntime steps.
ReturnsLagFreeSeriesif lag is 0.- Test: Evaluating in past within lag does not change cache.
- Test: Evaluating in past beyond lag returns
Sinn.Expired(for now – easier to implement than recomputing and updating cache) - Test: Evaluating at future
$t_i$ moves cache ahead so that values from$t_i - \text{lag}$ to$t_i$ are available.
-
VirtualHistory: Does not store anything- Basically just a wrapper around a function
- Can be safely shared between samples/threads since nothing is cached.
-
ProbabilisticHistoryMixin:- Identifies history as probabilistic (i.e. PyMC3 distribution)
- Sets history type to
None- Disables cast to history's dtype in
update. Replaces with an optional check whenconfig.debug = True(Set this at instantiation – don't check value at every call toupdate) - stores original dtype as
sampling_dtype
- Disables cast to history's dtype in
- Adds
make_sampling_historymethod:- Takes a
sample_sizeorparticlesargument and adds a sampling dimension to the new history. - Wraps the
computemethod with a function callingsampleon the result. - Sets history type to
sampling_dtype
- Takes a
- Add
observedkeyword argument to initializer- Sets the data
- Locks the data
- Use the
NotLongerComputed&Expiredreturn types appropriately.- Access (
[]) may return- cached value
-
Sinn.NotComputedif value has not been computed -
Sinn.NoLongerComputed(Sinn.NotComputed)if it must be recomputed -
Sinn.Expiredif it was computed and cannot be recomputed (for example, if it depends on a RNG.)
- Evaluation (
())- Returns: value or
sinn.Expired. - Implemented as
def __call__(self, t): r = self[t] if issubclass(r, NotComputed): r = self.compute(t) return r
- Returns: value or
- Access (
-
Model updates
- Allow any history in a model to be passed as a parameter, or created with a default type
This will be used to create the “particle” and “probability” models we will need.- Create HistorySpec to define at class level the history names, shapes, and allowed/default types.
- Default created histories use model's time axis.
- Add
make_sampling_modelwhich creates a new model where some probabilistic histories are replaced by samplers.
Args:sampled_histories: histories it's conditioned on: these probabilistic histories are replaced by samplers
Other probabilistic histories are left probabilistic
Passing a non-probabilistic history has no effect
Throw error if a given history is locked
Special valueallmakes all prob. histories into samplersconditioned_on: synonym forsampled_historiessample_sizeorparticles
- Locked / observed histories are shared between models
- VirtualHistory's are shared between models
- Other histories are recreated
Reactions are currently unavailable