def testLoads(self): # test initiating from multiple chain arrays samps = [] for i in range(3): samps.append(Gaussian2D([1.5, -2], np.diagflat([1, 2])).MCSamples(1001 + i * 10, names=['x', 'y'])) fromChains = MCSamples(samples=[s.samples for s in samps], names=['x', 'y']) mean = np.sum([s.norm * s.mean('x') for s in samps]) / np.sum([s.norm for s in samps]) meanChains = fromChains.mean('x') self.assertAlmostEqual(mean, meanChains)
def testDensitySymmetries(self): # check flipping samples gives flipped density samps = Gaussian1D(0, 1, xmin=-1, xmax=4).MCSamples(12000) d = samps.get1DDensity('x') samps.samples[:, 0] *= -1 samps = MCSamples(samples=samps.samples, names=['x'], ranges={'x': [-4, 1]}) d2 = samps.get1DDensity('x') self.assertTrue(np.allclose(d.P, d2.P[::-1])) samps = Gaussian2D([0, 0], np.diagflat([1, 2]), xmin=-1, xmax=2, ymin=0, ymax=3).MCSamples(12000) d = samps.get2DDensity('x', 'y') samps.samples[:, 0] *= -1 samps = MCSamples(samples=samps.samples, names=['x', 'y'], ranges={'x': [-2, 1], 'y': [0, 3]}) d2 = samps.get2DDensity('x', 'y') self.assertTrue(np.allclose(d.P, d2.P[:, ::-1])) samps.samples[:, 0] *= -1 samps.samples[:, 1] *= -1 samps = MCSamples(samples=samps.samples, names=['x', 'y'], ranges={'x': [-1, 2], 'y': [-3, 0]}) d2 = samps.get2DDensity('x', 'y') self.assertTrue(np.allclose(d.P, d2.P[::-1, ::], atol=1e-5))