class LogRegTests(unittest.TestCase): def setUp(self): self.stat_calc = Identity(degree=2, cross=False) self.distancefunc = LogReg(self.stat_calc, seed=1) self.rng = np.random.RandomState(1) def test_distance(self): d1 = 0.5 * self.rng.randn(100, 2) - 10 d2 = 0.5 * self.rng.randn(100, 2) + 10 d1 = d1.tolist() d2 = d2.tolist() # Checks whether wrong input type produces error message self.assertRaises(TypeError, self.distancefunc.distance, 3.4, d2) self.assertRaises(TypeError, self.distancefunc.distance, d1, 3.4) # completely separable datasets should have a distance of 1.0 self.assertEqual(self.distancefunc.distance(d1, d2), 1.0) # equal data sets should have a distance of 0.0 self.assertEqual(self.distancefunc.distance(d1, d1), 0.0) def test_dist_max(self): self.assertTrue(self.distancefunc.dist_max() == 1.0)
class LogRegTests(unittest.TestCase): def setUp(self): self.stat_calc = Identity(degree = 1, cross = 0) self.distancefunc = LogReg(self.stat_calc) def test_distance(self): d1 = 0.5 * np.random.randn(100,2) - 10 d2 = 0.5 * np.random.randn(100,2) + 10 #Checks whether wrong input type produces error message self.assertRaises(TypeError, self.distancefunc.distance, 3.4, d2) self.assertRaises(TypeError, self.distancefunc.distance, d1, 3.4) # completely separable datasets should have a distance of 1.0 self.assertEqual(self.distancefunc.distance(list(d1),list(d2)), 1.0) # equal data sets should have a distance of 0.0 self.assertEqual(self.distancefunc.distance(list(d1),list(d1)), 0.0) def test_dist_max(self): self.assertTrue(self.distancefunc.dist_max() == 1.0)
distance_calculator = Euclidean(statistics_calculator) distance_calculator2 = Wasserstein(statistics_calculator) distance_calculator3 = LogReg(statistics_calculator) # checking sim_data = hh_simulator.forward_simulate( [gbar_K_true + 3, gbar_Na_true + 4]) #obs_data = [obs_data[0] / np.max(obs_data[0]) + noise] #sim_data = [sim_data[0] / np.max(sim_data[0])] s1 = statistics_calculator.statistics(obs_data) s2 = statistics_calculator.statistics(sim_data) dist = distance_calculator.distance(obs_data, sim_data) dist2 = distance_calculator2.distance(obs_data, sim_data) dist3 = distance_calculator3.distance(obs_data, sim_data) print(s1) print(s2) print(dist) print(dist2) print(dist3) # plt.plot(t, obs_data[0] / np.max(obs_data[0]), label='obs') # plt.plot(t, sim_data[0] / np.max(sim_data[0]), label='sim') plt.plot(t, obs_data[0], label='obs') plt.plot(t, sim_data[0], label='sim') plt.legend() plt.show() ''' # inference scheme sampler = RejectionABC(