Markopy
Utilizing Markov Models for brute forcing attacks
Python.Markopy.Evaluation.ModelEvaluator Class Reference

evaluate a model More...

Inheritance diagram for Python.Markopy.Evaluation.ModelEvaluator:
Collaboration diagram for Python.Markopy.Evaluation.ModelEvaluator:

Public Member Functions

None __init__ (self, str filename)
 default constructor for evaluator More...
 
def evaluate (self)
 
def check_dangling (self)
 
def check_structure (self)
 
def check_weight_deviation (self)
 
def check_min (self)
 
def check_min_10percent (self)
 
def check_lean (self)
 
def check_distrib (self)
 
def success (self, checkname)
 pass a test More...
 
def fail (self, checkname)
 fail a test More...
 
def finalize (self)
 

Public Attributes

 lnodes
 
 rnodes
 
 ews
 
 edge_count
 
 lnode_count
 
 rnode_count
 
 stdev
 
 filename
 
 checks
 
 TEST_PASS_SYMBOL
 
 TEST_FAIL_SYMBOL
 
 all_checks_passed
 
 files
 
 check_funcs
 

Private Member Functions

list _evaluate (self, file)
 internal evaluation function for a single file More...
 

Detailed Description

evaluate a model

Definition at line 90 of file evaluate.py.

Constructor & Destructor Documentation

◆ __init__()

None Python.Markopy.Evaluation.ModelEvaluator.__init__ (   self,
str  filename 
)

default constructor for evaluator

Parameters
filenamefilename to evaluate. Can be a pattern

Reimplemented from Python.Markopy.Evaluation.Evaluator.

Definition at line 96 of file evaluate.py.

96  def __init__(self, filename: str) -> None:
97  "! @brief default constructor"
98  valid = super().__init__(filename)
99 
100  if not valid:
101  return False
102 

Member Function Documentation

◆ _evaluate()

list Python.Markopy.Evaluation.Evaluator._evaluate (   self,
  file 
)
privateinherited

internal evaluation function for a single file

Parameters
filefilename to evaluate

Reimplemented in Python.Markopy.Evaluation.CorpusEvaluator.

Definition at line 52 of file evaluate.py.

52  def _evaluate(self, file) -> list:
53  """!
54  @brief internal evaluation function for a single file
55  @param file filename to evaluate
56  """
57  if(not os.path.isfile(file)):
58  logging.pprint(f"Given file {file} is not a valid filename")
59  return False
60  else:
61  return open(file, "rb").read().split(b"\n")
62 
63 
64 

Referenced by Python.Markopy.Evaluation.Evaluator.evaluate(), and Python.Markopy.Evaluation.ModelEvaluator.evaluate().

Here is the caller graph for this function:

◆ check_dangling()

def Python.Markopy.Evaluation.ModelEvaluator.check_dangling (   self)

Definition at line 151 of file evaluate.py.

151  def check_dangling(self):
152  "! @brief check if model has dangling nodes"
153  if(self.lnode_count == self.rnode_count):
154  self.success("No dangling nodes")
155  else:
156  logging.pprint(f"Dangling nodes found, lnodes and rnodes do not match", 0)
157  self.fail("No dangling nodes")
158 

References Python.Markopy.Evaluation.Evaluator.fail(), Python.Markopy.Evaluation.ModelEvaluator.lnode_count, Python.Markopy.Evaluation.ModelEvaluator.rnode_count, and Python.Markopy.Evaluation.Evaluator.success().

Here is the call graph for this function:

◆ check_distrib()

def Python.Markopy.Evaluation.ModelEvaluator.check_distrib (   self)

Definition at line 228 of file evaluate.py.

228  def check_distrib(self):
229  "! @deprecated"
230  sorted_ews = copy(self.ews)
231  sorted_ews.sort(reverse=True)
232  ratio1 = sorted_ews[0]/sorted_ews[int(self.edge_count/2)]
233  ratio2 = sorted_ews[int(self.edge_count/2)]/sorted_ews[int(self.edge_count*0.1)]
234  #print(ratio1)
235  #print(ratio2)
236 
237 

References Python.Markopy.Evaluation.ModelEvaluator.edge_count, and Python.Markopy.Evaluation.ModelEvaluator.ews.

◆ check_lean()

def Python.Markopy.Evaluation.ModelEvaluator.check_lean (   self)

Definition at line 207 of file evaluate.py.

207  def check_lean(self):
208  "! @brief check which way model is leaning. Left, or right"
209  sample = self.ews[int(self.edge_count*0.1)]
210  avg = sum(self.ews) / len(self.ews)
211  med = statistics.median(self.ews)
212 
213  if(med*10<sample):
214  logging.pprint("Median is too left leaning and might indicate high entropy")
215  self.fail("Median too left leaning")
216  else:
217  self.success("Median in expected ratio")
218  pass
219 
220  if(sample*5>avg):
221  logging.pprint("Least probable 10% too close to average, might indicate inadequate training")
222  self.fail("Bad bottom 10%")
223  else:
224  self.success("Good bottom 10%")
225  pass
226 
227 

References Python.Markopy.Evaluation.ModelEvaluator.edge_count, Python.Markopy.Evaluation.ModelEvaluator.ews, Python.Markopy.Evaluation.Evaluator.fail(), and Python.Markopy.Evaluation.Evaluator.success().

Here is the call graph for this function:

◆ check_min()

def Python.Markopy.Evaluation.ModelEvaluator.check_min (   self)

Definition at line 186 of file evaluate.py.

186  def check_min(self):
187  "! @brief check 0 edge weights distribution"
188  count = 0
189  for ew in self.ews:
190  if ew==0:
191  count+=1
192  if(count > self.rnode_count*0.8):
193  self.fail("Too many 0 edges")
194  logging.pprint(f"0 weighted edges are dangerous and may halt the model.", 0)
195  else:
196  self.success("0 edges below threshold")
197 

References Python.Markopy.Evaluation.ModelEvaluator.ews, Python.Markopy.Evaluation.Evaluator.fail(), Python.Markopy.Evaluation.ModelEvaluator.rnode_count, and Python.Markopy.Evaluation.Evaluator.success().

Here is the call graph for this function:

◆ check_min_10percent()

def Python.Markopy.Evaluation.ModelEvaluator.check_min_10percent (   self)

Definition at line 198 of file evaluate.py.

198  def check_min_10percent(self):
199  "! @brief check minimum 10% of the edges"
200  sample = self.ews[int(self.edge_count*0.1)]
201  #print(f"10per: {sample}")
202  avg = sum(self.ews) / len(self.ews)
203  #print(f"avg: {avg}")
204  med = statistics.median(self.ews)
205  #print(f"med: {med}")
206 

References Python.Markopy.Evaluation.ModelEvaluator.edge_count, and Python.Markopy.Evaluation.ModelEvaluator.ews.

◆ check_structure()

def Python.Markopy.Evaluation.ModelEvaluator.check_structure (   self)

Definition at line 159 of file evaluate.py.

159  def check_structure(self):
160  "! @brief check model structure for validity"
161  if((self.lnode_count-1) * (self.rnode_count-1) + 2*(self.lnode_count-1)):
162  self.success("Model structure")
163  else:
164  logging.pprint(f"Model did not satisfy structural integrity check (lnode_count-1) * (rnode_count-1) + 2*(lnode_count-1)", 0)
165  self.fail("Model structure")
166 

References Python.Markopy.Evaluation.Evaluator.fail(), Python.Markopy.Evaluation.ModelEvaluator.lnode_count, Python.Markopy.Evaluation.ModelEvaluator.rnode_count, and Python.Markopy.Evaluation.Evaluator.success().

Here is the call graph for this function:

◆ check_weight_deviation()

def Python.Markopy.Evaluation.ModelEvaluator.check_weight_deviation (   self)

Definition at line 167 of file evaluate.py.

167  def check_weight_deviation(self):
168  "! @brief check model standart deviation between edge weights"
169  mean = sum(self.ews) / len(self.ews)
170  variance = sum([((x - mean) ** 2) for x in self.ews]) / len(self.ews)
171  res = variance ** 0.5
172  self.stdev = res
173  if(res==0):
174  logging.pprint(f"Model seems to be untrained", 0)
175  self.fail("Model has any training")
176  else:
177  self.success("Model has any training")
178  if(res<3000):
179  logging.pprint(f"Model is not adequately trained. Might result in inadequate results", 1)
180  self.fail("Model has training")
181  self.fail(f"Model training score: {round(self.stdev,2)}")
182  else:
183  self.success("Model has training")
184  self.success(f"Model training score: {round(self.stdev)}")
185 

References Python.Markopy.Evaluation.ModelEvaluator.ews.

◆ evaluate()

def Python.Markopy.Evaluation.ModelEvaluator.evaluate (   self)

Reimplemented from Python.Markopy.Evaluation.Evaluator.

Definition at line 103 of file evaluate.py.

103  def evaluate(self):
104  "! @brief evaluate a model"
105  logging.VERBOSITY=2
106  logging.SHOW_STACK_THRESHOLD=3
107  super().evaluate()
108  for file in self.files:
109  logging.pprint(f"Model: {file.split('/')[-1]}: ",2)
110  edges = super()._evaluate(file)
111  if not edges:
112  continue
113  self.lnodes = {}
114  self.rnodes = {}
115  self.ews = []
116  self.edge_count = len(edges)
117  for edge in edges:
118  if(edge ==b''):
119  self.edge_count-=1
120  continue
121  try:
122  e = edge.split(b',')
123  self.ews.append(int(edge[2:-2:1]))
124  if(e[0] not in self.lnodes):
125  self.lnodes[e[0]]=1
126  else:
127  self.lnodes[e[0]]+=1
128  if(e[-1] not in self.rnodes):
129  self.rnodes[e[-1]]=1
130  else:
131  self.rnodes[e[-1]]+=1
132  except Exception as e:
133  print(e)
134  logging.pprint(f"Model file is corrupted.", 0)
135  continue
136 
137  self.lnode_count = len(self.lnodes)
138  self.rnode_count = len(self.rnodes)
139  logging.pprint(f"total edges: {self.edge_count}", 1)
140  logging.pprint(f"unique left nodes: {self.lnode_count}", 1)
141  logging.pprint(f"unique right nodes: {self.rnode_count}", 1)
142 
143  for check in self.check_funcs:
144  try:
145  self.__getattribute__(check)()
146  except Exception as e:
147  print(e)
148  self.fail(f"Exceptionn in {check}")
149  self.finalize()
150 

References Python.Markopy.Evaluation.Evaluator._evaluate(), and Python.Markopy.Evaluation.Evaluator.files.

Referenced by Python.Markopy.MarkopyCLI.parse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fail()

def Python.Markopy.Evaluation.Evaluator.fail (   self,
  checkname 
)
inherited

fail a test

Parameters
checknametext to display with the check

Definition at line 72 of file evaluate.py.

72  def fail(self, checkname):
73  """!
74  @brief fail a test
75  @param checkname text to display with the check
76  """
77 
78  self.all_checks_passed = False
79  self.checks.append((checkname, self.TEST_FAIL_SYMBOL))
80 

References Python.Markopy.Evaluation.Evaluator.all_checks_passed, Python.Markopy.Evaluation.Evaluator.checks, and Python.Markopy.Evaluation.Evaluator.TEST_FAIL_SYMBOL.

Referenced by Python.Markopy.Evaluation.ModelEvaluator.check_dangling(), Python.Markopy.Evaluation.ModelEvaluator.check_lean(), Python.Markopy.Evaluation.ModelEvaluator.check_min(), Python.Markopy.Evaluation.ModelEvaluator.check_structure(), and Python.Markopy.Evaluation.CorpusEvaluator.evaluate().

Here is the caller graph for this function:

◆ finalize()

def Python.Markopy.Evaluation.Evaluator.finalize (   self)
inherited

Definition at line 81 of file evaluate.py.

81  def finalize(self):
82  "! @brief finalize an evaluation and print checks"
83  print("\n################ Checks ################ ")
84  for test in self.checks:
85  logging.pprint(f"{test[0]:30}:{test[1]} ")
86  print("\n")
87  self.checks = []
88  return self.all_checks_passed
89 

References Python.Markopy.Evaluation.Evaluator.all_checks_passed, and Python.Markopy.Evaluation.Evaluator.checks.

Referenced by Python.Markopy.Evaluation.CorpusEvaluator.evaluate().

Here is the caller graph for this function:

◆ success()

def Python.Markopy.Evaluation.Evaluator.success (   self,
  checkname 
)
inherited

pass a test

Parameters
checknametext to display with the check

Definition at line 65 of file evaluate.py.

65  def success(self, checkname):
66  """!
67  @brief pass a test
68  @param checkname text to display with the check
69  """
70  self.checks.append((checkname, self.TEST_PASS_SYMBOL))
71 

References Python.Markopy.Evaluation.Evaluator.checks, and Python.Markopy.Evaluation.Evaluator.TEST_PASS_SYMBOL.

Referenced by Python.Markopy.Evaluation.ModelEvaluator.check_dangling(), Python.Markopy.Evaluation.ModelEvaluator.check_lean(), Python.Markopy.Evaluation.ModelEvaluator.check_min(), Python.Markopy.Evaluation.ModelEvaluator.check_structure(), and Python.Markopy.Evaluation.CorpusEvaluator.evaluate().

Here is the caller graph for this function:

Member Data Documentation

◆ all_checks_passed

Python.Markopy.Evaluation.Evaluator.all_checks_passed
inherited

◆ check_funcs

Python.Markopy.Evaluation.Evaluator.check_funcs
inherited

Definition at line 49 of file evaluate.py.

◆ checks

Python.Markopy.Evaluation.Evaluator.checks
inherited

◆ edge_count

◆ ews

◆ filename

Python.Markopy.Evaluation.Evaluator.filename
inherited

Definition at line 32 of file evaluate.py.

◆ files

◆ lnode_count

Python.Markopy.Evaluation.ModelEvaluator.lnode_count

◆ lnodes

Python.Markopy.Evaluation.ModelEvaluator.lnodes

Definition at line 113 of file evaluate.py.

◆ rnode_count

◆ rnodes

Python.Markopy.Evaluation.ModelEvaluator.rnodes

Definition at line 114 of file evaluate.py.

◆ stdev

Python.Markopy.Evaluation.ModelEvaluator.stdev

Definition at line 172 of file evaluate.py.

◆ TEST_FAIL_SYMBOL

Python.Markopy.Evaluation.Evaluator.TEST_FAIL_SYMBOL
inherited

Definition at line 35 of file evaluate.py.

Referenced by Python.Markopy.Evaluation.Evaluator.fail().

◆ TEST_PASS_SYMBOL

Python.Markopy.Evaluation.Evaluator.TEST_PASS_SYMBOL
inherited

Definition at line 34 of file evaluate.py.

Referenced by Python.Markopy.Evaluation.Evaluator.success().


The documentation for this class was generated from the following file: