Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Dec 16, 2019
1 parent 3dd88fa commit f5b0134
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions app/grants/clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@


'''
Helper function that translates existing grant data structure to a list of lists.
Helper function that translates existing grant data structure
to a list of lists.
Args:
{
Expand All @@ -60,7 +61,9 @@ def translate_data(grants_data):


'''
Helper function that aggregates contributions by contributor, and then uses the aggregated contributors by contributor and calculates total contributions by unique pairs.
Helper function that aggregates contributions by contributor, and then
uses the aggregated contributors by contributor and calculates total
contributions by unique pairs.
Args:
from translate_data:
Expand Down Expand Up @@ -93,14 +96,15 @@ def aggregate_contributions(grant_contributions):


'''
Helper function that runs the pairwise clr formula while "binary" searching for the correct threshold.
Helper function that runs the pairwise clr formula while "binary"
searching for the correct threshold.
Args:
set variables:
lower_bound: set at 0.0
total_pot: set at 100000.0
from the helper function aggregate_contributions:
aggregated_contributions: {grant_id (str): {user_id (str): aggregated_amount (float)}}
pair_totals: {user_id (str): {user_id (str): pair_total (float)}}
Expand All @@ -109,16 +113,16 @@ def aggregate_contributions(grant_contributions):
bigtot: should equal total pot
totals: clr totals
'''
def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total_pot=100000.0):
def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total_pot=100000.0):
lower = lower_bound
upper = total_pot
iterations = 0
while iterations < 100:
threshold = (lower + upper) / 2
iterations += 1
if iterations == 100:
print("--- %s seconds ---" % (time.time() - start_time))
print(f'iterations reached, bigtot at {bigtot}')
# print("--- %s seconds ---" % (time.time() - start_time))
# print(f'iterations reached, bigtot at {bigtot}')
break
bigtot = 0
totals = []
Expand All @@ -128,24 +132,20 @@ def iter_threshold(aggregated_contributions, pair_totals, lower_bound=0.0, total
for k1, v1 in contribz.items():
for k2, v2 in contribz.items():
if k2 > k1: # remove pairs
# # pairwise matching formula
# tot += (v1 * v2) ** 0.5 * min(1, threshold / pair_totals[k1][k2])
# vitalik's division formula
tot += ((v1 * v2) ** 0.5) / (pair_totals[k1][k2] / threshold + 1)
bigtot += tot
# totals.append((proj, tot))
totals.append({'id': proj, 'clr_amount': tot})
# print(f'threshold {threshold} yields bigtot {bigtot} vs totalpot {total_pot} at iteration {iterations}')
if bigtot == total_pot:
print("--- %s seconds ---" % (time.time() - start_time))
print(f'bigtot {bigtot} = total_pot {total_pot} with threshold {threshold}')
print(totals)
# print("--- %s seconds ---" % (time.time() - start_time))
# print(f'bigtot {bigtot} = total_pot {total_pot} with threshold {threshold}')
# print(totals)
break
elif bigtot < total_pot:
lower = threshold
elif bigtot > total_pot:
upper = threshold
return bigtot, totals
return bigtot, totals


'''
Expand Down

0 comments on commit f5b0134

Please sign in to comment.