def calculate_auc(fprates, tprates):
    """ Calculate the AUC of given ROC curve (defined by vectors of FPR and TPR) """
    curr_fprate = fprates[0]
    curr_tprate = tprates[0]
    area = 0
    for index in range( 1, len(fprates) ):
       next_fprate = fprates[index]
       next_tprate = tprates[index]
       x_delta = next_fprate - curr_fprate
       y_mean = (curr_tprate + next_tprate)/2
       area = area + (x_delta*y_mean)
       curr_fprate = fprates[index]
       curr_tprate = tprates[index]
    return area