#NEWLINE# def expr( self , model , data , **kwargs ) : #NEWLINE# #INDENT# '\n        Returns the sum of the costs the SumOfCosts instance was given at\n        initialization.\n\n        Parameters\n        ----------\n        model : pylearn2.models.model.Model\n            the model for which we want to calculate the sum of costs\n        data : flat tuple of tensor_like variables.\n            data has to follow the format defined by self.get_data_specs(),\n            but this format will always be a flat tuple.\n        ' #NEWLINE# self . get_data_specs ( model ) [ 0 ] . validate ( data ) #NEWLINE# ( composite_specs , mapping ) = self . get_composite_specs_and_mapping ( model ) #NEWLINE# nested_data = mapping . nest ( data ) #NEWLINE# costs = [ ] #NEWLINE# for ( cost , cost_data ) in safe_zip ( composite_specs . costs , nested_data ) : #NEWLINE# #INDENT# costs . append ( cost . expr ( model , cost_data , ** kwargs ) ) #NEWLINE# #UNINDENT# assert ( len ( costs ) > 0 ) #NEWLINE# if any ( [ ( cost is None ) for cost in costs ] ) : #NEWLINE# #INDENT# sum_of_costs = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# costs = [ ( coeff * cost ) for ( coeff , cost ) in safe_zip ( self . coeffs , costs ) ] #NEWLINE# assert ( len ( costs ) > 0 ) #NEWLINE# sum_of_costs = reduce ( ( lambda x , y : ( x + y ) ) , costs ) #NEWLINE# #UNINDENT# return sum_of_costs