gns.prob_funcs module¶
-
class
gns.prob_funcs.KentDistribution(kappa, beta, g1, g2, g3)[source]¶ Bases:
objectKent-Fisher distribution (see https://en.wikipedia.org/wiki/Kent_distribution). Attempts to roughly follow style of scipy.stats functions in terms of how the pdf is fitted and evaluated
Methods
cCalc(self)Calculate normalisation coefficient c logpdf(self, angles)Uses try and IndexError block for same reason as pdf and logpdf methods above pdf
-
class
gns.prob_funcs.KentDistributionSum(kappas, betas, g1s, g2s, g3s)[source]¶ Bases:
objectSum of Kent distribution pdfs.
Methods
logpdf pdf
-
class
gns.prob_funcs.LhoodObjs(mu, sigma, LhoodTypes, bounds=array([], dtype=float64))[source]¶ Bases:
objectClass which is essentially defined to wrap around scipy.stats.continuous_rv inheriting classes (e.g. scipy.stats.norm). Main purpose of class is to have methods .pdf (.logpdf) which evaluate the .pdf methods of a list of rv_continuous instances (specified by LhoodTypes) and multiply (add) together the resulting values. Useful so that you can create an object whose .pdf method evaluates product of Lhoods and can still be used by Lhood() (LLhood()) Note the outputted Lhood has shape (len(x[:]),), NOT AS IN CASE OF instances of single continuous_rv instances. This is because the variable Lhoods is declared to have this shape.
Methods
fitLhoods(self)Separately fits 1-d likelihood functions (normal or von Mises) using each element of self.mu, and each diagonal element of self.sigma. logpdf(self, x)evaluates .logpdf method of all Lhood objects in self.LhoodObjsList and adds resulting values together. pdf(self, x)evaluates .pdf method of all Lhood objects in self.LhoodObjsList and multiplies resulting values together. -
fitLhoods(self)[source]¶ Separately fits 1-d likelihood functions (normal or von Mises) using each element of self.mu, and each diagonal element of self.sigma. NB von Mises is parameterised by kappa = 1 / variance, normal is parameterised by standard deviation
-
logpdf(self, x)[source]¶ evaluates .logpdf method of all Lhood objects in self.LhoodObjsList and adds resulting values together. It may be the case that x is a 1d array (n,) instead of a 2d array (m,n), this is what causes the IndexErrors. Could instead ensure that all Lhood vectors are instead arrays, but I don’t think it makes much difference in terms of efficiency or clarity of code. Note this isn’t in an issue in integrating functions, as they reshape each parameter point to (1,nDims) This could be done by writing separate .pdf methods for when x is 1-d or 2-d
-
pdf(self, x)[source]¶ evaluates .pdf method of all Lhood objects in self.LhoodObjsList and multiplies resulting values together. It may be the case that x is a 1d array (n,) instead of a 2d array (m,n), this is what the IndexError except statements are for. Could instead ensure that all Lhood vectors are instead arrays, but I don’t think it makes much difference in terms of efficiency or clarity of code. Note this isn’t in an issue in integrating functions, as they reshape each parameter point to (1,nDims)
-
-
class
gns.prob_funcs.priorObjs(priorFuncsPdf, priorFuncsLogPdf, priorFuncsPpf)[source]¶ Bases:
objectclass with priorFuncsP*f as attributes required when creating an object, with methods which evaluate these functions (and multiply together in case of pdf) whilst just requiring livepoints as argument. This is essentially a work around for the toys models so the prior and inverse prior functions can be called with just livepoints as an argument, to fit to the way a user specified prior would be best called
Methods
invPrior(self, livePoints)Same as the function invPrior(), but uses self.priorFuncsPpf rather than taking it as an argument logPriorFuncsSum(self, livePoint)Same as the function logPriorFuncsSum(), but uses self.priorFuncsPdf rather than taking it as an argument. priorFuncsProd(self, livePoint)Same as the function priorFuncsProd(), but uses self.priorFuncsPdf rather than taking it as an argument Only currently designed to work with one livepoint at a time. -
invPrior(self, livePoints)[source]¶ Same as the function invPrior(), but uses self.priorFuncsPpf rather than taking it as an argument
-
logPriorFuncsSum(self, livePoint)[source]¶ Same as the function logPriorFuncsSum(), but uses self.priorFuncsPdf rather than taking it as an argument. Here we have opposite problem to LhoodObjs class. When using theoretical Z/ H functions, parameter has shape (1, nDims) when it needs to have shape (nDims) to not cause an IndexError exception
-
priorFuncsProd(self, livePoint)[source]¶ Same as the function priorFuncsProd(), but uses self.priorFuncsPdf rather than taking it as an argument Only currently designed to work with one livepoint at a time. Here we have opposite problem to LhoodObjs class. When using theoretical Z/ H functions, parameter has shape (1, nDims) when it needs to have shape (nDims) to not cause an IndexError exception
-
-
gns.prob_funcs.fitLhood(LhoodParams)[source]¶ fit scipy.stats objects (without data) for parameters to make future evaluations much faster. LLhoodType values correspond as follows
2: is multivariate Gaussian, applicable in most ‘usual’ circumstances
3: is the 1d von Mises distribution, a ‘wrapped likelihood function defined on [-pi, pi], equivalent to having a likelihood defined on the unit circle and parameterised by theta isin [-pi, pi]
4: is the 2d (independent) von Mises distribution, a wrapped likelihood function defined on [-pi, pi] x [-pi, pi], equivalent to having a likelihood defined on the unit torus and parameterised by theta isin [-pi, pi] and phi isin [-pi, pi]
5: uniform x truncated Gaussian on [0, pi]
6: von Mises on [-pi, pi] x truncated Gaussian on [-pi/2, pi/2]
7: von Mises on [-pi, pi] x truncated Gaussian on [0, pi]
8: von Mises on [-pi, pi]^4
9: von Mises on [-pi, pi]^6
10: Kent distribution on a sphere
11: sum of Kent distributions on a sphere
12: sums of Kent distributions on three spheres
13: sums of Kent distributions on five spheres
14: sums of Kent distributions on six spheres
15: Gaussian x sum of Kent distributions on a sphere
16: von Mises on [-pi, pi]^8
17: von Mises on [-pi, pi]^10
Args:
LhoodParams: list containing likelihood type (denoted by integer) and hyperparameters (array), see prob_funcs.getToyHypers() docstring.
Returns:
LhoodObj object corresponding to LhoodParams
-
gns.prob_funcs.fitPriors(priorParams)[source]¶ Only currently handles one dimensional (independent priors). Scipy.stats multivariate functions do not have built in inverse CDF methods, so if one wants to consider multivariate priors one may have to write their own. Note scipy.stats.uniform takes parameters loc and scale where the boundaries are defined to be loc and loc + scale, so scale = upper - lower bound. Returns list of fitted prior objects length of nDims (one function for each parameter).
The prior types (integers) correspond as follows:
1: Uniform
2: Gaussian
3: Sine
Args:
priorParams: array containing prior type (denoted by integer) and hyperparameters (array), see getToyHypers() docstring.
Returns:
List of prior functions corresponding to priorParams.
-
gns.prob_funcs.getPriorLogPdfs(priorObjs)[source]¶ Takes list of fitted prior objects, returns list of objects’ .logpdf() methods
-
gns.prob_funcs.getPriorPdfs(priorObjs)[source]¶ Takes list of fitted prior objects, returns list of objects’ .pdf() methods
-
gns.prob_funcs.getPriorPpfs(priorObjs)[source]¶ Takes list of fitted prior objects, returns list of objects’ .ppf() methods
-
gns.prob_funcs.invPrior(livePoints, priorFuncsPpf)[source]¶ take in array of livepoints each which has value isin[0,1], and has nDim dimensions. Output physical array of values corresponding to priors for each parameter dimension.
-
gns.prob_funcs.logPriorFuncsSum(livePoint, priorFuncsLogPdf)[source]¶ calculates logpdf of prior for each parameter dimension, then adds these together to get the logpdf of the prior (i.e. the prior logpdf assuming the parameters are independent)
-
gns.prob_funcs.priorFuncsProd(livePoint, priorFuncsPdf)[source]¶ calculates pdf of prior for each parameter dimension, then multiplies these together to get the pdf of the prior (i.e. the prior pdf assuming the parameters are independent) Works in linear space, but can easily be adapted if this ever leads to underflow errors (consider sum of log(pi(theta))). Only currently designed to work with one livepoint at a time