def _compute_log_likelihood(self, obs): """Compute the log likelihood of each observation in each state Parameters ---------- obs : np.array, shape (`n_samples`, `n_features`) Returns ------- logl : np.array, shape (`n_samples`, `n_components`) """ return _vmhmm._compute_log_likelihood(obs, self._means_, self._kappas_)
def _compute_log_likelihood(self, obs): """Compute the log likelihood of each observation in each state Parameters ---------- obs : np.array, shape (`n_samples`, `n_features`) Returns ------- logl : np.array, shape (`n_samples`, `n_components`) """ return _vmhmm._compute_log_likelihood(obs, self._means_, self._kappas_)
def test_log_likelihood(): n_samples, n_states, n_features = 1000, 27, 16 obs = np.random.rand(n_samples, n_features) vm = VonMisesHMM(n_states=n_states) vm.fit([obs]) t0 = time.time() from scipy.stats.distributions import vonmises reference = np.array([np.sum(vonmises.logpdf(obs, vm.kappas_[i], vm.means_[i]), axis=1) for i in range(n_states)]).T t1 = time.time() value = _vmhmm._compute_log_likelihood(obs, vm.means_, vm.kappas_) t2 = time.time() print("Log likeihood timings") print('reference time ', t1-t0) print('c time ', t2-t1) np.testing.assert_array_almost_equal(reference, value)
def test_log_likelihood(): n_samples, n_states, n_features = 1000, 27, 16 obs = np.random.rand(n_samples, n_features) vm = VonMisesHMM(n_states=n_states) vm.fit([obs]) t0 = time.time() from scipy.stats.distributions import vonmises reference = np.array([ np.sum(vonmises.logpdf(obs, vm.kappas_[i], vm.means_[i]), axis=1) for i in range(n_states) ]).T t1 = time.time() value = _vmhmm._compute_log_likelihood(obs, vm.means_, vm.kappas_) t2 = time.time() print("Log likeihood timings") print('reference time ', t1 - t0) print('c time ', t2 - t1) np.testing.assert_array_almost_equal(reference, value)