Exemple #1
0
def _ecgmm(c, e, alpha=[0.2,0.8], mu=[0.5,1.2], sigma=[0.5,0.05],
           flavour='BIC', bootstrap=False):
    """
    Error-Corrected Gaussian Mixture Model (ECGMM) by Hao et al. (2009)

    Everything is coded in their script so here just execute it.

    Parameters
    ----------
        c       : float array
                  galaxy colours
        e       : float array
                  galaxy colour uncertainties
        alpha   : float array-like
                  initial guess for the mixing of the Gaussian models
        mu      : float array-like
                  initial guess for the locations of the Gaussians
        sigma   : float array-like
                  initial guess for the widths of the Gaussians
        flavour : {'AIC', 'BIC'}
                  which information criterion to use
        bootstrap : False or int
                  whether to bootstrap the ECGMM and, if so, how many
                  bootstrap samples to use

    """
    if bootstrap is not False:
        gmm = ecgmmPy.bsecgmm(c, e, alpha, mu, sigma, nboot=100,
                              InfoCriteria=flavour)
    elif flavour.upper() == 'AIC':
        gmm = ecgmmPy.aic_ecgmm(c, e, alpha, mu, sigma)
    elif flavour.upper() == 'BIC':
        gmm = ecgmmPy.bic_ecgmm(c, e, alpha, mu, sigma)
    return alpha, mu, sigma
def ecgmm(c, e, alpha = [0.2, 0.8], mu = [0.5, 1.2], sigma = [0.5, 0.05]):
  """
  Error-Corrected Gaussian Mixture Model (ECGMM) by Hao et al. (2009)
  
  Everything is coded in their script so here just execute it.
  """
  bic = ecgmmPy.bic_ecgmm(c, e, alpha, mu, sigma)
  return alpha, mu, sigma
Exemple #3
0
bg=np.random.normal(mubg,sdbg,nbg)

xerr=np.random.uniform(0,0.2,ncl+nbg)

x=np.append(cl,bg)+np.random.uniform(0,1,ncl+nbg)*xerr


ec.wstat(x,xerr)   # calculate the weighted statistics

# assign initial guess as two mixtures
alpha=np.array([0.5,0.5])
mu=np.array([0.3,0.1])
sigma=np.array([0.05,0.2])

#aic=ec.aic_ecgmm(x,xerr,alpha,mu,sigma)
bic=ec.bic_ecgmm(x,xerr,alpha,mu,sigma)

#make plots
pl.figure(figsize=(12,6))

pl.subplot(1,2,1)
y=np.arange(-1,1,0.0001)
pl.hist(x,bins=30,alpha=0.3,normed=True,facecolor='green')
ec.ecgmmplot(y,alpha,mu,sigma)
pl.xlabel='x'
pl.text(-0.9,3, r'$\mu=$'+str(mu))
pl.text(-0.9,2.6, r'$\sigma=$'+str(sigma))
pl.ylim(0,7)
pl.title("ECGMM")

Exemple #4
0
bg=np.random.normal(mubg,sdbg,nbg)

xerr=np.random.uniform(0,0.2,ncl+nbg)

x=np.append(cl,bg)+np.random.uniform(0,1,ncl+nbg)*xerr


ec.wstat(x,xerr)   # calculate the weighted statistics

# assign initial guess as two mixtures
alpha=np.array([0.5,0.5])
mu=np.array([0.3,0.1])
sigma=np.array([0.05,0.2])

#aic=ec.aic_ecgmm(x,xerr,alpha,mu,sigma)
bic=ec.bic_ecgmm(x,xerr,alpha,mu,sigma)

#make plots
pl.figure(figsize=(12,6))

pl.subplot(1,2,1)
y=np.arange(-1,1,0.0001)
pl.hist(x,bins=30,alpha=0.3,normed=True,facecolor='green')
ec.ecgmmplot(y,alpha,mu,sigma)
pl.xlabel='x'
pl.text(-0.9,3, r'$\mu=$'+str(mu))
pl.text(-0.9,2.6, r'$\sigma=$'+str(sigma))
pl.ylim(0,7)
pl.title("ECGMM")