Răsfoiți Sursa

[research/lotterysim] headstart, remove airdrop

ertosns 3 ani în urmă
părinte
comite
d7f477e4f9

+ 39 - 0
script/research/lotterysim/acc_vs_staked_ratio_pi_headstart.py

@@ -0,0 +1,39 @@
+from core.lottery import *
+import os
+import numpy
+from matplotlib import pyplot as plt
+
+os.system("rm log/f_output.hist; rm log/f_feedback.hist")
+
+RUNNING_TIME = int(input("running time:"))
+ERC20DRK=2.1*10**9
+NODES=1000
+plot = []
+EXPS=10
+for nodes in numpy.concatenate((numpy.array([1,5]), numpy.linspace(10,NODES, 10))):
+    accs = []
+    for _ in range(EXPS):
+        darkies = []
+        egalitarian = ERC20DRK/NODES
+        darkies += [ Darkie(random.gauss(0, 0), strategy=random_strategy(EPOCH_LENGTH)) for id in range(int(nodes)) ]
+        airdrop = ERC20DRK
+        dt = DarkfiTable(0, RUNNING_TIME, CONTROLLER_TYPE_DISCRETE, kp=-0.0104, ki=-0.0366, kd=0.0384,  r_kp=-2.53, r_ki=29.5, r_kd=53.77)
+        for darkie in darkies:
+            dt.add_darkie(darkie)
+        acc, apy, reward, staked_ratio, apr = dt.background(rand_running_time=False)
+        accs += [acc]
+        effective_airdrop  = 0
+        for darkie in darkies:
+            effective_airdrop+=darkie.stake
+        effective_airdrop*=float(staked_ratio)
+        stake_portion = effective_airdrop/airdrop*100
+        print("network airdrop: {}, staked token: {}/{}% on {} nodes".format(airdrop, effective_airdrop, stake_portion, len(darkies)))
+    avg_acc = sum(accs)/EXPS
+    plot+=[(stake_portion, avg_acc)]
+
+
+plt.plot([x[0] for x in plot], [x[1] for x in plot])
+plt.xlabel('drk staked %')
+plt.ylabel('accuracy %')
+plt.savefig('img'+os.sep+'stake_pi.png')
+plt.show()

+ 3 - 0
script/research/lotterysim/core/constants.py

@@ -35,3 +35,6 @@ REWARD_MIN_HP = Num(REWARD_MIN)
 REWARD_MAX_HP = Num(REWARD_MAX)
 
 ACC_WINDOW = 100
+
+BASE_L = 0.001*L
+BASE_L_HP = Num(BASE_L)

+ 1 - 1
script/research/lotterysim/core/darkie.py

@@ -65,7 +65,7 @@ class Darkie():
             x = (Num(1) if hp else 1)  - (Num(tune_parameter) if hp else tune_parameter)
             c = (x.ln() if type(x)==Num else math.log(x))
             sigmas = [   c/((self.Sigma+EPSILON)**i) * ( ((L_HP if hp else L)/fact(i)) ) for i in range(1, k+1) ]
-            scaled_target = approx_target_in_zk(sigmas, Num(stake)) #+ (BASE_L_HP if hp else BASE_L)
+            scaled_target = approx_target_in_zk(sigmas, Num(stake)) + (BASE_L_HP if hp else BASE_L)
             return scaled_target
 
         if self.slot % EPOCH_LENGTH ==0 and self.slot > 0:

+ 44 - 0
script/research/lotterysim/discrete_instance_pi_headstart.py

@@ -0,0 +1,44 @@
+import os
+import numpy
+from core.strategy import *
+from core.lottery import *
+import matplotlib.pyplot as plt
+import scipy.stats as stats
+import math
+from draw import draw
+
+os.system("rm log/*_feedback.hist; rm log/*_output.hist")
+
+RUNNING_TIME = int(input("running time:"))
+NODES=1000
+
+if __name__ == "__main__":
+    darkies = [Darkie(0, strategy=LinearStrategy(EPOCH_LENGTH)) for _ in range(NODES)]
+    dt = DarkfiTable(0, RUNNING_TIME, CONTROLLER_TYPE_DISCRETE, kp=-0.010399999999938556, ki=-0.0365999996461878, kd=0,  r_kp=-0.63, r_ki=3.35, r_kd=0)
+    for darkie in darkies:
+        dt.add_darkie(darkie)
+    acc, avg_apy, avg_reward, stake_ratio, avg_apr = dt.background(rand_running_time=False)
+    sum_zero_stake = sum([darkie.stake for darkie in darkies[NODES:]])
+    print('acc: {}, avg(apr): {}, avg(reward): {}, stake_ratio: {}'.format(acc, avg_apr, avg_reward, stake_ratio))
+    print('total stake of 0mint: {}, ratio: {}'.format(sum_zero_stake, sum_zero_stake/ERC20DRK))
+    dt.write()
+    aprs = []
+    fortuners = 0.0
+    for darkie in darkies:
+        aprs += [float(darkie.apr_scaled_to_runningtime())]
+        if darkie.initial_stake[-1] - darkie.initial_stake[0] > 0:
+            fortuners+=1
+
+    print('fortuners: {}'.format(str(fortuners/len(darkies))))
+    # distribution of aprs
+    aprs = sorted(aprs)
+    mu = float(sum(aprs)/len(aprs))
+    shifted_aprs = [apr - mu for apr in aprs]
+    plt.plot([apr*100 for apr in aprs])
+    plt.title('annual percentage return, avg: {:}'.format(mu*100))
+    plt.savefig('img/apr_distribution.png')
+    plt.show()
+
+    variance = sum(shifted_aprs)/(len(aprs)-1)
+    print('mu: {}, variance: {}'.format(str(mu), str(variance)))
+    draw()

BIN
script/research/lotterysim/img/apr_distribution.png


BIN
script/research/lotterysim/img/feedback_history_processed.png


BIN
script/research/lotterysim/img/output_history_processed.png


BIN
script/research/lotterysim/img/stake_pi.png