(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 12.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 15913, 395] NotebookOptionsPosition[ 15385, 378] NotebookOutlinePosition[ 15731, 393] CellTagsIndexPosition[ 15688, 390] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ Rand and Jaccard index and the confusion matrix according to Definition 5.11 \ and Remark 5.13\ \>", "Subsubsection", CellChangeTimes->{{3.8209065017567563`*^9, 3.8209065052492156`*^9}, { 3.821159641642407*^9, 3.821159663452804*^9}, {3.821159723216816*^9, 3.8211597481343307`*^9}},ExpressionUUID->"3c873366-33d5-47a9-bb89-\ 169b6c5687f1"], Cell[BoxData[ RowBox[{"(*", " ", "\[IndentingNewLine]", RowBox[{ RowBox[{"Input", ":", " ", RowBox[{"two", " ", "partitions", " ", SuperscriptBox["\[CapitalPi]", RowBox[{"(", "1", ")"}]]}]}], ",", " ", RowBox[{ RowBox[{ RowBox[{ SuperscriptBox["\[CapitalPi]", RowBox[{"(", "2", ")"}]], " ", "of", " ", "the", " ", "set", " ", StyleBox["\[ScriptCapitalA]", FontSlant->"Italic"]}], StyleBox[" ", FontSlant->"Italic"], StyleBox["\[Subset]", FontSlant->"Italic"], StyleBox[" ", FontSlant->"Italic"], SuperscriptBox["\[DoubleStruckCapitalR]", "n"]}], ";", " ", "\[IndentingNewLine]", RowBox[{"Output", ":", " ", RowBox[{"sets", " ", SubscriptBox["C", "1"]}]}]}], ",", " ", SubscriptBox["C", "2"], ",", " ", SubscriptBox["C", "3"], ",", " ", SubscriptBox["C", "4"], ",", " ", RowBox[{"Rand", " ", "index", " ", "R"}], ",", " ", RowBox[{"Jaccard", " ", "index", " ", "J"}], ",", " ", RowBox[{"confusion", " ", "matrix", " ", "S"}], ",", " ", RowBox[{ RowBox[{"CPU", "-", "time"}], ";", "\[IndentingNewLine]", RowBox[{"Submodules", ":", " ", RowBox[{"none", " ", "needed"}]}]}]}], " ", "\[IndentingNewLine]", "*)"}]], "Input", CellChangeTimes->{{3.820906623387834*^9, 3.8209066255004454`*^9}, 3.8209066825823717`*^9, {3.820906804015813*^9, 3.8209068632471776`*^9}, 3.8209069470406637`*^9, {3.8209070074603195`*^9, 3.820907033234789*^9}, { 3.8211592045452576`*^9, 3.821159217530075*^9}, {3.821159774732521*^9, 3.8211598351371183`*^9}},ExpressionUUID->"cb5bbe93-493f-4a46-aedb-\ 3b01a9dc848d"], Cell[BoxData[ RowBox[{ RowBox[{"RandCompare", "[", RowBox[{"PI1_", ",", "PI2_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"CC1", "=", RowBox[{"CC2", "=", RowBox[{"CC3", "=", RowBox[{"CC4", "=", RowBox[{"{", "}"}]}]}]}]}], ",", "S", ",", "a", ",", "b", ",", "c", ",", "d"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"time", "=", RowBox[{"Timing", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "=", RowBox[{"Flatten", "[", RowBox[{"PI1", ",", "1"}], "]"}]}], ";", RowBox[{"m", "=", RowBox[{"Length", "[", "A", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI1", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}], "&&", RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI2", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}]}], ",", RowBox[{"CC1", "=", RowBox[{"Append", "[", RowBox[{"CC1", ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI1", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}], "&&", RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI2", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}]}], ",", RowBox[{"CC2", "=", RowBox[{"Append", "[", RowBox[{"CC2", ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI1", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}], "&&", RowBox[{"MemberQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI2", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}]}], ",", RowBox[{"CC3", "=", RowBox[{"Append", "[", RowBox[{"CC3", ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI1", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}], "&&", RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"SubsetQ", "[", RowBox[{ RowBox[{"PI2", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ",", "True"}], "]"}]}], ",", RowBox[{"CC4", "=", RowBox[{"Append", "[", RowBox[{"CC4", ",", RowBox[{"{", RowBox[{ RowBox[{"A", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"A", "[", RowBox[{"[", "s", "]"}], "]"}]}], "}"}]}], "]"}]}]}], "]"}], ";"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"s", ",", RowBox[{"r", "+", "1"}], ",", "m"}], "}"}]}], "]"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"r", ",", "m"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"a", "=", RowBox[{"Length", "[", "CC1", "]"}]}], ";", RowBox[{"b", "=", RowBox[{"Length", "[", "CC2", "]"}]}], ";", RowBox[{"c", "=", RowBox[{"Length", "[", "CC3", "]"}]}], ";", RowBox[{"d", "=", RowBox[{"Length", "[", "CC4", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Confusion", " ", "matrix"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"S", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"r", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"r", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"S", "[", RowBox[{"[", RowBox[{"r", ",", "s"}], "]"}], "]"}], "=", RowBox[{"Length", "[", RowBox[{"Intersection", "[", RowBox[{ RowBox[{"PI1", "[", RowBox[{"[", "r", "]"}], "]"}], ",", RowBox[{"PI2", "[", RowBox[{"[", "s", "]"}], "]"}]}], "]"}], "]"}]}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"r", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"s", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ";"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"CC1", ",", "CC2", ",", "CC3", ",", "CC4", ",", RowBox[{ RowBox[{"(", RowBox[{"a", "+", "d"}], ")"}], "/", RowBox[{"Binomial", "[", RowBox[{"m", ",", "2"}], "]"}]}], ",", RowBox[{"a", "/", RowBox[{"(", RowBox[{"a", "+", "b", "+", "c"}], ")"}]}], ",", "S", ",", RowBox[{"time", "[", RowBox[{"[", "1", "]"}], "]"}]}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellChangeTimes->{{3.586067993211243*^9, 3.5860682866161623`*^9}, { 3.5860683652497015`*^9, 3.5860685851774917`*^9}, {3.586068880810214*^9, 3.5860688823078165`*^9}, {3.586068985264799*^9, 3.586068990866209*^9}, 3.5860691309502563`*^9, {3.586071361330633*^9, 3.5860713619390345`*^9}, 3.5861382212900352`*^9, 3.5861729117185307`*^9, 3.5879574031401577`*^9, { 3.5879575632750425`*^9, 3.587957595058299*^9}, {3.5879582796909122`*^9, 3.5879582825145173`*^9}, {3.8099239190699053`*^9, 3.809923985048075*^9}, { 3.8210135044918613`*^9, 3.821013533465925*^9}, 3.8211591513802633`*^9, 3.8211595816808014`*^9, {3.8211628988963947`*^9, 3.821162901476226*^9}, { 3.831638693328201*^9, 3.8316387171745195`*^9}, {3.83163915985085*^9, 3.8316391604363985`*^9}, {3.8316396876252575`*^9, 3.8316397421458206`*^9}, {3.831639772973482*^9, 3.8316397790981894`*^9}}, CellLabel->"In[33]:=",ExpressionUUID->"24b2ad79-9dc9-44eb-86f9-bb37caaab8ee"] }, Open ]] }, WindowSize->{747, 479}, WindowMargins->{{-1188, Automatic}, {105, Automatic}}, FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (April 8, 2019)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 354, 7, 69, "Subsubsection",ExpressionUUID->"3c873366-33d5-47a9-bb89-169b6c5687f1"], Cell[937, 31, 1676, 41, 105, "Input",ExpressionUUID->"cb5bbe93-493f-4a46-aedb-3b01a9dc848d"], Cell[2616, 74, 12753, 301, 594, "Input",ExpressionUUID->"24b2ad79-9dc9-44eb-86f9-bb37caaab8ee"] }, Open ]] } ] *)