(* 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[ 11711, 333] NotebookOptionsPosition[ 11348, 316] NotebookOutlinePosition[ 11696, 331] CellTagsIndexPosition[ 11653, 328] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Rand and Jaccard index and the confusion matrix", FontColor->RGBColor[1, 0, 0]]], "Subsubsection", CellChangeTimes->{{3.8209065017567563`*^9, 3.8209065052492156`*^9}}, ExpressionUUID -> "3c873366-33d5-47a9-bb89-169b6c5687f1"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{ StyleBox["Input", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"two", " ", "partitions", " ", SuperscriptBox["\[CapitalPi]", RowBox[{"(", "1", ")"}]]}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ 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"]}], ";"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["Output", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"Rand", " ", "index", " ", "R"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"Jaccard", " ", "index", " ", "J"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"confusion", " ", "matrix", " ", "S"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"CPU", "-", "time"}], ";"}], FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["Submodules", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"none", " ", "needed"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]"}], "Text", 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.8223149595041084`*^9, 3.8223149777462854`*^9}, {3.822315023803019*^9, 3.8223150329895306`*^9}}, FontSize->12, ExpressionUUID -> "cb5bbe93-493f-4a46-aedb-3b01a9dc848d"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Rand", "[", RowBox[{"PI1_", ",", "PI2_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"m", "=", RowBox[{"Length", "[", RowBox[{"Flatten", "[", "PI1", "]"}], "]"}]}], ",", "S", ",", RowBox[{"S1", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}]}], ",", RowBox[{"S2", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}]}], ",", "a", ",", "b", ",", "c", ",", "d"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"time", "=", RowBox[{"Timing", "[", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Confusion", " ", "matrix"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ 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[{ RowBox[{"Numbers", " ", "a"}], ",", " ", "b", ",", " ", "c", ",", " ", "d"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"TT", "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"S", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"S1", "[", RowBox[{"[", "i", "]"}], "]"}], "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{"S", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"S2", "[", RowBox[{"[", "j", "]"}], "]"}], "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{"S", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"a", "=", RowBox[{".5", RowBox[{"(", RowBox[{"TT", "-", "m"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"b", "=", RowBox[{".5", RowBox[{"(", RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"S1", "[", RowBox[{"[", "i", "]"}], "]"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], "-", "TT"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"c", "=", RowBox[{".5", RowBox[{"(", RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"S2", "[", RowBox[{"[", "j", "]"}], "]"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}], "-", "TT"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"d", "=", RowBox[{".5", RowBox[{"(", RowBox[{"TT", "+", RowBox[{"m", "^", "2"}], "-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"S1", "[", RowBox[{"[", "i", "]"}], "]"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "PI1", "]"}]}], "}"}]}], "]"}], "-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"S2", "[", RowBox[{"[", "j", "]"}], "]"}], "^", "2"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI2", "]"}]}], "}"}]}], "]"}]}], ")"}]}]}], ";"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"a", "+", "d"}], ")"}], "/", RowBox[{"Binomial", "[", RowBox[{"m", ",", "2"}], "]"}]}], ",", RowBox[{"a", "/", RowBox[{"(", RowBox[{"a", "+", "b", "+", "c"}], ")"}]}], ",", "S", ",", RowBox[{"time", "[", RowBox[{"[", "1", "]"}], "]"}]}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[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.8211628567803926`*^9}, ExpressionUUID -> "24b2ad79-9dc9-44eb-86f9-bb37caaab8ee"] }, Open ]] }, WindowSize->{1536, 779}, WindowMargins->{{-8, Automatic}, {Automatic, -8}}, FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (September 21, 2016)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 252, 3, 39, "Subsubsection"], Cell[835, 27, 2783, 89, 85, "Text"], Cell[3621, 118, 7711, 195, 487, "Input"] }, Open ]] } ] *)