#NEWLINE# def cvm_2samp( data1 , data2 , weights1 = None , weights2 = None , power = 2.0 ) : #NEWLINE# #INDENT# "A handmade function for Cramer-von Mises similarity,\n    \\int |F_2 - F_1|^p dF_1\n    This implementation sorts the arrays each time, so it's slow" #NEWLINE# weights1 = check_sample_weight ( data1 , sample_weight = weights1 ) #NEWLINE# weights2 = check_sample_weight ( data2 , sample_weight = weights2 ) #NEWLINE# weights1 /= numpy . sum ( weights1 ) #NEWLINE# weights2 /= numpy . sum ( weights2 ) #NEWLINE# data = numpy . unique ( numpy . concatenate ( [ data1 , data2 ] ) ) #NEWLINE# bins = numpy . append ( data , ( data [ ( - 1 ) ] + 1 ) ) #NEWLINE# weights1_new = numpy . histogram ( data1 , bins = bins , weights = weights1 ) [ 0 ] #NEWLINE# weights2_new = numpy . histogram ( data2 , bins = bins , weights = weights2 ) [ 0 ] #NEWLINE# F1 = compute_cdf ( weights1_new ) #NEWLINE# F2 = compute_cdf ( weights2_new ) #NEWLINE# return numpy . average ( ( numpy . abs ( ( F1 - F2 ) ) ** power ) , weights = weights1_new )