32from .._modelfitLib
import (Mixture, SemiEmpiricalPriorControl, SemiEmpiricalPrior,
54def fitMixture(data, nComponents, minFactor=0.25, maxFactor=4.0,
55 nIterations=20, df=float(
"inf")):
56 """Fit a ``Mixture`` distribution to a set of (e1, e2, r) data points,
57 returing a ``MixturePrior`` object.
62 array of data points to fit; shape=(N,3)
64 number of components in the mixture distribution
66 ellipticity variance of the smallest component in the initial mixture,
67 relative to the measured variance
69 ellipticity variance of the largest component in the initial mixture,
70 relative to the measured variance
72 number of expectation-maximization update iterations
74 number of degrees of freedom for component Student's T distributions
78 rMu = data[:, 2].mean()
79 rSigma = data[:, 2].var()
80 eSigma = 0.5*(data[:, 0].var() + data[:, 1].var())
81 mu = np.array([0.0, 0.0, rMu], dtype=float)
82 baseSigma = np.array([[eSigma, 0.0, 0.0],
85 for factor
in np.linspace(minFactor, maxFactor, nComponents):
86 sigma = baseSigma.copy()
87 sigma[:2, :2] *= factor
89 mixture = Mixture(3, components, df)
90 restriction = MixturePrior.getUpdateRestriction()
91 for i
in range(nIterations):
92 mixture.updateEM(data, restriction)