(* 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[ 7946, 245] NotebookOptionsPosition[ 7588, 228] NotebookOutlinePosition[ 7933, 243] CellTagsIndexPosition[ 7890, 240] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Mahalanobis Calinski\[Dash]Harabasz index for optimal \ Mahalanobis partitions", FontColor->RGBColor[1, 0, 0]]], "Subsection", CellChangeTimes->{ 3.5854097085807176`*^9, 3.585637218737363*^9, 3.8067555638956704`*^9, { 3.822221900508813*^9, 3.822221903815808*^9}}, ExpressionUUID -> "40480428-912f-47e8-bf93-a11e4a6190d7"], 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[{"partition", " ", "\[CapitalPi]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox["=", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ SubscriptBox["\[Pi]", "1"], ",", "\[TripleDot]", ",", SubscriptBox["\[Pi]", "k"]}], "}"}], " ", "of", " ", "the", " ", "weighted", " ", "set", " ", "\[ScriptCapitalA]"}], " ", "\[Subset]", " ", SuperscriptBox["\[DoubleStruckCapitalR]", "n"]}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"centers", " ", SubscriptBox["c", "1"]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox["\[TripleDot]", FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ SubscriptBox["c", "k"], " ", "\[Element]", " ", SuperscriptBox["\[DoubleStruckCapitalR]", "n"]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"covariance", " ", "matrices", " ", UnderscriptBox["\[Sum]", "j"]}], "\[Element]", SuperscriptBox["\[DoubleStruckCapitalR]", RowBox[{"n", "\[Cross]", "n"}]]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"j", "=", RowBox[{"1", "\[TripleDot]k"}]}], ";"}], 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[{ "MCH", " ", "index", " ", "for", " ", "the", " ", "partition", " ", "\[CapitalPi]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[";", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ StyleBox["Submodules", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"dM", "[", "]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"MWF", "[", "]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]"}], "Text", CellChangeTimes->{{3.5886541897699375`*^9, 3.5886541909877396`*^9}, { 3.588654263023868*^9, 3.588654339794004*^9}, {3.5917588683674088`*^9, 3.591758869047409*^9}, {3.5917590328866577`*^9, 3.591759044816675*^9}, { 3.5937444692479725`*^9, 3.5937444771129847`*^9}, {3.8067251659311037`*^9, 3.8067252085746784`*^9}, {3.8067252462048798`*^9, 3.806725247420523*^9}, { 3.8067555742205267`*^9, 3.8067555768738213`*^9}, {3.8071002028759546`*^9, 3.807100208919777*^9}, {3.8107927170556965`*^9, 3.8107927208402033`*^9}, { 3.813128996198531*^9, 3.81312899765561*^9}, {3.8131290871131477`*^9, 3.8131291044656687`*^9}, 3.813129162727297*^9, {3.813129217851308*^9, 3.81312926039266*^9}, {3.8131293311074486`*^9, 3.813129508676306*^9}, { 3.8208235288040915`*^9, 3.8208235296679153`*^9}, {3.820823683703711*^9, 3.820823686279229*^9}, {3.822221932773207*^9, 3.822222005492038*^9}, { 3.8223123338845463`*^9, 3.8223123422221813`*^9}}, FontSize->12, ExpressionUUID -> "4f6001e5-4731-4da1-898f-f0f23cdb63d0"], Cell[BoxData[{ RowBox[{"Clear", "[", "MCH", "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MCH", "[", RowBox[{"PI_", ",", "z_", ",", "Scov_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"k", "=", RowBox[{"Length", "[", "z", "]"}]}], ",", "F", ",", "G"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"m", "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{"Length", "[", RowBox[{"PI", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", "k"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"F", "=", RowBox[{"MWF", "[", RowBox[{"PI", ",", "z", ",", "Scov"}], "]"}]}], ";", " ", RowBox[{"(*", " ", "or", " ", "*)"}], RowBox[{"F", "=", RowBox[{"n", " ", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"Total", "[", RowBox[{"PI", "[", RowBox[{"[", RowBox[{"j", ",", "All", ",", "1"}], "]"}], "]"}], "]"}], " ", RowBox[{ RowBox[{"(", RowBox[{"Det", "[", RowBox[{"Scov", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}], ")"}], "^", RowBox[{"(", RowBox[{"1", "/", "n"}], ")"}]}]}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PI", "]"}]}], "}"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"G", "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"Sum", "[", RowBox[{ RowBox[{"PI", "[", RowBox[{"[", RowBox[{"j", ",", "s", ",", "1"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"s", ",", RowBox[{"Length", "[", RowBox[{"PI", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}]}], "}"}]}], "]"}], "*", RowBox[{"dM", "[", RowBox[{ RowBox[{"z", "[", RowBox[{"[", "j", "]"}], "]"}], ",", "cc", ",", RowBox[{"Scov", "[", RowBox[{"[", "j", "]"}], "]"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"j", ",", "k"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{"m", "-", "k"}], ")"}], "*", RowBox[{"G", "/", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"k", "-", "1"}], ")"}], "F"}], ")"}]}]}]}]}], "\[IndentingNewLine]", " ", "]"}]}]}], "Input",ExpressionUUID->"419b6331-337f-43b9-baf6-e49f720f6b10"] }, Open ]] }, WindowSize->{830, 327}, WindowMargins->{{0, Automatic}, {Automatic, 7}}, 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, 353, 6, 49, "Subsection"], Cell[936, 30, 3924, 115, 125, "Text"], Cell[4863, 147, 2709, 78, 164, "Input"] }, Open ]] } ] *)