lsst.meas.modelfit  15.0-3-g150fc43+8
priorsContinued.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008-2013 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 from __future__ import absolute_import, division, print_function
25 
26 __all__ = ("fitMixture", "SemiEmpiricalPriorConfig",
27  "SoftenedLinearPriorControl")
28 
29 from builtins import range
30 
31 import numpy as np
32 
33 from lsst.pex.config import makeConfigClass
34 from lsst.utils import continueClass
35 
36 from ..mixture import Mixture
37 from .priors import (SemiEmpiricalPriorControl, SemiEmpiricalPrior,
38  SoftenedLinearPriorControl, SoftenedLinearPrior,
39  MixturePrior)
40 
41 
42 SemiEmpiricalPriorConfig = makeConfigClass(SemiEmpiricalPriorControl)
43 
44 SoftenedLinearPriorConfig = makeConfigClass(SoftenedLinearPriorControl)
45 
46 
47 @continueClass # noqa
49 
50  ConfigClass = SemiEmpiricalPriorConfig
51 
52 
53 @continueClass # noqa
55 
56  ConfigClass = SoftenedLinearPriorConfig
57 
58 
59 def fitMixture(data, nComponents, minFactor=0.25, maxFactor=4.0,
60  nIterations=20, df=float("inf")):
61  """Fit a ``Mixture`` distribution to a set of (e1, e2, r) data points,
62  returing a ``MixturePrior`` object.
63 
64  Parameters
65  ----------
66  data : numpy.ndarray
67  array of data points to fit; shape=(N,3)
68  nComponents : int
69  number of components in the mixture distribution
70  minFactor : float
71  ellipticity variance of the smallest component in the initial mixture,
72  relative to the measured variance
73  maxFactor : float
74  ellipticity variance of the largest component in the initial mixture,
75  relative to the measured variance
76  nIterations : int
77  number of expectation-maximization update iterations
78  df : float
79  number of degrees of freedom for component Student's T distributions
80  (inf=Gaussian).
81  """
82  components = Mixture.ComponentList()
83  rMu = data[:, 2].mean()
84  rSigma = data[:, 2].var()
85  eSigma = 0.5*(data[:, 0].var() + data[:, 1].var())
86  mu = np.array([0.0, 0.0, rMu], dtype=float)
87  baseSigma = np.array([[eSigma, 0.0, 0.0],
88  [0.0, eSigma, 0.0],
89  [0.0, 0.0, rSigma]])
90  for factor in np.linspace(minFactor, maxFactor, nComponents):
91  sigma = baseSigma.copy()
92  sigma[:2, :2] *= factor
93  components.append(Mixture.Component(1.0, mu, sigma))
94  mixture = Mixture(3, components, df)
95  restriction = MixturePrior.getUpdateRestriction()
96  for i in range(nIterations):
97  mixture.updateEM(data, restriction)
98  return mixture
def fitMixture(data, nComponents, minFactor=0.25, maxFactor=4.0, nIterations=20, df=float("inf"))
A weighted Student&#39;s T or Gaussian distribution used as a component in a Mixture. ...
Definition: Mixture.h:46