Last active
April 22, 2019 01:51
-
-
Save resilience-me/f5a09651aed95203049972945f4e0ede to your computer and use it in GitHub Desktop.
Revisions
-
resilience-me revised this gist
Apr 22, 2019 . No changes.There are no files selected for viewing
-
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 13 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,11 @@ # This simulation creates a web of trust with a static number of trust lines # per person. The swarm redistribution pulses then find credit line paths based # on those trust lines, without any loops (credit lines in Ripple cannot loop, # because when they do credit is cleared. ) from __future__ import division import random # Set parameters for the simulation population = 2 ** 13 @@ -25,19 +28,19 @@ frequency = {} totalPulses = population def incrementFrequency(node, step): frequency.get(node, 0) if frequency.get(node) == None: frequency[node] = {} for hop in range(totalHops): frequency[node][hop] = 0 frequency[node][step] += 1 def swarmRedistribution(): duplicates = {} branchingTree = {} def selectCreditLines(step, agent): # Select credit line paths without any loops (a person cannot be two times in a single pulse. ) -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 11 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ from __future__ import division import random # This simulation creates a web of trust with a static number of trust lines per person. The swarm redistribution pulses then find credit line paths based on those trust lines, 4 per person, without any loops (a person cannot be two times in a single pulse. ) # Set parameters for the simulation population = 2 ** 13 trustLines = 16 @@ -17,21 +19,20 @@ initiateWoT() creditLines = 4 totalHops = 4 frequency = {} totalPulses = population def swarmRedistribution(): duplicates = {} branchingTree = {} def incrementFrequency(node, step): frequency.get(node, 0) if frequency.get(node) == None: frequency[node] = {} for hop in range(totalHops): frequency[node][hop] = 0 @@ -52,21 +53,15 @@ def swarmRedistribution(): indexLength = trustLines - linkUtility.counter while node < indexLength: randomLink = random.randint(0, indexLength - 1) if linkUtility.index.get(randomLink) == None: linkUtility.index[randomLink] = randomLink fromIndex = linkUtility.index[randomLink] if linkUtility.index.get(indexLength - 1) == None: linkUtility.index[indexLength - 1] = indexLength - 1 linkUtility.index[fromIndex] = linkUtility.index[indexLength - 1] linkUtility.counter += 1 indexLength -= 1 if duplicates.get(people[agent][fromIndex]) == None: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) incrementFrequency(people[agent][fromIndex], step-1) @@ -91,5 +86,5 @@ def swarmRedistribution(): for i in range(totalPulses): swarmRedistribution() randomAgent = random.randint(0, population - 1) print(frequency[randomAgent]) -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import random # Set parameters for the simulation population = 2 ** 15 trustLines = 16 @@ -17,11 +17,11 @@ initiateWoT() creditLines = 4 totalHops = 5 frequency = {} totalPulses = 10000 def swarmRedistribution(): -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ frequency = {} totalPulses = 1000 def swarmRedistribution(): duplicates = {} branchingTree = {} @@ -33,10 +33,8 @@ def swarmRedistribution(): frequency[node] except: frequency[node] = {} for hop in range(totalHops): frequency[node][hop] = 0 frequency[node][step] += 1 def selectCreditLines(step, agent): @@ -71,7 +69,7 @@ def swarmRedistribution(): except: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) incrementFrequency(people[agent][fromIndex], step-1) break node += 1 if node == indexLength: -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,9 +24,21 @@ frequency = {} totalPulses = 1000 def swarmRedistribution(): duplicates = {} branchingTree = {} def incrementFrequency(node, step): try: frequency[node] except: frequency[node] = {} try: frequency[node][step] except: frequency[node][step] = 0 frequency[node][step] += 1 def selectCreditLines(step, agent): # Select credit line paths without any loops (a person cannot be two times in a single pulse. ) @@ -59,6 +71,7 @@ def swarmRedistribution(): except: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) incrementFrequency(agent, step) break node += 1 if node == indexLength: @@ -76,15 +89,6 @@ def swarmRedistribution(): branchingTree[step+1] = [] for node in branchingTree[step]: selectCreditLines(step+1, node) for i in range(totalPulses): swarmRedistribution() -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 22 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import random population = 2 ** 12 trustLines = 16 people = {} @@ -19,6 +19,10 @@ creditLines = 4 totalHops = 4 frequency = {} totalPulses = 1000 def swarmRedistribution(): duplicates = {} branchingTree = {} @@ -58,8 +62,8 @@ def swarmRedistribution(): break node += 1 if node == indexLength: # If this happens, just increase the population, # and/or trust lines, or decrease credit lines, # or decrease the number of hops print("Failure. The pulse has looped. ") quit() @@ -72,6 +76,18 @@ def swarmRedistribution(): branchingTree[step+1] = [] for node in branchingTree[step]: selectCreditLines(step+1, node) try: frequency[node] except: frequency[node] = {} try: frequency[node][step] except: frequency[node][step] = 0 frequency[node][step] += 1 for i in range(totalPulses): swarmRedistribution() randomAgent = random.randint(0, population) print(frequency[randomAgent]) -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,9 @@ import random # Set parameters for the simulation population = 2 ** 12 trustLines = 4 people = {} @@ -58,6 +58,9 @@ def swarmRedistribution(): break node += 1 if node == indexLength: # If this happens, just increase the population, # and/or trust lines, or decrease credit lines, # or decrease the number of hops print("Failure. The pulse has looped. ") quit() @@ -70,5 +73,5 @@ def swarmRedistribution(): for node in branchingTree[step]: selectCreditLines(step+1, node) for i in range(1000): swarmRedistribution() -
resilience-me revised this gist
Apr 22, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,13 +51,15 @@ def swarmRedistribution(): linkUtility.counter += 1 indexLength -= 1 try: duplicates[people[agent][fromIndex]] except: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) break node += 1 if node == indexLength: print("Failure. The pulse has looped. ") quit() taxPayer = random.randint(0, population - 1) branchingTree[0] = [] @@ -66,9 +68,7 @@ def swarmRedistribution(): for step in range(totalHops): branchingTree[step+1] = [] for node in branchingTree[step]: selectCreditLines(step+1, node) for i in range(10000000): swarmRedistribution() -
resilience-me revised this gist
Apr 21, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ trustLines = 16 people = {} def initiateWoT(): for node in range(population): people[node] = random.sample(range(population), trustLines) -
resilience-me revised this gist
Apr 21, 2019 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,7 @@ people = {} def initiateWoT(): for node in range(population): people[node] = random.sample(range(population), trustLines) initiateWoT() @@ -53,21 +52,24 @@ def swarmRedistribution(): linkUtility.counter += 1 indexLength -= 1 try: print(agent) duplicates[people[agent][fromIndex]] except: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) break node += 1 taxPayer = random.randint(0, population - 1) branchingTree[0] = [] branchingTree[0].append(taxPayer) for step in range(totalHops): branchingTree[step+1] = [] for node in branchingTree[step]: print(branchingTree[step]) print(node) selectCreditLines(step+1, node) for i in range(100000): swarmRedistribution() -
resilience-me revised this gist
Apr 21, 2019 . 1 changed file with 46 additions and 43 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,12 @@ trustLines = 16 people = {} def initiateWoT(): for node in range(population): people[node] = random.sample(range(1, population), trustLines) initiateWoT() creditLines = 4 @@ -22,49 +24,50 @@ totalHops = 4 def swarmRedistribution(): duplicates = {} branchingTree = {} def selectCreditLines(step, agent): # Select credit line paths without any loops (a person cannot be two times in a single pulse. ) class LinkUtility(): index = {} counter = 0 linkUtility = LinkUtility() for creditLine in range(creditLines): node = 0 indexLength = trustLines - linkUtility.counter while node < indexLength: randomLink = random.randint(0, indexLength - 1) try: linkUtility.index[randomLink] except: linkUtility.index[randomLink] = randomLink fromIndex = linkUtility.index[randomLink] try: linkUtility.index[indexLength - 1] except: linkUtility.index[indexLength - 1] = indexLength - 1 linkUtility.index[fromIndex] = linkUtility.index[indexLength - 1] linkUtility.counter += 1 indexLength -= 1 try: duplicates[people[agent][fromIndex]] except: duplicates[people[agent][fromIndex]] = True branchingTree[step].append(people[agent][fromIndex]) break node += 1 taxPayer = random.randint(0, population) branchingTree[0] = [] branchingTree[0].append(taxPayer) for step in range(totalHops): branchingTree[step+1] = [] print(step) for node in branchingTree[step]: selectCreditLines(step+1, node) swarmRedistribution() -
resilience-me revised this gist
Apr 21, 2019 . 1 changed file with 21 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,18 +19,6 @@ creditLines = 4 totalHops = 4 def swarmRedistribution(): duplicates = {} branchingTree = {} @@ -40,19 +28,32 @@ def swarmRedistribution(): class LinkUtility(): index = {} counter = 0 linkUtility = LinkUtility() for creditLine in range(creditLines): node = 0 indexLength = trustLines - linkUtility.counter while node < indexLength: randomLink = random.randint(0, indexLength - 1) try: linkUtility.index[randomLink] except: linkUtility.index[randomLink] = randomLink fromIndex = linkUtility.index[randomLink] try: linkUtility.index[indexLength - 1] except: linkUtility.index[indexLength - 1] = indexLength - 1 linkUtility.index[fromIndex] = linkUtility.index[indexLength - 1] linkUtility.counter += 1 indexLength -= 1 try: duplicates[fromIndex] except: duplicates[fromIndex] = True branchingTree[0].append(fromIndex) break node += 1 -
resilience-me revised this gist
Apr 21, 2019 . 1 changed file with 26 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,16 +34,35 @@ treeSize = calculateTreeSize() def swarmRedistribution(): duplicates = {} branchingTree = {} taxPayer = random.randint(0, population) branchingTree[0] = taxPayer class LinkUtility(): index = {} counter = 0 linkUtility = LinkUtility() for creditLine in range(creditLines): node = 0 while node < trustLines - linkUtility.counter: issueIOU = random.randint(0, trustLines - 1 - linkUtility.counter) node += 1 try: duplicates[issueIOU] except: duplicates[issueIOU] = True linkUtility.counter += 1 for step in range(1 + totalHops): computeBranch = [] for node in range(creditLines ** step): taxPayer = random.randint(0, population) computeBranch.append(taxPayer) branchingTree[step] = computeBranch print(branchingTree[0][0]) # branchingTree = random.sample(range(1, trustLines), treeSize) del duplicates -
resilience-me created this gist
Apr 21, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ from __future__ import division import random # Set parameters for the simulation population = 2 ** 10 trustLines = 16 people = {} def initiateWoT(): for node in range(population): people[node] = random.sample(range(1, population), trustLines) initiateWoT() creditLines = 4 totalHops = 4 # Calculate geometric series for creditLines^totalHops # to get total nodes in branching tree. # Includes the person paying the tax, 1 + totalHops. def calculateTreeSize(): computeTree = 0 for step in range(1 + totalHops): computeTree += creditLines ** step return computeTree treeSize = calculateTreeSize() def swarmRedistribution(): duplicates = {} branchingTree = {} for step in range(treeSize) taxPayer = random.randint(0, population) computeBranch = [] computeBranch.append(taxPayer) branchingTree[1] = computeBranch print(branchingTree[1]) print(taxPayer) print(people[taxPayer]) # branchingTree = random.sample(range(1, trustLines), treeSize) del duplicates swarmRedistribution()