def checkMatch(input, prediction, sparse=True, verbosity=0):
 if sparse:
  activeElementsInInput = set(input)
  activeElementsInPrediction = set(prediction)
 else:
  activeElementsInInput = set(input.nonzero()[0])
  activeElementsInPrediction = set(prediction.nonzero()[0])
 totalActiveInPrediction = len(activeElementsInPrediction)
 totalActiveInInput = len(activeElementsInInput)
 foundInInput = len(activeElementsInPrediction.intersection(activeElementsInInput))
 missingFromInput = len(activeElementsInPrediction.difference(activeElementsInInput))
 missingFromPrediction = len(activeElementsInInput.difference(activeElementsInPrediction))
 if (verbosity >= 1):
  print 'preds. found in input:', foundInInput, 'out of', totalActiveInPrediction,
  print '; preds. missing from input:', missingFromInput, 'out of', totalActiveInPrediction,
  print '; unexpected active in input:', missingFromPrediction, 'out of', totalActiveInInput
 return (foundInInput, totalActiveInInput, missingFromInput, totalActiveInPrediction)

def checkMatch ( input , prediction , sparse = True , verbosity = 0 ) : if sparse : activeElementsInInput = set ( input ) activeElementsInPrediction = set ( prediction ) else : activeElementsInInput = set ( input . nonzero ( ) [ 0 ] ) activeElementsInPrediction = set ( prediction . nonzero ( ) [ 0 ] ) totalActiveInPrediction = len ( activeElementsInPrediction ) totalActiveInInput = len ( activeElementsInInput ) foundInInput = len ( activeElementsInPrediction . intersection ( activeElementsInInput ) ) missingFromInput = len ( activeElementsInPrediction . difference ( activeElementsInInput ) ) missingFromPrediction = len ( activeElementsInInput . difference ( activeElementsInPrediction ) ) if ( verbosity >= 1 ) : print 'preds. found in input:' , foundInInput , 'out of' , totalActiveInPrediction , print '; preds. missing from input:' , missingFromInput , 'out of' , totalActiveInPrediction , print '; unexpected active in input:' , missingFromPrediction , 'out of' , totalActiveInInput return ( foundInInput , totalActiveInInput , missingFromInput , totalActiveInPrediction )
compares the actual input with the predicted input and returns results parameters: input: the actual input prediction: the predicted input verbosity: if > 0 .