(* 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[ 9711, 275] NotebookOptionsPosition[ 9352, 258] NotebookOutlinePosition[ 9697, 273] CellTagsIndexPosition[ 9654, 270] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Mahalanobis Davies - Bouldin 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}, {3.822222129185065*^9, 3.822222147210169*^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[{ "MDB", " ", "index", " ", "for", " ", "the", " ", "partition", " ", "\[CapitalPi]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[";", 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[{"dM", "[", "]"}], 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.8222221607470207`*^9, 3.8222221750484905`*^9}, {3.8223124189683475`*^9, 3.8223124264429436`*^9}}, FontSize->12, ExpressionUUID -> "4f6001e5-4731-4da1-898f-f0f23cdb63d0"], Cell[BoxData[{ RowBox[{"Clear", "[", "MDB", "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MDB", "[", RowBox[{"PI_", ",", "z_", ",", "Scov_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"k", "=", RowBox[{"Length", "[", "z", "]"}]}], ",", "FF", ",", "VV", ",", "mj", ",", RowBox[{"sum", "=", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"FF", "=", RowBox[{"VV", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"j", ",", "k"}], "}"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"mj", "=", RowBox[{"Length", "[", RowBox[{"PI", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"FF", "[", RowBox[{"[", "j", "]"}], "]"}], "=", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"PI", "[", RowBox[{"[", RowBox[{"j", ",", "i", ",", "1"}], "]"}], "]"}], "*", RowBox[{"dM", "[", RowBox[{ RowBox[{"PI", "[", RowBox[{"[", RowBox[{"j", ",", "i", ",", "2"}], "]"}], "]"}], ",", RowBox[{"z", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"Scov", "[", RowBox[{"[", "j", "]"}], "]"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "mj"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"VV", "[", RowBox[{"[", "j", "]"}], "]"}], "=", RowBox[{ RowBox[{"FF", "[", RowBox[{"[", "j", "]"}], "]"}], "/", RowBox[{"Sum", "[", RowBox[{ RowBox[{"PI", "[", RowBox[{"[", RowBox[{"j", ",", "i", ",", "1"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "mj"}], "}"}]}], "]"}]}]}]}], "\[IndentingNewLine]", " ", ",", RowBox[{"{", RowBox[{"j", ",", "k"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"max", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[NotEqual]", "j"}], ",", RowBox[{"max", "=", RowBox[{"Append", "[", RowBox[{"max", ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"VV", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"VV", "[", RowBox[{"[", "j", "]"}], "]"}]}], ")"}], "/", RowBox[{"dM", "[", RowBox[{ RowBox[{"z", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"z", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"Scov", "[", RowBox[{"[", "j", "]"}], "]"}]}], "]"}]}]}], " ", "]"}]}]}], "]"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"i", ",", "k"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"sum", "=", RowBox[{"sum", "+", RowBox[{"Max", "[", "max", "]"}]}]}]}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{"j", ",", "k"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"sum", "/", "k"}]}]}], "\[IndentingNewLine]", " ", "]"}]}]}], "Input", CellChangeTimes->{{3.5923719395193915`*^9, 3.5923719412041945`*^9}, { 3.5923720988112717`*^9, 3.592372102555278*^9}, {3.5923980453197746`*^9, 3.5923980576497936`*^9}, {3.5923980876578383`*^9, 3.5923981052308645`*^9}, { 3.5923981402759175`*^9, 3.5923981646229544`*^9}, {3.5923990668913393`*^9, 3.592399080523359*^9}, {3.5923991283174324`*^9, 3.592399134126441*^9}, { 3.5923991986715393`*^9, 3.592399230828588*^9}, {3.5923993899258285`*^9, 3.592399407617855*^9}, {3.592399502093996*^9, 3.592399516165018*^9}, { 3.592399553822075*^9, 3.5923995766501102`*^9}, {3.8067578646197467`*^9, 3.8067578652497487`*^9}}, ExpressionUUID -> "5ba93379-ba13-4fe9-986a-af0f9c076ea0"] }, 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, 397, 7, 49, "Subsection"], Cell[980, 31, 3770, 108, 125, "Text"], Cell[4753, 141, 4583, 114, 335, "Input"] }, Open ]] } ] *)