#NEWLINE# def ConfusionMatrix( self , worker_to_example_label , example_to_softlabel ) : #NEWLINE# #INDENT# worker_to_finallabel_weight = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# worker_to_finallabel_workerlabel_weight = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( worker , example_label ) in worker_to_example_label . items ( ) : #NEWLINE# #INDENT# if ( worker not in worker_to_finallabel_weight ) : #NEWLINE# #INDENT# worker_to_finallabel_weight [ weight ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( worker not in worker_to_finallabel_workerlabel_weight ) : #NEWLINE# #INDENT# worker_to_finallabel_workerlabel_weight [ worker ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# for ( example , workerlabel ) in example_label : #NEWLINE# #INDENT# softlabel = example_to_softlabel [ example ] #NEWLINE# for ( finallabel , weight ) in softlabel . items ( ) : #NEWLINE# #INDENT# worker_to_finallabel_weight [ worker ] [ finallabel ] = ( worker_to_finallabel_weight [ worker ] . get ( finallabel , 0 ) + weight ) #NEWLINE# if ( finallabel not in worker_to_finallabel_workerlabel_weight [ worker ] ) : #NEWLINE# #INDENT# worker_to_finallabel_workerlabel_weight [ worker ] [ finallabel ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# worker_to_finallabel_workerlabel_weight [ worker ] [ finallabel ] [ workerlabel ] = ( worker_to_finallabel_workerlabel_weight [ worker ] [ finallabel ] . get ( workerlabel , 0 ) + weight ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# worker_to_confusion_matrix = worker_to_finallabel_workerlabel_weight #NEWLINE# for ( worker , finallabel_workerlabel_weight ) in worker_to_finallabel_workerlabel_weight . items ( ) : #NEWLINE# #INDENT# for ( finallabel , workerlabel_weight ) in finallabel_workerlabel_weight . items ( ) : #NEWLINE# #INDENT# if ( worker_to_finallabel_weight [ worker ] [ finallabel ] == 0 ) : #NEWLINE# #INDENT# for label in self . label_set : #NEWLINE# #INDENT# if ( label == finallabel ) : #NEWLINE# #INDENT# worker_to_confusion_matrix [ worker ] [ finallabel ] [ label ] = 0.7 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# worker_to_confusion_matrix [ worker ] [ finallabel ] [ label ] = ( 0.3 / ( len ( self . label_set ) - 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for label in self . label_set : #NEWLINE# #INDENT# if ( label in workerlabel_weight ) : #NEWLINE# #INDENT# worker_to_confusion_matrix [ worker ] [ finallabel ] [ label ] = ( ( workerlabel_weight [ label ] * 1.0 ) / worker_to_finallabel_weight [ worker ] [ finallabel ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# worker_to_confusion_matrix [ worker ] [ finallabel ] [ label ] = 0.0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return worker_to_confusion_matrix