Rand and Jaccard index and the confusion matrix according to Definition 5.11 and Remark 5.13

(* 
Input: two partitions (Π^((1))), (Π^((2))) of the set 𝒜 ⊂ (ℝ^n); 
Output: sets (Subscript[C, 1]), (Subscript[C, 2]), (Subscript[C, 3]), (Subscript[C, 4]), Rand index R, Jaccard index J, confusion matrix S, CPU-time;
Submodules: none needed 
*)

RandCompare[PI1_,PI2_]:=Module[{CC1=CC2=CC3=CC4={},S,a,b,c,d},
time=Timing[
A=Flatten[PI1,1];m=Length[A];
Do[
Do[
If[MemberQ[Table[SubsetQ[PI1[[j]],{A[[r]],A[[s]]}],{j,Length[PI1]}],True]&&MemberQ[Table[SubsetQ[PI2[[j]],{A[[r]],A[[s]]}],{j,Length[PI2]}],True],CC1=Append[CC1,{A[[r]],A[[s]]}]];
If[MemberQ[Table[SubsetQ[PI1[[j]],{A[[r]],A[[s]]}],{j,Length[PI1]}],True]&&FreeQ[Table[SubsetQ[PI2[[j]],{A[[r]],A[[s]]}],{j,Length[PI2]}],True],CC2=Append[CC2,{A[[r]],A[[s]]}]];
If[FreeQ[Table[SubsetQ[PI1[[j]],{A[[r]],A[[s]]}],{j,Length[PI1]}],True]&&MemberQ[Table[SubsetQ[PI2[[j]],{A[[r]],A[[s]]}],{j,Length[PI2]}],True],CC3=Append[CC3,{A[[r]],A[[s]]}]];
If[FreeQ[Table[SubsetQ[PI1[[j]],{A[[r]],A[[s]]}],{j,Length[PI1]}],True]&&FreeQ[Table[SubsetQ[PI2[[j]],{A[[r]],A[[s]]}],{j,Length[PI2]}],True],CC4=Append[CC4,{A[[r]],A[[s]]}]];
,{s,r+1,m}]
,{r,m}];
a=Length[CC1];b=Length[CC2];c=Length[CC3];d=Length[CC4];
(* Confusion matrix *)
S=Table[0,{r,Length[PI1]},{r,Length[PI2]}];
Do[
Do[
S[[r,s]]=Length[Intersection[PI1[[r]],PI2[[s]]]]
,{r,Length[PI1]}]
,{s,Length[PI2]}];];
{CC1,CC2,CC3,CC4,(a+d)/Binomial[m,2],a/(a+b+c),S,time[[1]]}
]