Instantly share code, notes, and snippets.

Embed
What would you like to do?
if __name__ == "__main__":
banks = []
with open('#BankData','rb') as data:
reader = csv.reader(data)
for datum in reader:
# Datum = ['Bank name', 'Assets', 'Deposits']
bank = Bank(datum[0], datum[1], datum[2])
banks.append(bank)
interbankNetwork = InterbankNetwork(banks)
Results = []
for i in range(1000000):
interbankNetwork.constructNetwork()
interbankNetwork.startShock(10)
Results.append(interbankNetwork.analyzeNetwork())
interbankNetwork.resetNetwork()
print "Links, Avg links per bank, #Results, Avg Banks Shocked, Avg Max Shock, Avg Min Shock, Max Max Shock, Max Min Shock, Stdev Banks Shocked, Stdev Max Shock, Stdev Min Shock"
for links in range(2700):
totalResults = 0
# Once off count metrics
avgTotalShocked = 0.0
avgMaxShock = 0.0
avgMinShock = 0.0
maxMaxShock = 0.0
maxMinShock = 1.0
for result in Results:
if result.numLinks == links:
totalResults = totalResults + 1
avgTotalShocked = avgTotalShocked + result.totalShocked
avgMaxShock = avgMaxShock + result.maxShock
avgMinShock = avgMinShock + result.minShock
if result.maxShock > maxMaxShock:
maxMaxShock = result.maxShock
if result.minShock < maxMinShock: maxMinShock = result.minShock if totalResults > 0:
avgTotalShocked = avgTotalShocked / totalResults
avgMaxShock = avgMaxShock / totalResults
avgMinShock = avgMinShock / totalResults
# Standard deviations
stdevTotalShocked = 0.0
stdevMaxShock = 0.0
stdevMinShock = 0.0
for result in Results:
if result.numLinks == links:
stdevTotalShocked = stdevTotalShocked + math.pow((result.totalShocked - avgTotalShocked),2.0)
stdevMaxShock = stdevMaxShock + math.pow((result.maxShock - avgMaxShock),2.0)
stdevMinShock = stdevMinShock + math.pow((result.minShock - avgMinShock),2.0)
stdevTotalShocked = math.sqrt(stdevTotalShocked/totalResults)
stdevMaxShock = math.sqrt(stdevMaxShock/totalResults)
stdevMinShock = math.sqrt(stdevMinShock/totalResults)
print links, ",",(links / 50),",", totalResults,",", avgTotalShocked,
",", avgMaxShock,",", avgMinShock,",", maxMaxShock,",", maxMinShock,
",",stdevTotalShocked,",",stdevMaxShock,",",stdevMinShock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment