Explorar o código

[research/lotterysim] update vesting before run, typo in random_strategy routine

police %!s(int64=3) %!d(string=hai) anos
pai
achega
7769cf0710

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

@@ -72,7 +72,7 @@ class Darkie():
     def update_vesting(self):
     def update_vesting(self):
         if self.slot >= len(self.vesting):
         if self.slot >= len(self.vesting):
             return 0
             return 0
-        slot2vest_index = int(self.slot/28800.0)
+        slot2vest_index = int(self.slot/28800.0) #slot to month conversion
         slot2vest_prev_index = int((self.slot-1)/28800.0)
         slot2vest_prev_index = int((self.slot-1)/28800.0)
         slot2vest_index_shifted = slot2vest_index - 1 # by end of month
         slot2vest_index_shifted = slot2vest_index - 1 # by end of month
         slot2vest_prev_index_shifted = slot2vest_prev_index - 1 # by end of month
         slot2vest_prev_index_shifted = slot2vest_prev_index - 1 # by end of month

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

@@ -47,8 +47,8 @@ class DarkfiTable:
             #note! thread overhead is 10X slower than sequential node execution!
             #note! thread overhead is 10X slower than sequential node execution!
             for i in range(len(self.darkies)):
             for i in range(len(self.darkies)):
                 self.darkies[i].set_sigma_feedback(self.Sigma, feedback, f, count, hp)
                 self.darkies[i].set_sigma_feedback(self.Sigma, feedback, f, count, hp)
-                self.darkies[i].run(hp)
                 total_vesting_stake+=self.darkies[i].update_vesting()
                 total_vesting_stake+=self.darkies[i].update_vesting()
+                self.darkies[i].run(hp)
 
 
 
 
             #print('reward: {}'.format(rewards[-1]))
             #print('reward: {}'.format(rewards[-1]))

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

@@ -79,7 +79,7 @@ def random_strategy(epoch_length):
     if rnd < 0.25:
     if rnd < 0.25:
         return Hodler(epoch_length)
         return Hodler(epoch_length)
     elif rnd < 0.5 and rnd >= 0.25:
     elif rnd < 0.5 and rnd >= 0.25:
-        #return LinearStrategy(epoch_length)
+        return LinearStrategy(epoch_length)
     elif rnd < 0.75 and rnd >= 0.5:
     elif rnd < 0.75 and rnd >= 0.5:
         return LogarithmicStrategy(epoch_length)
         return LogarithmicStrategy(epoch_length)
     else:
     else:

+ 1 - 0
script/research/lotterysim/discrete_instance.py

@@ -14,6 +14,7 @@ NODES=100
 if __name__ == "__main__":
 if __name__ == "__main__":
     egalitarian = ERC20DRK/NODES
     egalitarian = ERC20DRK/NODES
     darkies = []
     darkies = []
+
     for id in range(int(NODES)):
     for id in range(int(NODES)):
         darkie = Darkie(random.gauss(egalitarian, egalitarian*0.1), strategy=random_strategy(EPOCH_LENGTH))
         darkie = Darkie(random.gauss(egalitarian, egalitarian*0.1), strategy=random_strategy(EPOCH_LENGTH))
         darkies += [darkie]
         darkies += [darkie]

+ 17 - 4
script/research/lotterysim/playground.ipynb

@@ -5,11 +5,24 @@
    "execution_count": 1,
    "execution_count": 1,
    "id": "c0e2a42d",
    "id": "c0e2a42d",
    "metadata": {},
    "metadata": {},
-   "outputs": [],
+   "outputs": [
+    {
+     "ename": "IndentationError",
+     "evalue": "expected an indented block after 'elif' statement on line 81 (strategy.py, line 83)",
+     "output_type": "error",
+     "traceback": [
+      "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n",
+      "  File \u001b[1;32m\"/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py\"\u001b[0m, line \u001b[1;32m3457\u001b[0m, in \u001b[1;35mrun_code\u001b[0m\n    exec(code_obj, self.user_global_ns, self.user_ns)\n",
+      "  File \u001b[1;32m\"/tmp/ipykernel_25214/365631361.py\"\u001b[0m, line \u001b[1;32m1\u001b[0m, in \u001b[1;35m<module>\u001b[0m\n    from core.lottery import *\n",
+      "  File \u001b[1;32m\"/home/ertosns/wrk/darkfi/script/research/lotterysim/core/lottery.py\"\u001b[0m, line \u001b[1;32m5\u001b[0m, in \u001b[1;35m<module>\u001b[0m\n    from core.darkie import *\n",
+      "\u001b[0;36m  File \u001b[0;32m\"/home/ertosns/wrk/darkfi/script/research/lotterysim/core/darkie.py\"\u001b[0;36m, line \u001b[0;32m2\u001b[0;36m, in \u001b[0;35m<module>\u001b[0;36m\u001b[0m\n\u001b[0;31m    from core.strategy import *\u001b[0m\n",
+      "\u001b[0;36m  File \u001b[0;32m\"/home/ertosns/wrk/darkfi/script/research/lotterysim/core/strategy.py\"\u001b[0;36m, line \u001b[0;32m83\u001b[0m\n\u001b[0;31m    elif rnd < 0.75 and rnd >= 0.5:\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block after 'elif' statement on line 81\n"
+     ]
+    }
+   ],
    "source": [
    "source": [
-    "from lottery import *\n",
-    "from threading import Thread\n",
-    "from pid import *\n",
+    "from core.lottery import *\n",
+    "from pid.pid_base import *\n",
     "import os"
     "import os"
    ]
    ]
   },
   },