def f_measure(reference, test, alpha=0.5):
 p = precision(reference, test)
 r = recall(reference, test)
 if ((p is None) or (r is None)):
  return None
 if ((p == 0) or (r == 0)):
  return 0
 return (1.0 / ((alpha / p) + ((1 - alpha) / r)))

def f_measure ( reference , test , alpha = 0.5 ) : p = precision ( reference , test ) r = recall ( reference , test ) if ( ( p is None ) or ( r is None ) ) : return None if ( ( p == 0 ) or ( r == 0 ) ) : return 0 return ( 1.0 / ( ( alpha / p ) + ( ( 1 - alpha ) / r ) ) )
given a set of reference values and a set of test values .