temporal_priors
¶Handle temporal MVN priors.
CustomPrior (*args, **kwargs) |
Specify a custom temporal MVN prior. | ||
GaussianKernelPrior ([delays, sigma]) |
Gaussian kernel temporal prior (a.k.a RBF kernel). | ||
HRFPrior ([delays, dt, duration]) |
Haemodynamic response function prior | ||
PriorFromPenalty (penalty[, delays, wishart]) |
Build a prior from a Tikhnov temporal penalty covariance. | ||
SmoothnessPrior ([delays, order, wishart]) |
Smoothness temporal MVN prior. | ||
SphericalPrior ([delays]) |
Equivalent to ridge regression. | ||
TemporalPrior (prior[, delays, hhparams]) |
Basic temporal MVN prior. | ||
get_delays_from_prior (raw_prior, delays) |
|
CustomPrior
¶tikreg.temporal_priors.
CustomPrior
(*args, **kwargs)¶Bases: tikreg.temporal_priors.TemporalPrior
Specify a custom temporal MVN prior.
__init__
(self, *args, **kwargs)¶Parameters: |
|
---|
Examples
>>> mat = np.random.randn(5, 5)
>>> cov = np.dot(mat.T, mat)
>>> custom_prior = CustomPrior(cov)
>>> prior_covar = custom_prior.get_prior()
>>> print(prior_covar.shape)
(5, 5)
>>> print(np.round(prior_covar, 2)) # doctest: +SKIP
[[ 4.98 0. -0.66 -2.72 -3.89]
[ 0. 12.28 -5.91 0.49 -4.39]
[-0.66 -5.91 9.88 -2.15 7.56]
[-2.72 0.49 -2.15 5.49 3.13]
[-3.89 -4.39 7.56 3.13 12.95]]
GaussianKernelPrior
¶tikreg.temporal_priors.
GaussianKernelPrior
(delays=None, sigma=1.0, **kwargs)¶Bases: tikreg.temporal_priors.TemporalPrior
Gaussian kernel temporal prior (a.k.a RBF kernel).
__init__
(self, delays=None, sigma=1.0, **kwargs)¶Construct a temporal MVN prior from a Gaussian (RBF) kernel
Parameters: |
|
---|
References
For a great description of Gaussian Processes and their relationship to RBF Kernels: https://distill.pub/2019/visual-exploration-gaussian-processes/
Examples
>>> gaussian_prior = GaussianKernelPrior(delays=np.arange(5))
>>> prior_covar = gaussian_prior.get_prior()
>>> print(prior_covar.shape)
(5, 5)
>>> print(np.round(prior_covar, 2))
[[1. 0.61 0.14 0.01 0. ]
[0.61 1. 0.61 0.14 0.01]
[0.14 0.61 1. 0.61 0.14]
[0.01 0.14 0.61 1. 0.61]
[0. 0.01 0.14 0.61 1. ]]
get_prior
(self, alpha=1.0, hhparam=1.0, dodetnorm=False)¶Gaussian/RBF kernel as a temporal prior covariance matrix.
Parameters: |
|
---|
HRFPrior
¶tikreg.temporal_priors.
HRFPrior
(delays=None, dt=2.0, duration=20, **kwargs)¶Bases: tikreg.temporal_priors.TemporalPrior
Haemodynamic response function prior
__init__
(self, delays=None, dt=2.0, duration=20, **kwargs)¶Generates a discrete sampling of the HRF.
The time samples are generated as: time_samples = np.arange(0, duration, dt)
And the corresponding delays: delays = np.arange(len(time_samples))
Parameters: |
|
---|
Examples
>>> hrf_prior = HRFPrior(delays=range(5), dt=2.0, duration=20)
>>> print(hrf_prior.delays)
[0 1 2 3 4]
>>> prior_covar = hrf_prior.get_prior()
>>> print(prior_covar.shape)
(5, 5)
>>> print(np.round(prior_covar, 2))
[[0. 0. 0. 0. 0. ]
[0. 0.44 0.55 0.22 0.18]
[0. 0.55 1.28 0.97 0.54]
[0. 0.22 0.97 1. 0.56]
[0. 0.18 0.54 0.56 0.36]]
PriorFromPenalty
¶tikreg.temporal_priors.
PriorFromPenalty
(penalty, delays=None, wishart=True, **kwargs)¶Bases: tikreg.temporal_priors.TemporalPrior
Build a prior from a Tikhnov temporal penalty covariance.
__init__
(self, penalty, delays=None, wishart=True, **kwargs)¶Parameters: |
|
---|
get_prior
(self, alpha=1.0, hhparam=0.0, dodetnorm=False)¶Convert the penalty to a prior.
Parameters: |
|
---|---|
Returns: |
|
Notes
where P is the temporal penalty covariance, \(\gamma\) is the hyper-prior parameter (hhparam).
set_wishart
(self, wishart)¶Set the covariance of the hyper-prior regularization.
SmoothnessPrior
¶tikreg.temporal_priors.
SmoothnessPrior
(delays=[0, 1, 2, 3, 4], order=2, wishart=True, **kwargs)¶Bases: tikreg.temporal_priors.PriorFromPenalty
Smoothness temporal MVN prior.
__init__
(self, delays=[0, 1, 2, 3, 4], order=2, wishart=True, **kwargs)¶Parameters: |
|
---|
Examples
>>> smoothness_prior = SmoothnessPrior(delays=np.arange(5))
>>> print(smoothness_prior.penalty)
[[ 5. -4. 1. 0. 0.]
[-4. 6. -4. 1. 0.]
[ 1. -4. 6. -4. 1.]
[ 0. 1. -4. 6. -4.]
[ 0. 0. 1. -4. 5.]]
>>> prior_covar = smoothness_prior.get_prior()
>>> print(prior_covar.shape)
(5, 5)
>>> print(np.round(prior_covar, 2))
[[1.53 2.22 2.25 1.78 0.97]
[2.22 3.78 4. 3.22 1.78]
[2.25 4. 4.75 4. 2.25]
[1.78 3.22 4. 3.78 2.22]
[0.97 1.78 2.25 2.22 1.53]]
SphericalPrior
¶tikreg.temporal_priors.
SphericalPrior
(delays=[0, 1, 2, 3, 4], **kwargs)¶Bases: tikreg.temporal_priors.TemporalPrior
Equivalent to ridge regression.
__init__
(self, delays=[0, 1, 2, 3, 4], **kwargs)¶Parameters: |
|
---|
Examples
>>> spherical_prior = SphericalPrior(delays=np.arange(5))
>>> prior_covar = spherical_prior.get_prior()
>>> print(prior_covar.shape)
(5, 5)
>>> print(np.round(prior_covar, 2))
[[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]]
TemporalPrior
¶tikreg.temporal_priors.
TemporalPrior
(prior, delays=None, hhparams=[0.0], **kwargs)¶Bases: tikreg.BasePrior
Basic temporal MVN prior.
__init__
(self, prior, delays=None, hhparams=[0.0], **kwargs)¶Parameters: |
|
---|
get_hhparams
(self)¶Return the active hyper-prior parameters.
set_hhparameters
(self, hhparams)¶Set the hyper-prior parameters
tikreg.temporal_priors.
get_delays_from_prior
(raw_prior, delays)¶Parameters: |
|
---|