def test_model_hawkes_least_sq_multiple_events(self): """...Test that multiple events list for ModelHawkesFixedExpKernLeastSq is consistent with direct integral estimation """ # precision of the integral approximation (and the corresponding # tolerance) precison = 1 end_times = np.array([max(map(max, e)) for e in self.timestamps_list]) end_times += 1. self.model_list.fit(self.timestamps_list, end_times=end_times) intensities_list = [ hawkes_sumexp_kernel_intensities(self.baseline, self.decays, self.adjacency, timestamps) for timestamps in self.timestamps_list ] integral_approx = sum([ hawkes_least_square_error(intensities, timestamps, end_time, precision=precison) for (intensities, timestamps, end_time) in zip(intensities_list, self.timestamps_list, self.model_list.end_times) ]) integral_approx /= self.model_list.n_jumps self.assertAlmostEqual(integral_approx, self.model_list.loss(self.coeffs), places=precison)
def test_model_hawkes_loglik_multiple_events(self): """...Test that multiple events list for ModelHawkesFixedSumExpKernLogLik is consistent with direct integral estimation """ end_times = np.array([max(map(max, e)) for e in self.timestamps_list]) end_times += 1. self.model_list.fit(self.timestamps_list, end_times=end_times) intensities_list = [ hawkes_sumexp_kernel_intensities(self.baseline, self.decays, self.adjacency, timestamps) for timestamps in self.timestamps_list ] integral_approx = sum([ hawkes_log_likelihood(intensities, timestamps, end_time) for (intensities, timestamps, end_time) in zip(intensities_list, self.timestamps_list, self.model_list.end_times) ]) integral_approx /= self.model_list.n_jumps self.assertAlmostEqual(integral_approx, -self.model_list.loss(self.coeffs), places=2)
def test_model_hawkes_sum_exp_kernel_least_sq_loss(self): """...Test that computed losses are consistent with approximated theoretical values """ timestamps = self.timestamps_list[self.realization] intensities = hawkes_sumexp_kernel_intensities( self.baseline, self.decays, self.adjacency, timestamps) integral_approx = hawkes_least_square_error( intensities, timestamps, self.model.end_times[self.realization]) integral_approx /= self.model.n_jumps self.assertAlmostEqual(integral_approx, self.model.loss(self.coeffs), places=2)
def test_model_hawkes_losses(self): """...Test that computed losses are consistent with approximated theoretical values """ timestamps = self.timestamps_list[self.realization] intensities = hawkes_sumexp_kernel_intensities(self.baseline, self.decays, self.adjacency, timestamps) precision = 3 integral_approx = hawkes_log_likelihood(intensities, timestamps, self.end_time, precision=precision) integral_approx /= self.model.n_jumps self.assertAlmostEqual(integral_approx, -self.model.loss(self.coeffs), places=precision)