distance function between histograms accounting for bucket distance I'm trying to find a good distance measure for histograms that has the following properties:


*

*if histogram A and B have high values in buckets further apart, they're more different than if they had high values close together

*it should take into account similarity, therefore the distance between histogram A and B should be higher than the distance between histograms A1 and B1 built adding a bucket ad the end with the same height in A1 and B1.

*the distance between two buckets is linear and circular, meaning that the first and last bucket are considered next to each other
since probably I wasn't very clear, I'll give you some context.. first with bucket I mean a single bar of the histogram (bucket because it's basically an interval, and the height of the bar is defined as the count of element in a set that fall in that bucket).
In my case, buckets are the hours of the day (that's why 23 and 0 should be considered distance 1), and the height of the bars represents how many events I had in that hour.
If something is not clear, please comment and I'll try to explain better.
 A: I have two ideas for statistical tests of your data. 
Both are standard and can be done in readily available software (I used R). 
Neither specifically addresses the issue of circularity, but I don't see that as an important issue in detecting differences in traffic patterns between two days (or other time periods). If that is an issue you feel is essential,
then you can start by thinking about how these two tests might be inadequate for your purposes.
Chi-squared test (independence). The first is based on two histograms, each with 24 hourly bins.
Make a $2 \times 24$ matrix of the counts from the two histograms and do a chi-squared contingency test on the counts. The null hypothesis is that the counts in the two rows are consistent with matching traffic patterns in the two histograms. The null hypothesis is rejected if patterns differ significantly.
In the matrix tabled below I have used 12 bins of 2 hours each so the (fake) data will fit.
x.freq  947  829  864  761  781  772  789  778  799   802   868  1010
y.freq  243  543  716  927 1016 1129 1136 1054 1002  1010   789   435

It looks as if the x's peak on either side of midnight and the y's peak in
the afternoon. A standard chi-square (contingency-table) test for independence, had a P-value less than $10^{-15}$, so it in extremely
difficult to imagine that the two days (X and Y) have the same profile of counts across the two-hour periods. Here 'Independence' indicates that the frequency in a two-hour period does not depend significantly on which of the two days is considered; overwhelmingly false here.
Kolmogorov-Smirnov Goodness-of-Fit Test. The original data were collected continuously on a time scale from 0 to 86,400 sec. (in a day). In practice, 'continuous' means that no two of the 10,000 simulated observations in a day were exactly equal. Then a Kolmogorov-Smirnov test of the two daily empirical distribution functions (ECDFs) also has a tiny P-value, indicating a difference in the two daily patterns.
To make an ECDF start by sorting the data from smallest and largest; these
go on the horizontal axis. Going from left to right, the ECDF increases by 1/10000 at each datapoint; between plot points the ECDF is constant. For such a large number of datapoints, the ECDF closely imitates a smooth curve starting at 0 on the left and rising smoothly to 1 at the right. An ECDF
more reliably imitates the cumulative distribution function (CDF) of the daily population of events. 
A Kolmogorov-Smirnov test is based on a measurement of the maximum disagreement between the two ECDF plots. Good agreement implies a small value of the statistic and a large P-value; poor agreement a large value of the statistic and a small P-value. 
The code for my R session is given below, in case you know how to read it.
 # simulate fake data
 x = rbeta(10^4, .9, .9)*86400     # heavy near midnight
 y = rbeta(10^4, 1.1, 1.5)*86400   # heavy in afternoon

 # get counts and do chi-squared test
 cut = seq(0, 86400, length=13)    # cutpoints for 12 bins
 x.freq = hist(x, br=cut, plot=F)$counts
     y.freq = hist(y, br=cut, plot=F)$counts
 MAT = rbind(x.freq, y.freq)      # matrix of counts
 chisq.test(MAT)
 ##        Pearson's Chi-squared test
 ## data:  MAT 
 ## X-squared = 987.5261, df = 11, p-value < 2.2e-16

 # Kolmogorov-Smirnov goodness-of-fit test
 ks.test(x, y)
 ##        Two-sample Kolmogorov-Smirnov test
 ## data:  x and y 
 ## D = 0.1148, p-value < 2.2e-16
 ## alternative hypothesis: two.sided 

