spatial_priors¶Handle feature MVN priors.
CustomPrior(*args, **kwargs) |
Specify a custom feature prior |
PriorFromPenalty(penalty[, wishart]) |
Build a prior from a Tikhnov feature penalty covariance. |
SphericalPrior(feature_space, **kwargs) |
Equivalent to ridge regression. |
CustomPrior¶tikreg.spatial_priors.CustomPrior(*args, **kwargs)¶Bases: tikreg.BasePrior
Specify a custom feature prior
__init__(self, *args, **kwargs)¶| Parameters: |
|
|---|
Examples
>>> mat = np.random.randn(5, 5)
>>> cov = np.dot(mat.T, mat)
>>> custom_prior = CustomPrior(cov)
>>> print(custom_prior.asarray.shape)
(5, 5)
>>> prior_lambda_one = custom_prior.get_prior(1.0)
>>> print(np.round(prior_lambda_one, 2)) # doctest: +SKIP
[[ 3.27 -2.02 2.18 0.05 -5.37]
[-2.02 6.59 0.47 -1.2 3.95]
[ 2.18 0.47 3.75 0.35 -2.52]
[ 0.05 -1.2 0.35 5.9 1.31]
[-5.37 3.95 -2.52 1.31 10.86]]
>>> prior_lambda_two = custom_prior.get_prior(2.0)
>>> print(np.round(prior_lambda_two, 2)) # doctest: +SKIP
[[ 0.82 -0.51 0.54 0.01 -1.34]
[-0.51 1.65 0.12 -0.3 0.99]
[ 0.54 0.12 0.94 0.09 -0.63]
[ 0.01 -0.3 0.09 1.48 0.33]
[-1.34 0.99 -0.63 0.33 2.72]]
PriorFromPenalty¶tikreg.spatial_priors.PriorFromPenalty(penalty, wishart=True, **kwargs)¶Bases: tikreg.BasePrior
Build a prior from a Tikhnov feature penalty covariance.
__init__(self, penalty, wishart=True, **kwargs)¶| Parameters: |
|
|---|
get_prior(self, alpha=1.0, wishart_lambda=0.0, dodetnorm=False)¶Convert the penalty to a prior.
| Parameters: |
|
|---|---|
| Returns: |
|
Notes
where P is the penalty covariance, \(\gamma\) is the hyper-prior parameter (hhparam).
prior2penalty(self, regularizer=0.0, dodetnorm=True)¶set_wishart(self, wishart_prior)¶SphericalPrior¶tikreg.spatial_priors.SphericalPrior(feature_space, **kwargs)¶Bases: tikreg.BasePrior
Equivalent to ridge regression.
__init__(self, feature_space, **kwargs)¶Create a spherical MVN prior for a feature space.
| Parameters: |
|
|---|
Examples
>>> spherical_prior = SphericalPrior(5)
>>> print(spherical_prior.asarray.shape)
(5, 5)
>>> print(np.round(spherical_prior.asarray, 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.]]
get_prior(self, alpha=1.0)¶Apply regularization to prior
| Parameters: |
|
|---|---|
| Returns: |
|
Examples
>>> spherical_prior = SphericalPrior(5)
>>> prior_covar = spherical_prior.get_prior(2.0)
>>> print(np.round(prior_covar, 2))
[[0.25 0. 0. 0. 0. ]
[0. 0.25 0. 0. 0. ]
[0. 0. 0.25 0. 0. ]
[0. 0. 0. 0.25 0. ]
[0. 0. 0. 0. 0.25]]