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.
58
59 Parameters
60 ----------
61 data : numpy.ndarray
62 array of data points to fit; shape=(N,3)
63 nComponents : int
64 number of components in the mixture distribution
65 minFactor : float
66 ellipticity variance of the smallest component in the initial mixture,
67 relative to the measured variance
68 maxFactor : float
69 ellipticity variance of the largest component in the initial mixture,
70 relative to the measured variance
71 nIterations : int
72 number of expectation-maximization update iterations
73 df : float
74 number of degrees of freedom for component Student's T distributions
75 (inf=Gaussian).
76 """
77 components = Mixture.ComponentList()
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],
83 [0.0, eSigma, 0.0],
84 [0.0, 0.0, rSigma]])
85 for factor in np.linspace(minFactor, maxFactor, nComponents):
86 sigma = baseSigma.copy()
87 sigma[:2, :2] *= factor
88 components.append(Mixture.Component(1.0, mu, sigma))
89 mixture = Mixture(3, components, df)
90 restriction = MixturePrior.getUpdateRestriction()
91 for i in range(nIterations):
92 mixture.updateEM(data, restriction)
93 return mixture