def _resample_A_given_W(self, data):
        """
        Resample A given W. This must be immediately followed by an
        update of z | A, W.
        :return:
        """
        # Precompute weightedi impulse responses for each event
        lmbda_irs = [self._compute_weighted_impulses_at_events(d) for d in data]

        # lmbda_irs_manual = [self._compute_weighted_impulses_at_events_manual(d) for d in data]
        # for l1,l2 in zip(lmbda_irs_manual, lmbda_irs):
        #     assert np.allclose(l1,l2)

        lmbda0 = self.model.lambda0

        def _log_likelihood_single_process(k):
            ll = 0
            for lmbda_ir, d in zip(lmbda_irs, data):
                Ns, C, T = d.Ns, d.C, d.T

                # - \int lambda_k(t) dt
                ll -= lmbda0[k] * T
                ll -= self.W_effective[:,k].dot(Ns)

                # + \sum_n log(lambda(s_n))
                ll += np.log(lmbda0[k] + np.sum(self.A[:,k] * lmbda_ir[C==k,:], axis=1)).sum()
            return ll

        # TODO: Write a Cython function to sample this more efficiently
        p = self.network.P
        for k1 in xrange(self.K):
            # sys.stdout.write('.')
            # sys.stdout.flush()
            for k2 in xrange(self.K):
                # Handle deterministic cases
                if p[k1,k2] == 0.:
                    self.A[k1,k2] = 0
                    continue

                if p[k1,k2] == 1.:
                    self.A[k1,k2] = 1
                    continue

                # Compute the log likelihood of the events given W and A=0
                self.A[k1,k2] = 0
                ll0 = _log_likelihood_single_process(k2)

                # Compute the log likelihood of the events given W and A=1
                self.A[k1,k2] = 1
                ll1 = _log_likelihood_single_process(k2)

                # Sample A given conditional probability
                lp0 = ll0 + np.log(1.0 - p[k1,k2])
                lp1 = ll1 + np.log(p[k1,k2])
                Z   = logsumexp([lp0, lp1])

                self.A[k1,k2] = np.log(np.random.rand()) < Z - lp1

        # sys.stdout.write('\n')
        # sys.stdout.flush()
dataset/ETHPy150Open slinderman/pyhawkes/pyhawkes/internals/weights.py/SpikeAndSlabContinuousTimeGammaWeights._resample_A_given_W/swapped operands of `-`