def _log_likelihood_triplet(self, counts_triplet, theta_triplet, alpha, beta): """Compute the log likelihood of data for one triplet of annotators. Input: counts_triplet -- count data for one combination of annotators theta_triplet -- theta parameters of the current triplet """ nclasses = self.nclasses llhood = 0. # loop over all possible agreement patterns # 0=aaa, 1=aaA, 2=aAa, 3=Aaa, 4=Aa@ pattern_to_indices = _compatibility_tables(nclasses) for pattern in range(5): # P( A_ijk | T_ijk ) * P( T_ijk ) , or "alpha * theta triplet" prob = self._prob_a_and_t(pattern, theta_triplet, alpha) # P( V_ijk ! A_ijk) * P( A_ijk | T_ijk ) * P( T_ijk ) # = P( V_ijk | A, T, model) prob *= beta[pattern] # P( V_ijk | model ) = sum over A and T of conditional probability indices = pattern_to_indices[pattern] count_indices = _triplet_to_counts_index(indices, nclasses) log_prob = ninf_to_num(np.log(prob)) llhood += (counts_triplet[count_indices] * log_prob).sum() return llhood
def _log_likelihood_triplet(self, counts_triplet, theta_triplet): """Compute the log likelihood of data for one triplet of annotators. Input: counts_triplet -- count data for one combination of annotators theta_triplet -- theta parameters of the current triplet """ # log \prod_n P(v_{ijk}^{n} | params) # = \sum_n log P(v_{ijk}^{n} | params) # = \sum_v_{ijk} count(v_{ijk}) log P( v_{ijk} | params ) # # where n is n-th annotation of triplet {ijk}] # compute P( v_{ijk} | params ) pf = self._pattern_frequencies(theta_triplet) log_pf = ninf_to_num(np.log(pf)) l = (counts_triplet * log_pf).sum() return l