isochrones/starmodel_old.py
def fit_mcmc(self,nwalkers=200,nburn=100,niter=200,
                 p0=None,initial_burn=None,
                 ninitial=100, loglike_kwargs=None,
                 **kwargs):
        """Fits stellar model using MCMC.

        See :func:`StarModel.fit_mcmc`.
            
        """

        #clear any saved _samples
        if self._samples is not None:
            self._samples = None
            

        if self.fit_for_distance:
            npars = 7
            if initial_burn is None:
                initial_burn = True
        else:
            if initial_burn is None:
                initial_burn = False
            npars = 5

        if p0 is None:
            mA_0,age0,feh0 = self.ic.random_points(nwalkers)
            mB_0,foo1,foo2 = self.ic.random_points(nwalkers)
            mC_0,foo3,foo4 = self.ic.random_points(nwalkers)
            m_all = np.sort(np.array([mA_0, mB_0, mC_0]), axis=0)
            mA_0, mB_0, mC_0 = (m_all[0,:], m_all[1,:], m_all[2,:])

            d0 = 10**(rand.uniform(0,np.log10(self.max_distance),size=nwalkers))
            AV0 = rand.uniform(0,self.maxAV,size=nwalkers)
            if self.fit_for_distance:
                p0 = np.array([mA_0,mB_0,mC_0,age0,feh0,d0,AV0]).T
            else:
                p0 = np.array([mA_0,mB_0,mC_0,age0,feh0]).T
            if initial_burn:
                sampler = emcee.EnsembleSampler(nwalkers,npars,self.lnpost,
                                                **kwargs)
                #ninitial = 300 #should this be parameter?
                pos, prob, state = sampler.run_mcmc(p0, ninitial) 
                wokinds = np.where((sampler.naccepted/ninitial > 0.15) &
                                   (sampler.naccepted/ninitial < 0.4))[0]
                i=1
                while len(wokinds)==0:
                    thresh = 0.15 - i*0.02
                    if thresh < 0:
                        raise RuntimeError('Initial burn has no acceptance?')
                    wokinds = np.where((sampler.naccepted/ninitial > thresh) &
                                       (sampler.naccepted/ninitial < 0.4))[0]
                    i += 1
                inds = rand.randint(len(wokinds),size=nwalkers)
                p0 = sampler.chain[wokinds[inds],:,:].mean(axis=1) #reset p0
                p0 *= (1 + rand.normal(size=p0.shape)*0.01)
        else:
            p0 = np.array(p0)
            p0 = rand.normal(size=(nwalkers,npars))*0.01 + p0.T[None,:]
            if self.fit_for_distance:
                p0[:,5] *= (1 + rand.normal(size=nwalkers)*0.5) #distance
        
        sampler = emcee.EnsembleSampler(nwalkers,npars,self.lnpost)
        pos, prob, state = sampler.run_mcmc(p0, nburn)
        sampler.reset()
        sampler.run_mcmc(pos, niter, rstate0=state)
        
        self._sampler = sampler
        return sampler
Fits stellar model using MCMC.

        See :func:`StarModel.fit_mcmc`.
            
        
Fits stellar model using MCMC.
Fits stellar model using MCMC .
def fit_mcmc(self,nwalkers=200,nburn=100,niter=200,
                 p0=None,initial_burn=None,
                 ninitial=100, loglike_kwargs=None,
                 **kwargs):
        if self._samples is not None:
            self._samples = None
        if self.fit_for_distance:
            npars = 7
            if initial_burn is None:
                initial_burn = True
        else:
            if initial_burn is None:
                initial_burn = False
            npars = 5
        if p0 is None:
            mA_0,age0,feh0 = self.ic.random_points(nwalkers)
            mB_0,foo1,foo2 = self.ic.random_points(nwalkers)
            mC_0,foo3,foo4 = self.ic.random_points(nwalkers)
            m_all = np.sort(np.array([mA_0, mB_0, mC_0]), axis=0)
            mA_0, mB_0, mC_0 = (m_all[0,:], m_all[1,:], m_all[2,:])
            d0 = 10**(rand.uniform(0,np.log10(self.max_distance),size=nwalkers))
            AV0 = rand.uniform(0,self.maxAV,size=nwalkers)
            if self.fit_for_distance:
                p0 = np.array([mA_0,mB_0,mC_0,age0,feh0,d0,AV0]).T
            else:
                p0 = np.array([mA_0,mB_0,mC_0,age0,feh0]).T
            if initial_burn:
                sampler = emcee.EnsembleSampler(nwalkers,npars,self.lnpost,
                                                **kwargs)
                pos, prob, state = sampler.run_mcmc(p0, ninitial) 
                wokinds = np.where((sampler.naccepted/ninitial > 0.15) &
                                   (sampler.naccepted/ninitial < 0.4))[0]
                i=1
                while len(wokinds)==0:
                    thresh = 0.15 - i*0.02
                    if thresh < 0:
                        raise RuntimeError('Initial burn has no acceptance?')
                    wokinds = np.where((sampler.naccepted/ninitial > thresh) &
                                       (sampler.naccepted/ninitial < 0.4))[0]
                    i += 1
                inds = rand.randint(len(wokinds),size=nwalkers)
                p0 = sampler.chain[wokinds[inds],:,:].mean(axis=1) 
                p0 *= (1 + rand.normal(size=p0.shape)*0.01)
        else:
            p0 = np.array(p0)
            p0 = rand.normal(size=(nwalkers,npars))*0.01 + p0.T[None,:]
            if self.fit_for_distance:
                p0[:,5] *= (1 + rand.normal(size=nwalkers)*0.5) 
        sampler = emcee.EnsembleSampler(nwalkers,npars,self.lnpost)
        pos, prob, state = sampler.run_mcmc(p0, nburn)
        sampler.reset()
        sampler.run_mcmc(pos, niter, rstate0=state)
        self._sampler = sampler
        return sampler
def fit_mcmc ( self , nwalkers = 200 , nburn = 100 , niter = 200 , p0 = None , initial_burn = None , ninitial = 100 , loglike_kwargs = None , ** kwargs ) : if self . _samples is not None : self . _samples = None if self . fit_for_distance : npars = 7 if initial_burn is None : initial_burn = True else : if initial_burn is None : initial_burn = False npars = 5 if p0 is None : mA_0 , age0 , feh0 = self . ic . random_points ( nwalkers ) mB_0 , foo1 , foo2 = self . ic . random_points ( nwalkers ) mC_0 , foo3 , foo4 = self . ic . random_points ( nwalkers ) m_all = np . sort ( np . array ( [ mA_0 , mB_0 , mC_0 ] ) , axis = 0 ) mA_0 , mB_0 , mC_0 = ( m_all [ 0 , : ] , m_all [ 1 , : ] , m_all [ 2 , : ] ) d0 = 10 ** ( rand . uniform ( 0 , np . log10 ( self . max_distance ) , size = nwalkers ) ) AV0 = rand . uniform ( 0 , self . maxAV , size = nwalkers ) if self . fit_for_distance : p0 = np . array ( [ mA_0 , mB_0 , mC_0 , age0 , feh0 , d0 , AV0 ] ) . T else : p0 = np . array ( [ mA_0 , mB_0 , mC_0 , age0 , feh0 ] ) . T if initial_burn : sampler = emcee . EnsembleSampler ( nwalkers , npars , self . lnpost , ** kwargs ) pos , prob , state = sampler . run_mcmc ( p0 , ninitial ) wokinds = np . where ( ( sampler . naccepted / ninitial > 0.15 ) & ( sampler . naccepted / ninitial < 0.4 ) ) [ 0 ] i = 1 while len ( wokinds ) == 0 : thresh = 0.15 - i * 0.02 if thresh < 0 : raise RuntimeError ( 'Initial burn has no acceptance?' ) wokinds = np . where ( ( sampler . naccepted / ninitial > thresh ) & ( sampler . naccepted / ninitial < 0.4 ) ) [ 0 ] i += 1 inds = rand . randint ( len ( wokinds ) , size = nwalkers ) p0 = sampler . chain [ wokinds [ inds ] , : , : ] . mean ( axis = 1 ) p0 *= ( 1 + rand . normal ( size = p0 . shape ) * 0.01 ) else : p0 = np . array ( p0 ) p0 = rand . normal ( size = ( nwalkers , npars ) ) * 0.01 + p0 . T [ None , : ] if self . fit_for_distance : p0 [ : , 5 ] *= ( 1 + rand . normal ( size = nwalkers ) * 0.5 ) sampler = emcee . EnsembleSampler ( nwalkers , npars , self . lnpost ) pos , prob , state = sampler . run_mcmc ( p0 , nburn ) sampler . reset ( ) sampler . run_mcmc ( pos , niter , rstate0 = state ) self . _sampler = sampler return sampler
Fits stellar model using MCMC.
Fits stellar model using MCMC .
"""Fits stellar model using MCMC.

        See :func:`StarModel.fit_mcmc`.
            
        """ #clear any saved _samples #ninitial = 300 #should this be parameter? #reset p0 #distance
self
nwalkers
nburn
niter
p0
initial_burn
ninitial
loglike_kwargs