package commons.math.formulas;
public class TanomitoForcingStrongPairs implements Formula
{

/**
 * Implements a tanomito weighting formula. 
 * This weight weights a pair by the frequency of the terms
 * and the frequency of the combined occurence. 
 * INPUT: frequency (term_a), frequency (term_b), frequency(term_a, term_b) 
 * OUTPUT: value between 0..1, 1: words occur only pairwise, 0: no pairs of
 * a and b.
 */
public double calculate (double... arg)
{
   double result = 0D;
   double H_a = arg[0];
   double H_b = arg[1];
   double H_ab = arg[2];
   // w_a and w_b are normalized against the average term weight
   // so that 1 marks the average:
   double w_a = arg[3];
   double w_b = arg[4];
   // pure tanomito:
   result = H_ab / (H_a + H_b - H_ab);
   // calc average weighting of terms
   double w = (w_a + w_b) / 2;
   // calc difference of term weights:
   double e = Math.abs(w_a - w_b) + 1;
   // correct weighting, forcing equal weighted terms:
   double k = (w * w) / (e * e);
   // calc result:
   return result * k;
}
}
