Exemple #1
0
static double binary_dice_coefficient(const double *vec1, const double *vec2,
                                      size_t veclen)
{
    if (!vec1 && !vec2)
        return 1.0 ;
    else if (!vec1 || !vec2)
        return (veclen == 0) ? 1.0 : 0.0 ; // no overlap, but same if zero-length
    size_t only_1, only_2, intersection, neither ;
    term_matches(vec1,vec2,veclen,intersection,neither,only_1,only_2) ;
    size_t total_1(only_1 + intersection) ;
    size_t total_2(only_2 + intersection) ;
    return (2.0 * intersection) / (double)(total_1 + total_2) ;
}
Exemple #2
0
void SoftMatching::propagate_21 ()
{
  total_2();

  for (size_t ij = 0; ij < size_arc(); ++ij) {
    Arc arc = m_arcs[ij];

    float projected = likelihood_ratio(m_post_2_ass[ij], m_total[arc.j]);
    m_message[ij] = safe(projected / (m_message[ij] * m_prior_2_ass[ij]));
    m_prior_2_ass[ij] = projected;

    float lifted = m_message[ij] * m_scale_1[arc.i];
    m_post_1_ass[ij] = safe(m_post_1_ass[ij] * lifted);

    ASSERT1_PROB(m_message[ij]);
    ASSERT1_PROB(m_prior_2_ass[ij]);
    ASSERT1_PROB(m_post_1_ass[ij]);
  }
}
Exemple #3
0
void SoftMatching::normalize ()
{
  total_1();

  for (size_t i = 0; i < size_1(); ++i) {
    m_total[i] = 1 / m_total[i];
    m_post_1_non[i] = 1;
  }
  for (size_t ij = 0; ij < size_arc(); ++ij) {
    Arc arc = m_arcs[ij];
    m_post_1_ass[ij] *= m_total[arc.i];
  }

  total_2();

  for (size_t j = 0; j < size_2(); ++j) {
    m_total[j] = 1 / m_total[j];
    m_post_2_non[j] = 1;
  }
  for (size_t ij = 0; ij < size_arc(); ++ij) {
    Arc arc = m_arcs[ij];
    m_post_2_ass[ij] *= m_total[arc.j];

    float prob = min(m_post_1_ass[ij], m_post_2_ass[ij]);

    m_post_1_ass[ij] = prob;
    m_post_1_non[arc.i] -= prob;
    m_post_2_non[arc.j] -= prob;
  }

  for (size_t i = 0; i < size_1(); ++i) {
    clamp_nonneg(m_post_1_non[i]);
  }
  for (size_t j = 0; j < size_2(); ++j) {
    clamp_nonneg(m_post_2_non[j]);
  }
}