24 __all__ = (
"fitMixture",
"SemiEmpiricalPriorConfig",
25 "SoftenedLinearPriorControl")
29 from lsst.pex.config
import makeConfigClass
32 from ..mixture
import Mixture
33 from .priors
import (SemiEmpiricalPriorControl, SemiEmpiricalPrior,
34 SoftenedLinearPriorControl, SoftenedLinearPrior,
46 ConfigClass = SemiEmpiricalPriorConfig
52 ConfigClass = SoftenedLinearPriorConfig
55 def fitMixture(data, nComponents, minFactor=0.25, maxFactor=4.0,
56 nIterations=20, df=float(
"inf")):
57 """Fit a ``Mixture`` distribution to a set of (e1, e2, r) data points,
58 returing a ``MixturePrior`` object.
63 array of data points to fit; shape=(N,3)
65 number of components in the mixture distribution
67 ellipticity variance of the smallest component in the initial mixture,
68 relative to the measured variance
70 ellipticity variance of the largest component in the initial mixture,
71 relative to the measured variance
73 number of expectation-maximization update iterations
75 number of degrees of freedom for component Student's T distributions
79 rMu = data[:, 2].mean()
80 rSigma = data[:, 2].var()
81 eSigma = 0.5*(data[:, 0].var() + data[:, 1].var())
82 mu = np.array([0.0, 0.0, rMu], dtype=float)
83 baseSigma = np.array([[eSigma, 0.0, 0.0],
86 for factor
in np.linspace(minFactor, maxFactor, nComponents):
87 sigma = baseSigma.copy()
88 sigma[:2, :2] *= factor
90 mixture = Mixture(3, components, df)
91 restriction = MixturePrior.getUpdateRestriction()
92 for i
in range(nIterations):
93 mixture.updateEM(data, restriction)