0
$\begingroup$

I am trying to run FindClusters[hex, DistanceFunction -> HammingDistance[IntegerDigits[#, 2, 8], IntegerDigits[0, 2, 8]] &] over a list of data but I keep getting the error enter image description here

(the number of cluster DistanceFunction ... can only be either a positive integer or automatic)

There is no problem running FindClusters[hex] or FindClusters[hex, DistanceFunction -> CanberraDistance]

I have also tried using DistanceFunction -> HammingDistance[BaseForm[#, 2], BaseForm[16^^0, 2]] & DistanceFunction -> HammingDistance[#, 16^^0] &

Sort of at a loss as to what to try next. Any suggestions?

My data is just a list of integers. e.g. {85,137,229,...}

$\endgroup$
5
  • 2
    $\begingroup$ Try scoping the pure function DistanceFunction -> (HammingDistance[IntegerDigits[#, 2, 8], IntegerDigits[0, 2, 8]] &) $\endgroup$ Commented Dec 18, 2020 at 17:27
  • $\begingroup$ That did it! Thank you! What is the reasoning for this? $\endgroup$
    – skyfire
    Commented Dec 18, 2020 at 17:57
  • $\begingroup$ I guess as a followup, this puts everything in 1 cluster. Do you know why that may be? $\endgroup$
    – skyfire
    Commented Dec 18, 2020 at 17:59
  • $\begingroup$ Ah nvm just need to put the number of partitions between hex and dist.. $\endgroup$
    – skyfire
    Commented Dec 18, 2020 at 18:07
  • 1
    $\begingroup$ @skyfire you ran into an operator precedence issue. I have learned from experience that pure functions given on the right-hand-side of rules / options are best wrapped in ( ) to make sure that the & operator binds to the right thing, i.e. OptionName -> (something something &). $\endgroup$
    – MarcoB
    Commented Dec 18, 2020 at 19:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.