Commit 59a009cb by Philipp Arras

### Tweak docs

parent 0d3e909a
 ... @@ -33,14 +33,15 @@ from ..sugar import domain_union, from_random, full, makeField ... @@ -33,14 +33,15 @@ from ..sugar import domain_union, from_random, full, makeField class MeanfieldModel(): class MeanfieldModel(): ''' """Collect the operators required for Gaussian mean-field variational Collects the operators required for Gaussian mean-field variational inference. inference. Parameters Parameters ---------- ---------- domain: MultiDomain domain: MultiDomain The domain of the model parameters. The domain of the model parameters. ''' """ def __init__(self, domain): def __init__(self, domain): self.domain = MultiDomain.make(domain) self.domain = MultiDomain.make(domain) self.Flat = Multifield2Vector(self.domain) self.Flat = Multifield2Vector(self.domain) ... @@ -52,17 +53,18 @@ class MeanfieldModel(): ... @@ -52,17 +53,18 @@ class MeanfieldModel(): self.entropy = GaussianEntropy(self.std.target) @ self.std self.entropy = GaussianEntropy(self.std.target) @ self.std def get_initial_pos(self, initial_mean=None, initial_sig = 1): def get_initial_pos(self, initial_mean=None, initial_sig = 1): ''' """Provide an initial position for a given mean parameter vector and an Provides an initial position for a given mean parameter vector and an initial standard deviation. initial standard deviation. Parameters Parameters ---------- ---------- initial_mean: MultiField initial_mean: MultiField The initial mean of the variational approximation. If not None, a Gaussian sample with mean zero and standard deviation of 0.1 is used. The initial mean of the variational approximation. If not None, a Default: None Gaussian sample with mean zero and standard deviation of 0.1 is used. Default: None initial_sig: positive float initial_sig: positive float The initial standard deviation shared by all parameters. Default: 1 The initial standard deviation shared by all parameters. Default: 1 ''' """ initial_pos = from_random(self.generator.domain).to_dict() initial_pos = from_random(self.generator.domain).to_dict() initial_pos['latent'] = full(self.generator.domain['latent'], 0.) initial_pos['latent'] = full(self.generator.domain['latent'], 0.) ... @@ -76,14 +78,15 @@ class MeanfieldModel(): ... @@ -76,14 +78,15 @@ class MeanfieldModel(): class FullCovarianceModel(): class FullCovarianceModel(): ''' """Collect the operators required for Gaussian full-covariance variational Collects the operators required for Gaussian full-covariance variational inference. inference. Parameters Parameters ---------- ---------- domain: MultiDomain domain: MultiDomain The domain of the model parameters. The domain of the model parameters. ''' """ def __init__(self, domain): def __init__(self, domain): self.domain = MultiDomain.make(domain) self.domain = MultiDomain.make(domain) self.Flat = Multifield2Vector(self.domain) self.Flat = Multifield2Vector(self.domain) ... @@ -108,23 +111,24 @@ class FullCovarianceModel(): ... @@ -108,23 +111,24 @@ class FullCovarianceModel(): Resp = Respacer(MatMult.target, mean.target) Resp = Respacer(MatMult.target, mean.target) self.generator = self.Flat.adjoint @ (mean + Resp @ MatMult @ matmul_setup) self.generator = self.Flat.adjoint @ (mean + Resp @ MatMult @ matmul_setup) Diag = DiagonalSelector(cov.target, self.Flat.target) Diag = DiagonalSelector(cov.target, self.Flat.target) diag_cov = Diag(cov).absolute() diag_cov = Diag(cov).absolute() self.entropy = GaussianEntropy(diag_cov.target) @ diag_cov self.entropy = GaussianEntropy(diag_cov.target) @ diag_cov def get_initial_pos(self, initial_mean=None, initial_sig=1): def get_initial_pos(self, initial_mean=None, initial_sig=1): ''' """Provide an initial position for a given mean parameter vector and a Provides an initial position for a given mean parameter vector and a diagonal covariance with an initial standard deviation. diagonal covariance with an initial standard deviation. Parameters Parameters ---------- ---------- initial_mean: MultiField initial_mean: MultiField The initial mean of the variational approximation. If not None, a Gaussian sample with mean zero and standard deviation of 0.1 is used. The initial mean of the variational approximation. If not None, a Default: None Gaussian sample with mean zero and standard deviation of 0.1 is used. Default: None initial_sig: positive float initial_sig: positive float The initial standard deviation shared by all parameters. Default: 1 The initial standard deviation shared by all parameters. Default: 1 ''' """ initial_pos = from_random(self.generator.domain).to_dict() initial_pos = from_random(self.generator.domain).to_dict() initial_pos['latent'] = full(self.generator.domain['latent'], 0.) initial_pos['latent'] = full(self.generator.domain['latent'], 0.) diag_tri = np.diag(np.full(self.flat_domain.shape[0], initial_sig))[np.tril_indices(self.flat_domain.shape[0])] diag_tri = np.diag(np.full(self.flat_domain.shape[0], initial_sig))[np.tril_indices(self.flat_domain.shape[0])] ... @@ -136,14 +140,15 @@ class FullCovarianceModel(): ... @@ -136,14 +140,15 @@ class FullCovarianceModel(): class GaussianEntropy(EnergyOperator): class GaussianEntropy(EnergyOperator): ''' """Calculate the entropy of a Gaussian distribution given the diagonal of a Calculates the entropy of a Gaussian distribution given the diagonal of a triangular decomposition of the covariance. triangular decomposition of the covariance. Parameters Parameters ---------- ---------- domain: Domain domain: Domain The domain of the diagonal. The domain of the diagonal. ''' """ def __init__(self, domain): def __init__(self, domain): self._domain = domain self._domain = domain ... @@ -159,16 +164,17 @@ class GaussianEntropy(EnergyOperator): ... @@ -159,16 +164,17 @@ class GaussianEntropy(EnergyOperator): class LowerTriangularProjector(LinearOperator): class LowerTriangularProjector(LinearOperator): ''' """Project the DOFs of a triangular matrix into the matrix form. Projects the DOFs of a triangular matrix into the matrix form. Parameters Parameters ---------- ---------- domain: Domain domain: Domain A one-dimensional domain containing N(N+1)/2 DOFs of a triangular matrix. A one-dimensional domain containing N(N+1)/2 DOFs of a triangular matrix. target: Domain target: Domain A two-dimensional domain with NxN entries. A two-dimensional domain with NxN entries. ''' """ def __init__(self, domain, target): def __init__(self, domain, target): self._domain = DomainTuple.make(domain) self._domain = DomainTuple.make(domain) self._target = DomainTuple.make(target) self._target = DomainTuple.make(target) ... @@ -187,16 +193,17 @@ class LowerTriangularProjector(LinearOperator): ... @@ -187,16 +193,17 @@ class LowerTriangularProjector(LinearOperator): class DiagonalSelector(LinearOperator): class DiagonalSelector(LinearOperator): ''' """Extract the diagonal of a two-dimensional field. Extracts the diagonal of a two-dimensional field. Parameters Parameters ---------- ---------- domain: Domain domain: Domain The two-dimensional domain of the input field The two-dimensional domain of the input field target: Domain target: Domain A one-dimensional domain in which the diagonal of the input field lives. The one-dimensional domain on which the diagonal of the input field is ''' defined. """ def __init__(self, domain, target): def __init__(self, domain, target): self._domain = DomainTuple.make(domain) self._domain = DomainTuple.make(domain) self._target = DomainTuple.make(target) self._target = DomainTuple.make(target) ... @@ -211,16 +218,16 @@ class DiagonalSelector(LinearOperator): ... @@ -211,16 +218,16 @@ class DiagonalSelector(LinearOperator): class Respacer(LinearOperator): class Respacer(LinearOperator): ''' """Re-map a field from one domain to another one with the same amounts of Re-maps a field from one domain to another one with the same amounts of DOFs. Wrapps the numpy.reshape method. DOFs. Wrapps the numpy.reshape method. Parameters Parameters ---------- ---------- domain: Domain domain: Domain The domain of the input field. The domain of the input field. target: Domain target: Domain The domain of the output field. The domain of the output field. ''' """ def __init__(self, domain, target): def __init__(self, domain, target): self._domain = DomainTuple.make(domain) self._domain = DomainTuple.make(domain) ... ...