Exemplo n.º 1
0
def compute(data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data))
    [x.assert_eq(y) for (x,y) in zip(hashed_data, correct_hash)]

    # Compute graduation rates by category
    output = {}
    for category in data:
        arr2011 = [x == 1 for x in data[category]]
        arr2013 = [x == 11 for x in data[category]]
        
        graduated2011 = LinCombFxp(sum(arr2011))
        graduated2013 = LinCombFxp(sum(arr2013))
        length2011 = PrivVal(len(arr2011))
        length2013 = PrivVal(len(arr2013))

        gr2011 = graduated2011 * 100 / (length2011 + (length2011 == 0))
        gr2013 = graduated2013 * 100 / (length2013 + (length2013 == 0))

        output[category] = {
            "Began in 2011": gr2011,
            "Began in 2013": gr2013
        }

    # # Assert results are correct
    for category in results:
        output[category]["Began in 2011"].assert_eq(results[category]["Began in 2011"])
        output[category]["Began in 2013"].assert_eq(results[category]["Began in 2013"])
Exemplo n.º 2
0
def compute(data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data))
    [x.assert_eq(y) for (x, y) in zip(hashed_data, correct_hash)]

    # Compute outputs
    output = {}
    for category in data:
        num_pell = sum([i >= 10 for i in data[category]])
        num_non_pell = sum([i < 10 for i in data[category]])
        num_all = num_pell + num_non_pell

        received_bachelors_pell = LinCombFxp(
            sum([i == 11 for i in data[category]]))
        different_institution_pell = LinCombFxp(
            sum([i == 12 for i in data[category]]))
        same_institution_pell = LinCombFxp(
            sum([i == 13 for i in data[category]]))

        received_bachelors_non_pell = LinCombFxp(
            sum([i == 1 for i in data[category]]))
        different_institution_non_pell = LinCombFxp(
            sum([i == 2 for i in data[category]]))
        same_institution_non_pell = LinCombFxp(
            sum([i == 3 for i in data[category]]))

        output[category] = {
            "Pell": {
                "Received Bachelor's":
                received_bachelors_pell / num_pell,
                "Enrolled at same institution":
                same_institution_pell / num_pell,
                "Enrolled at different insitution":
                different_institution_pell / num_pell
            },
            "No Pell": {
                "Received Bachelor's":
                received_bachelors_non_pell / num_non_pell,
                "Enrolled at same institution":
                same_institution_non_pell / num_non_pell,
                "Enrolled at different insitution":
                different_institution_non_pell / num_non_pell
            },
            "All Students": {
                "Received Bachelor's":
                (received_bachelors_pell + received_bachelors_non_pell) /
                num_all,
                "Enrolled at same institution":
                (same_institution_pell + same_institution_non_pell) / num_all,
                "Enrolled at different insitution":
                (different_institution_pell + different_institution_non_pell) /
                num_all
            }
        }

    for category in results:
        for student_type in results[category]:
            for outcome in results[category][student_type]:
                output[category][student_type][outcome].assert_eq(
                    results[category][student_type][outcome])
Exemplo n.º 3
0
def compute(data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data))
    [x.assert_eq(y) for (x, y) in zip(hashed_data, correct_hash)]

    # Compute GPA
    total = sum(data)
    num_students = PrivVal(len(data))
    gpa = total / num_students

    # Assert GPAs match
    gpa.assert_eq(results)
Exemplo n.º 4
0
def compute(data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data))
    [x.assert_eq(y) for (x, y) in zip(hashed_data, correct_hash)]

    #  Begin with just 2016-2017
    output = {}
    for year in data:
        output[year] = {}
        for income in data[year]:
            year_data = data[year][income]
            total = sum(year_data)
            length = PrivVal(len(year_data))
            output[year][income] = total / length

    # Check equality
    for year in results:
        for income in results[year]:
            output[year][income].assert_eq(results[year][income])
Exemplo n.º 5
0
def compute(data, lfa_data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data + lfa_data))
    [x.assert_eq(y) for (x, y) in zip(hashed_data, correct_hash)]

    # Compute pre-LFA data
    output = {"Pre-COVID": {}, "Post-COVID": {}}

    num_students = PrivVal(len(data))

    only_distance = LinCombFxp(sum([i == 1 for i in data]))
    some_distance = LinCombFxp(sum([i == 2 for i in data]))
    no_distance = LinCombFxp(sum([i == 3 for i in data]))

    output["Pre-COVID"] = {
        "Only Distance Education": only_distance / num_students,
        "Some Distance": some_distance / num_students,
        "No Distance": no_distance / num_students
    }

    num_lfa_students = PrivVal(len(data))

    lfa_only_distance = LinCombFxp(sum([i == 1 for i in lfa_data]))
    lfa_some_distance = LinCombFxp(sum([i == 2 for i in lfa_data]))
    lfa_no_distance = LinCombFxp(sum([i == 3 for i in lfa_data]))

    output["Post-COVID"] = {
        "Only Distance Education": lfa_only_distance / num_lfa_students,
        "Some Distance": lfa_some_distance / num_lfa_students,
        "No Distance": lfa_no_distance / num_lfa_students
    }

    for time_period in results:
        for distance_status in results[time_period]:
            output[time_period][distance_status].assert_eq(
                results[time_period][distance_status])
Exemplo n.º 6
0
def compute(data, results, correct_hash):
    # Compute commitment
    hashed_data = poseidon_hash(flatten(data))
    [x.assert_eq(y) for (x, y) in zip(hashed_data, correct_hash)]

    # Compute percentage per category
    total_cases = len(data)

    data = {
        "0-19": LinCombFxp(sum([(0 <= x) & (x <= 19) for x in data])),
        "20-29": LinCombFxp(sum([(20 <= x) & (x <= 29) for x in data])),
        "30-39": LinCombFxp(sum([(30 <= x) & (x <= 39) for x in data])),
        "40-49": LinCombFxp(sum([(40 <= x) & (x <= 49) for x in data])),
        "50-59": LinCombFxp(sum([(50 <= x) & (x <= 59) for x in data])),
        "60-69": LinCombFxp(sum([(60 <= x) & (x <= 69) for x in data])),
        "70-79": LinCombFxp(sum([(70 <= x) & (x <= 79) for x in data])),
        "80+": LinCombFxp(sum([80 <= x for x in data]))
    }

    percentage_per_category = {x: data[x] / total_cases for x in data}

    # Check output
    for x in data:
        percentage_per_category[x].assert_eq(results[x])
Exemplo n.º 7
0
 def test_int(self):
     from pysnark.poseidon_hash import poseidon_hash
     with pytest.raises(RuntimeError):
         output = poseidon_hash([PrivVal(0), PrivVal(1), PrivVal(2), PrivVal(3), 4])
Exemplo n.º 8
0
 def test_lincombbool(self):
     from pysnark.poseidon_hash import poseidon_hash
     poseidon_hash([PrivValBool(0), PrivValBool(1), PrivValBool(0), PrivValBool(1), PrivValBool(0)])