<commit_before>import cvxpy

gamma = 100


def calculate(counts,vid_dict):
    n1 = 0.0
    n2 = 0.0
    a = 0.0
    c = 0.0
    for f1,f2,d in counts:
        f1f2 = max(f1+f2-1,0)
        f1nf2 = max(f1-f2,0)
        n1 += f1f2
        n2 += f1nf2
        if d[0]:
            a+= max(f1f2 + d[1] -1,0)
            c+= max(f1nf2 + d[1] -1,0)
        else:
            if f1f2==1:
                a+= vid_dict[d[1]] 
            else:
                a+= 0
            if f1nf2==1:
                c+= f1nf2 + vid_dict[d[1]] -1
            else:
                c+=0
    return a,c,n1,n2

def riskDifferenceObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(((n2/(n1*n2)*a-n1/(n1*n2)*c)))+cvxpy.pos(-((n2/(n1*n2)*a-n1/(n1*n2)*c)))

def riskRatioObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(n2*a-(1+epsilon)*c*n1) + cvxpy.pos((1-epsilon)*c*n1-n2*a)

def riskChanceObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(n1*n2-n2*a - (1+epsilon)*(n1*n2-n1*c)) + cvxpy.pos(((1-epsilon)*(n1*n2 -n1*c)+ n2*a-n1*n2))



def riskDifferenceConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append(((n2/(n1*n2)*a - n1/(n1*n2)*c))>0)
    constraints.append(((n2/(n1*n2)*a - n1/(n1*n2)*c))<0)
    return constraints



def riskRatioConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append((1-epsilon)*(n1*c)- n2*a>0)
    constraints.append((1+epsilon)*(n1*c)- n2*a <0)
    return constraints
    
    
    
def riskChanceConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append((1+epsilon)*(n1*n2-n1*c)-(n1*n2-n2*a)>0)
    constraints.append((1-epsilon)*(n1*n2-n1*c)-(n1*n2-n2*a)<0)
    return constraints
    
    
    
    
    
<commit_msg>fix fair constraints<commit_after>import cvxpy

gamma = 100


def calculate(counts,vid_dict):
    n1 = 0.0
    n2 = 0.0
    a = 0.0
    c = 0.0
    for f1,f2,d in counts:
        f1f2 = max(f1+f2-1,0)
        f1nf2 = max(f1-f2,0)
        n1 += f1f2
        n2 += f1nf2
        if d[0]:
            a+= max(f1f2 + d[1] -1,0)
            c+= max(f1nf2 + d[1] -1,0)
        else:
            if f1f2==1:
                a+= vid_dict[d[1]] 
            else:
                a+= 0
            if f1nf2==1:
                c+= f1nf2 + vid_dict[d[1]] -1
            else:
                c+=0
    return a,c,n1,n2

def riskDifferenceObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(((n2/(n1*n2)*a-n1/(n1*n2)*c)))+cvxpy.pos(-((n2/(n1*n2)*a-n1/(n1*n2)*c)))

def riskRatioObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(n2*a-(1+epsilon)*c*n1) + cvxpy.pos((1-epsilon)*c*n1-n2*a)

def riskChanceObjective(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    return gamma* cvxpy.pos(n1*n2-n2*a - (1+epsilon)*(n1*n2-n1*c)) + cvxpy.pos(((1-epsilon)*(n1*n2 -n1*c)+ n2*a-n1*n2))



def riskDifferenceConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append((n2*a-n1*c - n1*n2*epsilon) <=0)
    constraints.append((n2*a-n1*c + n1*n2*epsilon) >=0)
    return constraints



def riskRatioConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append(n2*a - (1+epsilon)*(n1*c) <=0)
    constraints.append(n2*a - (1-epsilon)*(n1*c) >=0)
    return constraints
    
    
    
def riskChanceConstraints(counts,vid_dict,epsilon):
    a,c,n1,n2 = calculate(counts,vid_dict)
    constraints = []
    constraints.append(-n2*a+ (1+epsilon)*n1*c - epsilon*n1*n2 <=0)
    constraints.append(-n2*a+ (1-epsilon)*n1*c + epsilon*n1*n2 >=0)
    return constraints
    
    
    
    
    

{'fraction_non_alphanumeric': 0.1772591857000993, 'fraction_numerical': 0.06752730883813307, 'mean_word_length': 2.703125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5346541', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1780, 'n_words': 235}