FindClusters doesn't accept custom DistanceFunction
You should assign Method -> "DBSCAN"
or Method -> "Agglomerate"
,such as
FindClusters[cases, DistanceFunction -> (Mod[#1 - #2, 3] &),
Method -> "Agglomerate"]
{{1,4,7,10,13,<<29>>},{2,3,5,6,8,<<61>>}}
As Simon Woods suggests in the comment, a workaround is to use ClusterAnalysis`FindClusters`FindClustersOld
instead of FindClusters
:
$Version
"11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)"
cases = Table[i, {i, 1, 100}];
ClusterAnalysis`FindClusters`FindClustersOld[cases,
DistanceFunction -> (Mod[#1 - #2, 2] &)]
{{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99}, {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100}}
ClusterAnalysis`FindClusters`FindClustersOld[cases,
DistanceFunction -> ((Abs[Mod[#1 - #2, 2]] + 1) &)]
{{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99}, {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100}}
The above output is identical to what version 10.4.1 returns.
Simon's guess that ClusterAnalysis`FindClusters`FindClustersOld
is the pre-version 11 FindClusters
is supported by the fact that it accepts only Method
's "Agglomerate"
and "Optimize"
and doesn't support any of the methods added in version 11:
cases = Table[i, {i, 1, 100}];
{#, Quiet@Check[
Shallow@ClusterAnalysis`FindClusters`FindClustersOld[cases,
DistanceFunction -> (Mod[#1 - #2, 2] &), Method -> #], $Failed]} & /@ {"Optimize",
"Agglomerate", "DBSCAN", "NeighborhoodContraction", "JarvisPatrick", "KMeans",
"MeanShift", "KMedoids", "SpanningTree", "Spectral", "GaussianMixture"}
(* {{"Optimize", {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, <<40>>},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20, <<40>>}}},
{"Agglomerate", {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, <<40>>},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20, <<40>>}}},
{"DBSCAN", $Failed}, {"NeighborhoodContraction", $Failed},
{"JarvisPatrick", $Failed}, {"KMeans", $Failed}, {"MeanShift", $Failed},
{"KMedoids", $Failed}, {"SpanningTree", $Failed}, {"Spectral", $Failed},
{"GaussianMixture", $Failed}}
*)