#NEWLINE# @ staticmethod #NEWLINE# def punchcard_module_classification_performance( module , dataset , s = 800 ) : #NEWLINE# #INDENT# "Punshcard-like clasification performances.__add__(\n\n        Actual dataset target vs. estimated target by the module.\n        The graph of a good classfier module should a have no red dots visible:\n        - Red Dots: Target (only visible if the black dot doesn't cover it).\n        - Green Dots: Estimated classes confidences (size = outputs means).\n        - Black Dots: Single winnter-takes-all estimated target.\n\n        :param module: An object that has at least reset() and activate() methods.\n        :param dataset: A classification dataset. It should, for any given sequence, have a constant target.\n        :type dataset: ClassificationDataSet\n        " #NEWLINE# def calculate_module_output_mean( module , inputs ) : #NEWLINE# #INDENT# "Returns the mean of the module's outputs for a given input list." #NEWLINE# outputs = np . zeros ( module . outdim ) #NEWLINE# module . reset ( ) #NEWLINE# for inpt in inputs : #NEWLINE# #INDENT# outputs += module . activate ( inpt ) #NEWLINE# #UNINDENT# return ( outputs / len ( inputs ) ) #NEWLINE# #UNINDENT# num_sequences = dataset . getNumSequences ( ) #NEWLINE# actual = [ ] #NEWLINE# expected = [ ] #NEWLINE# confidence_x = [ ] #NEWLINE# confidence_s = [ ] #NEWLINE# correct = 0 #NEWLINE# for seq_i in range ( num_sequences ) : #NEWLINE# #INDENT# seq = dataset . getSequence ( seq_i ) #NEWLINE# outputs_mean = calculate_module_output_mean ( module , seq [ 0 ] ) #NEWLINE# actual . append ( np . argmax ( outputs_mean ) ) #NEWLINE# confidence_s . append ( np . array ( outputs_mean ) ) #NEWLINE# confidence_x . append ( ( np . ones ( module . outdim ) * seq_i ) ) #NEWLINE# expected . append ( np . argmax ( seq [ 1 ] ) ) #NEWLINE# if ( actual [ ( - 1 ) ] == expected [ ( - 1 ) ] ) : #NEWLINE# #INDENT# correct += 1 #NEWLINE# #UNINDENT# #UNINDENT# plt . title ( '{}% Correct Classification (red dots mean bad classification)' . format ( ( ( correct * 100 ) / num_sequences ) ) ) #NEWLINE# plt . xlabel ( 'Sequence' ) #NEWLINE# plt . ylabel ( 'Class' ) #NEWLINE# plt . scatter ( list ( range ( num_sequences ) ) , expected , s = s , c = 'r' , linewidths = 0 ) #NEWLINE# plt . scatter ( list ( range ( num_sequences ) ) , actual , s = s , c = 'k' ) #NEWLINE# plt . scatter ( confidence_x , ( list ( range ( module . outdim ) ) * num_sequences ) , s = ( s * np . array ( confidence_s ) ) , c = 'g' , linewidths = 0 , alpha = 0.66 ) #NEWLINE# plt . yticks ( list ( range ( dataset . nClasses ) ) , dataset . class_labels )