def test_simpSample(self): """ Test simple rejection sampler Test method: use KS-statistic for two continuous distributions and ensure that generated values correctly correlate with each one """ #uniform dist ulim = [0,1] ufun = lambda x: 1.0/np.diff(ulim) n = int(1e5) usample = statsFun.simpSample(ufun,n,ulim[0],ulim[1]) self.assertGreaterEqual(usample.min(), ulim[0]) self.assertLessEqual(usample.max(), ulim[1]) nlim = [-10,10] nfun = lambda x: np.exp(-x**2./2.0)/np.sqrt(2.0*np.pi) nsample = statsFun.simpSample(nfun,n,nlim[0],nlim[1]) self.assertGreaterEqual(nsample.min(), nlim[0]) self.assertLessEqual(nsample.min(), nlim[1]) self.assertGreaterEqual(scipy.stats.kstest(usample,'uniform')[1],0.01,'Uniform sample does not look uniform.') self.assertGreaterEqual(scipy.stats.kstest(nsample,'norm')[1],0.01,'Normal sample does not look normal.') self.assertLessEqual(scipy.stats.kstest(nsample,'uniform')[1],0.01,'Normal sample looks too uniform.') self.assertLessEqual(scipy.stats.kstest(usample,'norm')[1],0.01,'Uniform sample looks too normal.')
def test_simpSample_trivial(self): """ Test simple rejection sampler with trivial inputs Test method: set up sampling with equal upper and lower bounds """ ulim = [0,1] ufun = lambda x: 1.0/np.diff(ulim) n = 10000 sample = statsFun.simpSample(ufun,n,0.5,0.5) self.assertEqual(len(sample),n) self.assertTrue(np.all(sample == 0.5))
def gen_eccen(self, n): """Generate eccentricity values Rayleigh distribution, as in Kipping et. al (2013) Args: n (integer): Number of samples to generate Returns: e (ndarray): Planet eccentricity """ n = self.gen_input_check(n) e = statsFun.simpSample(self.edist, n, self.erange[0],self.erange[1]) return e
def gen_eccen(self, n): """Generate eccentricity values Rayleigh distribution, as in Kipping et. al (2013) Args: n (integer): Number of samples to generate Returns: e (ndarray): Planet eccentricity """ n = self.gen_input_check(n) e = statsFun.simpSample(self.edist, n, self.erange[0], self.erange[1]) return e
def gen_sma(self, n): """Generate semi-major axis values in AU Samples a power law distribution with exponential turn-off determined by class attribute smaknee Args: n (integer): Number of samples to generate Returns: a (astropy Quantity array): Semi-major axis in units of AU """ n = self.gen_input_check(n) a = statsFun.simpSample(self.smadist, n, self.arange[0].to('AU').value,\ self.arange[1].to('AU').value)*u.AU return a
def gen_sma(self, n): """Generate semi-major axis values in AU Samples a power law distribution with exponential turn-off determined by class attribute smaknee Args: n (integer): Number of samples to generate Returns: astropy Quantity array: Semi-major axis values in units of AU """ n = self.gen_input_check(n) ar = self.arange.to('AU').value a = statsFun.simpSample(self.dist_sma, n, ar[0], ar[1]) * u.AU return a
def gen_mass(self,n): """Generate planetary mass values in Earth mass The mass is determined by sampling the RV mass distribution from Cumming et al. 2010 Args: n (integer): Number of samples to generate Returns: Mp (astropy Quantity array): Planet mass values in units of Earth mass """ n = self.gen_input_check(n) # unitless mass range Mpr = self.Mprange.to('earthMass').value Mp = statsFun.simpSample(self.dist_mass, n, Mpr[0], Mpr[1])*u.earthMass return Mp
def gen_mass(self,n): """Generate planetary mass values in kg The mass is determined by sampling the RV mass distribution from Cumming et al. 2010 Args: n (integer): Number of samples to generate Returns: Mp (astropy Quantity array): Planet mass in units of kg """ n = self.gen_input_check(n) Mmin = (self.Mprange[0]/const.M_jup).decompose().value Mmax = (self.Mprange[1]/const.M_jup).decompose().value Mp = statsFun.simpSample(self.massdist, n, Mmin, Mmax)*const.M_jup return Mp
def gen_mass(self, n): """Generate planetary mass values in Earth mass The mass is determined by sampling the RV mass distribution from Cumming et al. 2010 Args: n (integer): Number of samples to generate Returns: Mp (astropy Quantity array): Planet mass values in units of Earth mass """ n = self.gen_input_check(n) # unitless mass range Mpr = self.Mprange.to('earthMass').value Mp = statsFun.simpSample(self.dist_mass, n, Mpr[0], Mpr[1]) * u.earthMass return Mp