def test_vonmises_logpdf(T=100, K=4, D=10): # Test single datapoint log pdf x = npr.vonmises(0, 1, size=(T, D)) mus = npr.randn(K, D) kappas = np.exp(npr.randn(K, D)) ll1 = vonmises_logpdf(x[:, None, :], mus, kappas) ll2 = np.sum(vonmises.logpdf(x[:, None, :], kappas[None, :, :], loc=mus[None, :, :]), axis=-1) assert np.allclose(ll1, ll2)
def sample_x(self, z, xhist, input=None, tag=None, with_noise=True): D, mus, kappas = self.D, self.mus, np.exp(self.log_kappas) assert self.D == 1, "InputDrivenObservations written for D = 1!" if input.ndim == 1 and input.shape == ( self.M, ): # if input is vector of size self.M (one time point), expand dims to be (1, M) input = np.expand_dims(input, axis=0) ### driven_angle = mus @ input.T kappas_t = np.repeat(kappas[:, :, None], input.T.shape[-1], axis=2) #time-independent return npr.vonmises(driven_angle[z], kappas_t[z]) #, D)
def test_vonmises_logpdf(T=100, K=4, D=10): """ NOTE: Skipping this test until the scipy special functions make it into the release version of autograd. """ # Test single datapoint log pdf x = npr.vonmises(0, 1, size=(T, D)) mus = npr.randn(K, D) kappas = np.exp(npr.randn(K, D)) ll1 = vonmises_logpdf(x[:, None, :], mus, kappas) ll2 = np.sum(vonmises.logpdf(x[:, None, :], kappas[None, :, :], loc=mus[None, :, :]), axis=-1) assert np.allclose(ll1, ll2)
def sample_x(self, z, xhist, input=None, tag=None, with_noise=True): D, mus, kappas = self.D, self.mus, np.exp(self.log_kappas) return npr.vonmises(self.mus[z], kappas[z], D)