class TestOutputGaussian(unittest.TestCase): def setUp(self): nstates = 3 means = np.array([-0.5, 0.0, 0.5]) sigmas = np.array([0.2, 0.2, 0.2]) self.G = GaussianOutputModel(nstates, means=means, sigmas=sigmas) # random Gaussian samples self.obs = np.random.randn(10000) def tearDown(self): pass def test_p_obs(self): # compare results self.G.set_implementation('c') time1 = time.time() for i in range(10): p_c = self.G.p_obs(self.obs) time2 = time.time() t_c = time2 - time1 self.G.set_implementation('python') time1 = time.time() for i in range(10): p_p = self.G.p_obs(self.obs) time2 = time.time() t_p = time2 - time1 assert (np.allclose(p_c, p_p)) # speed report if print_speedup: print('p_obs speedup c/python = ' + str(t_p / t_c))
def __init__(self, nrep=10, kernel='c'): self.kernel = kernel self.nrep = nrep # variables self.nexamples = 0 self.A = [] self.pi = [] self.pobs = [] self.T = [] self.N = [] self.alpha = [] self.beta = [] self.gamma = [] self.time_alpha = [] self.time_beta = [] self.time_gamma = [] self.time_c = [] self.time_C = [] self.time_vpath = [] self.alpha_mem = [] self.beta_mem = [] self.gamma_mem = [] self.C_mem = [] # second example A = np.array([[0.97, 0.02, 0.01], [0.1, 0.8, 0.1], [0.01, 0.02, 0.97]]) pi = np.array([0.45, 0.1, 0.45]) T = 1000000 means = np.array([-1.0, 0.0, 1.0]) sigmas = np.array([0.5, 0.5, 0.5]) gom = GaussianOutputModel(3, means=means, sigmas=sigmas) obs = np.random.randint(3, size=T) pobs = gom.p_obs(obs) self.append_example(A, pi, pobs)
def setUp(self): self.nexamples = 0 self.A = [] self.pi = [] self.pobs = [] self.T = [] self.N = [] self.logprob = [] self.alpha = [] self.time_alpha = [] self.beta = [] self.time_beta = [] self.gamma = [] self.time_gamma = [] self.c = [] self.time_c = [] self.C = [] self.time_C = [] self.vpath = [] self.time_vpath = [] self.alpha_mem = [] self.beta_mem = [] self.gamma_mem = [] self.C_mem = [] # first toy example A = np.array([[0.9, 0.1], [0.1, 0.9]]) pi = np.array([0.5, 0.5]) pobs = np.array( [ [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.5, 0.5], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], ] ) self.append_example(A, pi, pobs) # second example A = np.array([[0.97, 0.02, 0.01], [0.1, 0.8, 0.1], [0.01, 0.02, 0.97]]) pi = np.array([0.45, 0.1, 0.45]) T = 10000 means = np.array([-1.0, 0.0, 1.0]) sigmas = np.array([0.5, 0.5, 0.5]) gom = GaussianOutputModel(3, means=means, sigmas=sigmas) obs = np.random.randint(3, size=T) pobs = gom.p_obs(obs) self.append_example(A, pi, pobs)
class TestOutputGaussian(unittest.TestCase): def setUp(self): nstates = 3 means = np.array([-0.5, 0.0, 0.5]) sigmas = np.array([0.2, 0.2, 0.2]) self.G = GaussianOutputModel(nstates, means=means, sigmas=sigmas) # random Gaussian samples self.obs = np.random.randn((10000)) def tearDown(self): pass def test_p_obs(self): # compare results self.G.set_implementation('c') time1 = time.time() for i in range(10): p_c = self.G.p_obs(self.obs) time2 = time.time() t_c = time2-time1 self.G.set_implementation('python') time1 = time.time() for i in range(10): p_p = self.G.p_obs(self.obs) time2 = time.time() t_p = time2-time1 assert(np.allclose(p_c, p_p)) # speed report if print_speedup: print('p_obs speedup c/python = '+str(t_p/t_c))
def setUp(self): self.nexamples = 0 self.A = [] self.pi = [] self.pobs = [] self.T = [] self.N = [] self.logprob = [] self.alpha = [] self.time_alpha = [] self.beta = [] self.time_beta = [] self.gamma = [] self.time_gamma = [] self.c = [] self.time_c = [] self.C = [] self.time_C = [] self.vpath = [] self.time_vpath = [] self.alpha_mem = [] self.beta_mem = [] self.gamma_mem = [] self.C_mem = [] # first toy example A = np.array([[0.9, 0.1], [0.1, 0.9]]) pi = np.array([0.5, 0.5]) pobs = np.array([[0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.1, 0.9], [0.5, 0.5], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1], [0.9, 0.1]]) self.append_example(A, pi, pobs) # second example A = np.array([[0.97, 0.02, 0.01], [0.1, 0.8, 0.1], [0.01, 0.02, 0.97]]) pi = np.array([0.45, 0.1, 0.45]) T = 10000 means = np.array([-1.0, 0.0, 1.0]) sigmas = np.array([0.5, 0.5, 0.5]) gom = GaussianOutputModel(3, means=means, sigmas=sigmas) obs = np.random.randint(3, size=T) pobs = gom.p_obs(obs) self.append_example(A, pi, pobs)
def __init__(self, nrep=10, kernel='c'): self.kernel = kernel self.nrep = nrep # variables self.nexamples = 0 self.A = [] self.pi = [] self.pobs = [] self.T = [] self.N = [] self.alpha = [] self.beta = [] self.gamma = [] self.time_alpha = [] self.time_beta = [] self.time_gamma = [] self.time_c = [] self.time_C = [] self.time_vpath = [] self.alpha_mem = [] self.beta_mem = [] self.gamma_mem = [] self.C_mem = [] # second example A = np.array([[0.97, 0.02, 0.01], [0.1, 0.8, 0.1], [0.01, 0.02, 0.97]]) pi = np.array([0.45, 0.1, 0.45]) T = 1000000 means = np.array([-1.0, 0.0, 1.0]) sigmas = np.array([0.5, 0.5, 0.5]) gom = GaussianOutputModel(3, means=means, sigmas=sigmas) obs = np.random.randint(3, size=T) pobs = gom.p_obs(obs) self.append_example(A, pi, pobs)