Mathematica’s Entropy function is order-dependent when using the SameTest option.
That is:
Entropy[RandomSample[Range[11]], SameTest->(Abs[#1-#2]>1&) ]
will give different results many times.
I assume that this is because Entropy[] is in fact Union-izing the list, but, unlike Union, it is actually replacing one of the SameTest values with the other, and this replacement is order sensitive.
Is this a bug or is it the expected behaviour?
You can see using
Trace[ ]that theEntropy[ ]function ends up usingTally[ ]for counting the frequency of each state (numbers in this case).So for example
calls
which gives
because it groups {1,3,4} and {2}
But if you ask for
you get
because it groups {2,4} and {1,3}
Resulting in a different states distribution (2,2) vs (3,1) before, and hence in a different entropy value.
I think the problem arises because your SameTest is not partitioning the domain in two equivalence classes, as it should.
Edit
Just reformulating the last sentence:
Mma assumes that
which is not true in your case. For example