Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
B1 = Binomial([10, 0.2])
N1 = Normal([0.03, 0.01])
N2 = Normal([0.1, N1])
graph1 = Normal([B1, N2])
graph2 = Normal([1, N2])
statistics_calculator = Identity(degree=2, cross=False)
distance_calculator = LogReg(statistics_calculator)
backend = Backend()
sampler = RejectionABC([graph1, graph2], [distance_calculator, distance_calculator], backend)
rng = np.random.RandomState(1)
sampler.sample_from_prior(rng=rng)
y_sim = sampler.simulate(1, rng=rng)
self.assertTrue(isinstance(y_sim, list))
self.assertTrue(len(y_sim)==2)
self.assertTrue(isinstance(y_sim[0][0], np.ndarray))
def setUp(self):
self.B1 = Binomial([10, 0.2])
self.N1 = Normal([0.03, 0.01])
self.N2 = Normal([0.1, self.N1])
self.graph = Normal([self.B1, self.N2])
statistics_calculator = Identity(degree=2, cross=False)
distance_calculator = LogReg(statistics_calculator)
backend = Backend()
self.sampler = RejectionABC([self.graph], [distance_calculator], backend)
self.rng = np.random.RandomState(1)
self.sampler.sample_from_prior(rng=self.rng)
def setUp(self):
self.stat_calc = Identity(degree = 1, cross = 0)
self.distancefunc = LogReg(self.stat_calc)
y_obs = [160.82499176, 167.24266737, 185.71695756, 153.7045709, 163.40568812, 140.70658699, 169.59102084, 172.81041696, 187.38782738, 179.66358934, 176.63417241, 189.16082803, 181.98288443, 170.18565017, 183.78493886, 166.58387299, 161.9521899, 155.69213073, 156.17867343, 144.51580379, 170.29847515, 197.96767899, 153.36646527, 162.22710198, 158.70012047, 178.53470703, 170.77697743, 164.31392633, 165.88595994, 177.38083686, 146.67058471763457, 179.41946565658628, 238.02751620619537, 206.22458790620766, 220.89530574344568, 221.04082532837026, 142.25301427453394, 261.37656571434275, 171.63761180867033, 210.28121820385866, 237.29130237612236, 175.75558340169619, 224.54340549862235, 197.42448680731226, 165.88273684581381, 166.55094082844519, 229.54308602661584, 222.99844054358519, 185.30223966014586, 152.69149367593846, 206.94372818527413, 256.35498655339154, 165.43140916577741, 250.19273595481803, 148.87781549665536, 223.05547559193792, 230.03418198709608, 146.13611923127021, 138.24716809523139, 179.26755740864527, 141.21704876815426, 170.89587081800852, 222.96391329259626, 188.27229523693822, 202.67075179617672, 211.75963110985992, 217.45423324370509]
# define prior
from abcpy.continuousmodels import Uniform
prior = Uniform([[150, 5], [200, 25]], )
# define the model
model = Gaussian([prior], )
# define statistics
from abcpy.statistics import Identity
statistics_calculator = Identity(degree = 2, cross = False)
# define distance
from abcpy.distances import LogReg
distance_calculator = LogReg(statistics_calculator)
# define backend
from abcpy.backends import BackendSpark as Backend
from abcpy.backends import BackendDummy as Backend
backend = Backend()
# define sampling scheme
from abcpy.inferences import PMCABC
sampler = PMCABC([model], [distance_calculator], backend)
# sample from scheme
T, n_sample, n_samples_per_param = 3, 100, 10
eps_arr = np.array([.75])
epsilon_percentile = 10
journal = sampler.sample([y_obs], T, eps_arr, n_sample, n_samples_per_param, epsilon_percentile)
y_obs = [160.82499176, 167.24266737, 185.71695756, 153.7045709, 163.40568812, 140.70658699, 169.59102084, 172.81041696, 187.38782738, 179.66358934, 176.63417241, 189.16082803, 181.98288443, 170.18565017, 183.78493886, 166.58387299, 161.9521899, 155.69213073, 156.17867343, 144.51580379, 170.29847515, 197.96767899, 153.36646527, 162.22710198, 158.70012047, 178.53470703, 170.77697743, 164.31392633, 165.88595994, 177.38083686, 146.67058471763457, 179.41946565658628, 238.02751620619537, 206.22458790620766, 220.89530574344568, 221.04082532837026, 142.25301427453394, 261.37656571434275, 171.63761180867033, 210.28121820385866, 237.29130237612236, 175.75558340169619, 224.54340549862235, 197.42448680731226, 165.88273684581381, 166.55094082844519, 229.54308602661584, 222.99844054358519, 185.30223966014586, 152.69149367593846, 206.94372818527413, 256.35498655339154, 165.43140916577741, 250.19273595481803, 148.87781549665536, 223.05547559193792, 230.03418198709608, 146.13611923127021, 138.24716809523139, 179.26755740864527, 141.21704876815426, 170.89587081800852, 222.96391329259626, 188.27229523693822, 202.67075179617672, 211.75963110985992, 217.45423324370509]
# define prior
from abcpy.continousmodels import Uniform
prior = Uniform([[150, 5],[200, 25]])
# define the model
model = Gaussian([prior])
# define statistics
from abcpy.statistics import Identity
statistics_calculator = Identity(degree = 2, cross = False)
# define distance
from abcpy.distances import LogReg
distance_calculator = LogReg(statistics_calculator)
# define backend
from abcpy.backends import BackendDummy as Backend
backend = Backend()
# define sampling scheme
from abcpy.inferences import PMCABC
sampler = PMCABC([model], distance_calculator, backend)
# sample from scheme
T, n_sample, n_samples_per_param = 3, 250, 10
eps_arr = np.array([.75])
epsilon_percentile = 10
journal = sampler.sample([y_obs], T, eps_arr, n_sample, n_samples_per_param, epsilon_percentile)
return journal
# define prior
from abcpy.continuousmodels import Uniform
mu = Uniform([[150], [200]], )
sigma = Uniform([[5], [25]], )
# define the model
from abcpy.continuousmodels import Normal
height = Normal([mu, sigma], )
# define statistics
from abcpy.statistics import Identity
statistics_calculator = Identity(degree = 2, cross = False)
# define distance
from abcpy.distances import LogReg
distance_calculator = LogReg(statistics_calculator)
# define kernel
from abcpy.perturbationkernel import DefaultKernel
kernel = DefaultKernel([mu, sigma])
# define backend
# Note, the dummy backend does not parallelize the code!
from abcpy.backends import BackendDummy as Backend
backend = Backend()
# define sampling scheme
from abcpy.inferences import PMCABC
sampler = PMCABC([height], [distance_calculator], backend, kernel, seed=1)
# sample from scheme
T, n_sample, n_samples_per_param = 3, 250, 10
y_obs = [160.82499176, 167.24266737, 185.71695756, 153.7045709, 163.40568812, 140.70658699, 169.59102084, 172.81041696, 187.38782738, 179.66358934, 176.63417241, 189.16082803, 181.98288443, 170.18565017, 183.78493886, 166.58387299, 161.9521899, 155.69213073, 156.17867343, 144.51580379, 170.29847515, 197.96767899, 153.36646527, 162.22710198, 158.70012047, 178.53470703, 170.77697743, 164.31392633, 165.88595994, 177.38083686, 146.67058471763457, 179.41946565658628, 238.02751620619537, 206.22458790620766, 220.89530574344568, 221.04082532837026, 142.25301427453394, 261.37656571434275, 171.63761180867033, 210.28121820385866, 237.29130237612236, 175.75558340169619, 224.54340549862235, 197.42448680731226, 165.88273684581381, 166.55094082844519, 229.54308602661584, 222.99844054358519, 185.30223966014586, 152.69149367593846, 206.94372818527413, 256.35498655339154, 165.43140916577741, 250.19273595481803, 148.87781549665536, 223.05547559193792, 230.03418198709608, 146.13611923127021, 138.24716809523139, 179.26755740864527, 141.21704876815426, 170.89587081800852, 222.96391329259626, 188.27229523693822, 202.67075179617672, 211.75963110985992, 217.45423324370509]
# define prior
from abcpy.distributions import Uniform
prior = Uniform([150, 5],[200, 25])
# define the model
model = Gaussian(prior)
# define statistics
from abcpy.statistics import Identity
statistics_calculator = Identity(degree = 2, cross = False)
# define distance
from abcpy.distances import LogReg
distance_calculator = LogReg(statistics_calculator)
# define kernel
from abcpy.distributions import MultiStudentT
mean, cov, df = np.array([.0, .0]), np.eye(2), 3.
kernel = MultiStudentT(mean, cov, df)
# define backend
from abcpy.backends import BackendSpark as Backend
from abcpy.backends import BackendDummy as Backend
backend = Backend()
# define sampling scheme
from abcpy.inferences import PMCABC
sampler = PMCABC(model, distance_calculator, kernel, backend)
# sample from scheme