Added New Plot 'No. of Repaired Samples by each Node'

This commit is contained in:
Sudipta Basak 2024-02-19 23:20:53 +01:00
parent 4ef2617674
commit be0ce303c6
No known key found for this signature in database
4 changed files with 34 additions and 4 deletions

View File

@ -50,12 +50,14 @@ class Block:
"""
line = self.data[id::self.blockSizeR]
success = line.count(1)
repairedSamples = 0
if success >= self.blockSizeCK:
ret = ~line
self.data[id::self.blockSizeR] = 1
repairedSamples = len(line) - success
else:
ret = zeros(self.blockSizeC)
return ret
return ret, repairedSamples
def getRow(self, rowID):
"""It returns the block row corresponding to rowID."""
@ -71,12 +73,14 @@ class Block:
"""
line = self.data[id*self.blockSizeR:(id+1)*self.blockSizeR]
success = line.count(1)
repairedSamples = 0
if success >= self.blockSizeRK:
ret = ~line
self.data[id*self.blockSizeR:(id+1)*self.blockSizeR] = 1
repairedSamples = len(line) - success
else:
ret = zeros(self.blockSizeR)
return ret
return ret, repairedSamples
def print(self):
"""It prints the block in the terminal (outside of the logger rules))."""

View File

@ -22,6 +22,7 @@ class Result:
self.sampleRecvCount = [0] * shape.numberNodes
self.restoreRowCount = [0] * shape.numberNodes
self.restoreColumnCount = [0] * shape.numberNodes
self.repairedSampleCount = [0] * shape.numberNodes
def copyValidators(self, validators):
"""Copy information from simulator.validators to result."""
@ -32,6 +33,7 @@ class Result:
self.sampleRecvCount[i] = validators[i].sampleRecvCount
self.restoreRowCount[i] = validators[i].restoreRowCount
self.restoreColumnCount[i] = validators[i].restoreColumnCount
self.repairedSampleCount[i] = validators[i].repairedSampleCount
def populate(self, shape, config, missingVector):
"""It populates part of the result data inside a vector."""

View File

@ -62,6 +62,7 @@ class Validator:
self.sampleRecvCount = 0
self.restoreRowCount = 0
self.restoreColumnCount = 0
self.repairedSampleCount = 0
self.logger = logger
if self.shape.chiR < 1 and self.shape.chiC < 1:
self.logger.error("Chi has to be greater than 0", extra=self.format)
@ -518,7 +519,8 @@ class Validator:
def restoreRow(self, id):
"""Restore a given row if repairable."""
rep = self.block.repairRow(id)
rep, repairedSamples = self.block.repairRow(id)
self.repairedSampleCount += repairedSamples
if (rep.any()):
# If operation is based on send queues, segments should
# be queued after successful repair.
@ -538,7 +540,8 @@ class Validator:
def restoreColumn(self, id):
"""Restore a given column if repairable."""
rep = self.block.repairColumn(id)
rep, repairedSamples = self.block.repairColumn(id)
self.repairedSampleCount += repairedSamples
if (rep.any()):
# If operation is based on send queues, segments should
# be queued after successful repair.

View File

@ -86,6 +86,7 @@ class Visualizor:
self.plotSentData(result, plotPath)
self.plotRecvData(result, plotPath)
self.plotDupData(result, plotPath)
self.plotSamplesRepaired(result, plotPath)
if self.config.saveRCdist:
self.plotRowCol(result, plotPath)
@ -380,3 +381,23 @@ class Visualizor:
conf["yaxismax"] = maxi
plotData(conf)
print("Plot %s created." % conf["path"])
def plotSamplesRepaired(self, result, plotPath):
"""Plots the number of samples repaired by all nodes"""
conf = {}
text = str(result.shape).split("-")
conf["textBox"] = "Row Size: "+text[2]+"\nColumn Size: "+text[6]+"\nNumber of nodes: "+text[10]\
+"\nFailure rate: "+text[14]+"%"+"\nNetwork degree: "+text[32]+"\nMalicious Nodes: "+text[36]+"%"
conf["title"] = "Number of Samples Repaired by Nodes"
conf["type"] = "individual_bar"
conf["legLoc"] = 1
conf["desLoc"] = 1
conf["xlabel"] = "Nodes"
conf["ylabel"] = "Number of Samples Repaired"
conf["data"] = result.repairedSampleCount
conf["xdots"] = range(result.shape.numberNodes)
conf["path"] = plotPath + "/repairedSampleCount.png"
maxi = max(conf["data"])
conf["yaxismax"] = maxi
plotData(conf)
print("Plot %s created." % conf["path"])