(* 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[ 11359, 306] NotebookOptionsPosition[ 10999, 289] NotebookOutlinePosition[ 11344, 304] CellTagsIndexPosition[ 11301, 301] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["A single step of DBSCAN algorithm", FontColor->RGBColor[1, 0, 0]]], "Subsubsection", CellChangeTimes->{{3.6818902836728277`*^9, 3.681890292157613*^9}, { 3.6832692294515667`*^9, 3.6832692315297985`*^9}, {3.8209795464830685`*^9, 3.820979549598916*^9}}, ExpressionUUID -> "fb31151f-75c3-4399-ab00-43cac90040cc"], Cell[BoxData[{ RowBox[{ RowBox[{ StyleBox["Input", FontColor->RGBColor[1, 0, 0]], StyleBox[":", FontColor->RGBColor[1, 0, 0]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"data", " ", "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[{"core", " ", "point", " ", StyleBox[ SubscriptBox["c", "p"], FontSlant->"Italic"]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox["MinPts", FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"\[Epsilon]", "-", RowBox[{"density", " ", "\[Epsilon]", RowBox[{"(", "\[ScriptCapitalA]", ")"}]}]}], ";"}], 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[{"cluster", " ", "\[Pi]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"border", " ", "points", " ", StyleBox["SSE", FontSlant->"Italic"]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"outliers", " ", StyleBox["SSN", FontSlant->"Italic"]}], ";"}], 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[{"Neps", "[", "]"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"EPSILON", "[", "]"}], FontColor->RGBColor[0, 0, 1]]}], " "}], "\[IndentingNewLine]"}], "Text", CellChangeTimes->{{3.8209796424920626`*^9, 3.8209797447167287`*^9}, { 3.8209797931301317`*^9, 3.8209798365128937`*^9}, {3.8223060732755876`*^9, 3.8223060816637373`*^9}}, FontSize->12, ExpressionUUID -> "c662ff0b-0295-4ce5-842c-b9894886a7ad"], Cell[BoxData[ RowBox[{ RowBox[{"DBSCAN1", "[", RowBox[{"A_", ",", "xx_", ",", "MinPts_", ",", "eps_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"B", ",", "S", ",", "SE", ",", "SN", ",", "PP"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"SE", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"B", "=", "A"}], ";", "\[IndentingNewLine]", RowBox[{"S", "=", RowBox[{"{", "xx", "}"}]}], ";", " ", RowBox[{"SN", "=", RowBox[{"{", "}"}]}], ";", RowBox[{"PP", "=", RowBox[{"{", "}"}]}], ";", " ", "\[IndentingNewLine]", " ", RowBox[{"Ne", "=", RowBox[{"Neps", "[", RowBox[{"A", ",", "xx", ",", "eps"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "Ne", "]"}], ">", "1"}], "&&", RowBox[{ RowBox[{"Length", "[", "Ne", "]"}], "<", " ", "MinPts"}]}], ",", RowBox[{"SE", "=", RowBox[{"Union", "[", RowBox[{"SE", ",", "Ne"}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "Ne", "]"}], "<", " ", "MinPts"}], ",", RowBox[{"SN", "=", RowBox[{"Union", "[", RowBox[{"SN", ",", RowBox[{"{", "xx", "}"}]}], "]"}]}], ",", "\[IndentingNewLine]", " ", RowBox[{ RowBox[{"S", "=", RowBox[{"Union", "[", RowBox[{"S", ",", RowBox[{"{", "xx", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\t", RowBox[{"NeB", "=", RowBox[{"Intersection", "[", RowBox[{"B", ",", "Ne"}], "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"If", "[", RowBox[{ RowBox[{"NeB", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", RowBox[{ RowBox[{"PP", "=", RowBox[{"Union", "[", RowBox[{"PP", ",", "NeB"}], "]"}]}], ";", "\[IndentingNewLine]", "\t", RowBox[{"B", "=", RowBox[{"Complement", "[", RowBox[{"B", ",", "NeB"}], "]"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", "\t", RowBox[{"Qu", "=", RowBox[{"Complement", "[", RowBox[{"Ne", ",", "S"}], "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"While", "[", RowBox[{ RowBox[{"Qu", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", RowBox[{ RowBox[{"y", "=", RowBox[{"RandomChoice", "[", "Qu", "]"}]}], ";", " ", RowBox[{"S", "=", RowBox[{"Union", "[", RowBox[{"S", ",", RowBox[{"{", "y", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"Ny", "=", RowBox[{"Neps", "[", RowBox[{"A", ",", "y", ",", "eps"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Length", "[", "Ny", "]"}], ">", "1"}], "&&", RowBox[{ RowBox[{"Length", "[", "Ny", "]"}], "<", " ", "MinPts"}]}], ",", RowBox[{"SE", "=", RowBox[{"Union", "[", RowBox[{"SE", ",", "Ny"}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "Ny", "]"}], "\[GreaterEqual]", " ", "MinPts"}], ",", RowBox[{ RowBox[{"NeB", "=", RowBox[{"Intersection", "[", RowBox[{"B", ",", "Ny"}], "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"PP", "=", RowBox[{"Union", "[", RowBox[{"PP", ",", "NeB"}], "]"}]}], ";", "\[IndentingNewLine]", "\t\t ", RowBox[{"B", "=", RowBox[{"Complement", "[", RowBox[{"B", ",", "Ny"}], "]"}]}], ";", " ", "\[IndentingNewLine]", " ", RowBox[{"SN", "=", RowBox[{"Complement", "[", RowBox[{"SN", ",", "Ny"}], "]"}]}], ";", " ", "\[IndentingNewLine]", " ", RowBox[{"Qu", "=", RowBox[{"Union", "[", RowBox[{"Qu", ",", RowBox[{"Complement", "[", RowBox[{"Ny", ",", "S"}], "]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", " ", "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"Qu", "=", RowBox[{"Complement", "[", RowBox[{"Qu", ",", RowBox[{"{", "y", "}"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", " ", "]"}], ";"}]}], " ", "\[IndentingNewLine]", " ", "]"}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"PP", ",", "SE", ",", "SN", ",", "xx"}], "}"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellChangeTimes->{{3.6818871750342913`*^9, 3.681887175674947*^9}, { 3.6818873070719523`*^9, 3.681887307462596*^9}, {3.6818875240356092`*^9, 3.6818875426771393`*^9}, {3.6818875867574043`*^9, 3.681887588288729*^9}, { 3.6818877349052305`*^9, 3.681887735483382*^9}, {3.6818878058774195`*^9, 3.6818878075025043`*^9}, {3.681888316090351*^9, 3.6818883190592403`*^9}, 3.681888580243792*^9, {3.681889152201496*^9, 3.6818891678338327`*^9}, { 3.6818893894887886`*^9, 3.6818894094585075`*^9}, 3.6818895315581827`*^9, { 3.6820012864741335`*^9, 3.6820012882710943`*^9}, {3.683164145491889*^9, 3.6831641476482487`*^9}, {3.683266625980114*^9, 3.6832666334805355`*^9}, { 3.683269236014386*^9, 3.6832692399677114`*^9}, {3.6832726537354436`*^9, 3.683272661767118*^9}, {3.6832762992737346`*^9, 3.683276301117585*^9}, { 3.6832765534041023`*^9, 3.6832765548756094`*^9}, {3.6832767613150883`*^9, 3.6832767630144873`*^9}, {3.6832769499953704`*^9, 3.6832769616690607`*^9}, 3.6835484998536077`*^9, {3.6835487909300084`*^9, 3.683548791211273*^9}, { 3.6835494833068275`*^9, 3.683549483603717*^9}, {3.683550192588665*^9, 3.6835502376376925`*^9}, 3.683550543949195*^9, {3.683558353337017*^9, 3.68355836797832*^9}, {3.6835959744272146`*^9, 3.6835959796462145`*^9}, { 3.6835967475759783`*^9, 3.6835967492479324`*^9}, {3.686228956964752*^9, 3.6862289810284023`*^9}, {3.803450670986514*^9, 3.803450685344137*^9}, { 3.8061947465616293`*^9, 3.806194752796327*^9}, {3.806196737774179*^9, 3.8061967398605347`*^9}, {3.806196781848212*^9, 3.8061968218202915`*^9}, { 3.8061973755370502`*^9, 3.8061973946801796`*^9}, {3.806197558652356*^9, 3.8061975605196776`*^9}, {3.806197753313589*^9, 3.8061977561965466`*^9}, { 3.8061986989671764`*^9, 3.8061987003786135`*^9}, {3.8061988078933525`*^9, 3.8061988100481844`*^9}, 3.806217900462427*^9}, ExpressionUUID -> "e67351cd-a2e9-4163-9b64-9d17e2dd8440"] }, Open ]] }, WindowSize->{670, 374}, WindowMargins->{{0, Automatic}, {Automatic, 3}}, 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, 340, 5, 39, "Subsubsection"], Cell[923, 29, 2709, 94, 85, "Text"], Cell[3635, 125, 7348, 161, 506, "Input"] }, Open ]] } ] *)