(* 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[ 18670, 486] NotebookOptionsPosition[ 18304, 469] NotebookOutlinePosition[ 18652, 484] CellTagsIndexPosition[ 18609, 481] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["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}, 3.820980206495015*^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["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]", ")"}]}]}], ";", RowBox[{ "The", " ", "algorithm", " ", "can", " ", "use", " ", "data", " ", "sets", " ", "from", " ", RowBox[{"DataDiscs", ".", "txt"}]}]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"DataGenCirc", ".", "txt"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"DataEllipseGarland", ".", "txt"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"Coral", ".", "txt"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"constructed", " ", "using", " ", "modules", " ", RowBox[{"DataCircle", "[", "]"}]}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"DataOval", "[", "]"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"DataCAoval", "[", "]"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"DataEllipseGarland", "[", "]"}], ";"}], 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[{ "partition", " ", "\[CapitalPi]", " ", "of", " ", "the", " ", "set", " ", "\[ScriptCapitalA]", " ", "with", " ", "marked", " ", "border", " ", "points", " ", StyleBox["SSE", FontSlant->"Italic"], StyleBox[" ", FontSlant->"Italic"], "and", " ", "outliers", " ", StyleBox["SSN", FontSlant->"Italic"]}], 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[{"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]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{"CorePoint", "[", "]"}], FontColor->RGBColor[0, 0, 1]], StyleBox[",", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[ RowBox[{ RowBox[{"DBSCAN1", "[", "]"}], ";"}], FontColor->RGBColor[0, 0, 1]]}], StyleBox[" ", FontColor->RGBColor[0, 0, 1]]}], "\[IndentingNewLine]"}], "Text", CellChangeTimes->{{3.8209796424920626`*^9, 3.8209797447167287`*^9}, { 3.8209797931301317`*^9, 3.8209798365128937`*^9}, {3.820980233508868*^9, 3.8209802824888935`*^9}, {3.8209803328403125`*^9, 3.820980346841185*^9}, { 3.820980403069928*^9, 3.820980429439943*^9}, {3.8209804595295043`*^9, 3.8209804643116508`*^9}, {3.8223059650548844`*^9, 3.822305974589098*^9}, { 3.8223060157480307`*^9, 3.822306027634097*^9}}, ExpressionUUID -> "c662ff0b-0295-4ce5-842c-b9894886a7ad"], Cell[BoxData[ RowBox[{ RowBox[{"DBSCAN", "[", RowBox[{"A_", ",", "MinPts_", ",", "eps_", ",", RowBox[{"Ind_:", "0"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"kk", "=", "0"}], ",", RowBox[{"It0", "=", RowBox[{".1", RowBox[{"Length", "[", "A", "]"}]}]}], ",", RowBox[{"TH", "=", RowBox[{".1", " ", RowBox[{"Length", "[", "A", "]"}]}]}], ",", RowBox[{"time", "=", "0"}], ",", "B", ",", "cp", ",", "PPP", ",", "PP", ",", "SPP", ",", "SE", ",", "SSN"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"PPP", "=", RowBox[{"SSN", "=", RowBox[{"SSE", "=", RowBox[{"SPP", "=", RowBox[{"{", "}"}]}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{"B", "=", "A"}], ";", " ", RowBox[{"TH", "=", RowBox[{".01", " ", RowBox[{"Length", "[", "A", "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "B", "]"}], ">", RowBox[{"TH", " ", "MinPts"}]}], ",", RowBox[{ RowBox[{"kk", "=", RowBox[{"kk", "+", "1"}]}], ";", RowBox[{"cp", "=", RowBox[{"CorePoint", "[", RowBox[{"B", ",", "eps", ",", "It0"}], "]"}]}], ";", RowBox[{"If", "[", RowBox[{ RowBox[{"Ind", "\[NotEqual]", "0"}], ",", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "cp"}], "]"}]}], "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"dbran", "=", RowBox[{ RowBox[{"DBSCAN1", "[", RowBox[{"B", ",", RowBox[{"cp", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "MinPts", ",", "eps"}], "]"}], "//", "Timing"}]}], ";", "\[IndentingNewLine]", RowBox[{"PP", "=", RowBox[{"dbran", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}]}], ";", RowBox[{"Border", "=", RowBox[{"dbran", "[", RowBox[{"[", RowBox[{"2", ",", "2"}], "]"}], "]"}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"SPP", "=", RowBox[{"Append", "[", RowBox[{"SPP", ",", "PP"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Noise", "=", RowBox[{"dbran", "[", RowBox[{"[", RowBox[{"2", ",", "3"}], "]"}], "]"}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"time", "=", RowBox[{"time", "+", RowBox[{"dbran", "[", RowBox[{"[", "1", "]"}], "]"}]}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"B", "=", RowBox[{"Complement", "[", RowBox[{"B", ",", RowBox[{"Union", "[", RowBox[{"PP", ",", "Border", ",", "Noise"}], "]"}]}], "]"}]}], ";", " ", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Ind", "\[NotEqual]", "0"}], ",", RowBox[{"Print", "[", RowBox[{"kk", ",", "\"\<. izabrana to\[CHacek]ka cp: \>\"", ",", RowBox[{"cp", "[", RowBox[{"[", "1", "]"}], "]"}], ",", "\"\<; |Cp|=\>\"", ",", RowBox[{"cp", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "\"\<; |PP|=\>\"", ",", RowBox[{"Length", "[", "PP", "]"}], ",", "\"\<; |Border|= \>\"", ",", RowBox[{"Length", "[", "Border", "]"}], ",", "\"\<; |B|=\>\"", ",", RowBox[{"Length", "[", "B", "]"}], ",", "\"\<; Time(DBRAN)=\>\"", ",", "time"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Izabrani", " ", "cluster"}], " ", "+", " ", RowBox[{"Ostatak", " ", "skupa"}], " ", "-", " ", RowBox[{ "mo\[ZHacek]e", " ", "se", " ", "uklju\[CHacek]iti", " ", "\[IndentingNewLine]", "slizbor"}]}], "=", RowBox[{"ListPlot", "[", RowBox[{"B", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Blue", ",", RowBox[{"PointSize", "[", ".005", "]"}]}], "}"}]}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", RowBox[{"PlotRange", "\[Rule]", "AG"}], ",", RowBox[{"PlotLabel", "->", "\"\\""}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"slPP", "=", RowBox[{"ListPlot", "[", RowBox[{"PP", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Blue", ",", RowBox[{"PointSize", "[", ".001", "]"}]}], "}"}]}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", RowBox[{"PlotRange", "\[Rule]", "AG"}], ",", RowBox[{"PlotLabel", "->", "\"\\""}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"GraphicsGrid", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{"slPP", ",", "slizbor"}], "}"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Medium"}]}], "]"}], "]"}], ";"}], "\[IndentingNewLine]", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Ind", "\[NotEqual]", "0"}], ",", RowBox[{"Print", "[", RowBox[{"Show", "[", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{"SPP", ",", "1"}], "]"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Gray", ",", RowBox[{"PointSize", "[", ".001", "]"}]}], "}"}]}]}], "]"}], ",", RowBox[{"ListPlot", "[", RowBox[{"B", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Blue", ",", RowBox[{"PointSize", "[", ".005", "]"}]}], "}"}]}]}], "]"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", RowBox[{"PlotRange", "\[Rule]", "AG"}], " ", ",", RowBox[{"Frame", "\[Rule]", "True"}], ",", RowBox[{"AxesOrigin", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"AG", "[", RowBox[{"[", RowBox[{"1", ",", "1"}], "]"}], "]"}], ",", RowBox[{"AG", "[", RowBox[{"[", RowBox[{"2", ",", "1"}], "]"}], "]"}]}], "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", "Small"}]}], "]"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"PPP", "=", RowBox[{"AppendTo", "[", RowBox[{"PPP", ",", "PP"}], "]"}]}], ";", " ", RowBox[{"SSE", "=", RowBox[{"Append", "[", RowBox[{"SSE", ",", "Border"}], "]"}]}], ";", RowBox[{"SSN", "=", RowBox[{"Append", "[", RowBox[{"SSN", ",", "Noise"}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"SSN", "=", RowBox[{"Complement", "[", RowBox[{"A", ",", RowBox[{"Flatten", "[", RowBox[{"PPP", ",", "1"}], "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"\"\<|PPP| = \>\"", ",", RowBox[{"Sum", "[", RowBox[{ RowBox[{"Length", "[", RowBox[{"PPP", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "PPP", "]"}]}], "}"}]}], "]"}], ",", "\"\< od toga |SSE| = \>\"", ",", RowBox[{"Sum", "[", RowBox[{ RowBox[{"Length", "[", RowBox[{"SSE", "[", RowBox[{"[", "j", "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", RowBox[{"Length", "[", "SSE", "]"}]}], "}"}]}], "]"}], ",", "\"\<; |SSN| = \>\"", ",", RowBox[{"Length", "[", "SSN", "]"}], ",", " ", "\"\<; TOTAL[A] = \>\"", ",", RowBox[{"Length", "[", "A", "]"}], ",", "\"\<; Total[time]=\>\"", ",", "time"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"slPPP", "=", RowBox[{"ListPlot", "[", RowBox[{"Flatten", "[", RowBox[{"PPP", ",", "1"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"slSN", "=", RowBox[{"ListPlot", "[", RowBox[{"SSN", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Red", ",", RowBox[{"PointSize", "[", ".025", "]"}]}], "}"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"slSE", "=", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{"SSE", ",", "1"}], "]"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Brown", ",", RowBox[{"PointSize", "[", ".02", "]"}]}], "}"}]}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"sl1", "=", RowBox[{"ListPlot", "[", RowBox[{"PPP", ",", " ", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"Frame", "\[Rule]", "True"}], ",", RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", RowBox[{"PlotRange", "\[Rule]", "AG"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"sl2", "=", RowBox[{"Show", "[", RowBox[{"sl1", ",", "slSN", ",", "slSE", ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"Frame", "\[Rule]", "True"}], ",", RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", RowBox[{"PlotRange", "\[Rule]", "AG"}], ",", RowBox[{"ImageSize", "\[Rule]", "Small"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", "sl2", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Print", "[", RowBox[{"GraphicsGrid", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{"sl1", ",", "sl2"}], "}"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Medium"}]}], "]"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"PPP", ",", "SSE", ",", "SSN"}], "}"}]}]}], "\[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, {3.820980172390957*^9, 3.82098017513669*^9}}, ExpressionUUID -> "e67351cd-a2e9-4163-9b64-9d17e2dd8440"] }, 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, 347, 5, 39, "Subsubsection"], Cell[930, 29, 4480, 146, 142, "Text"], Cell[5413, 177, 12875, 289, 620, "Input"] }, Open ]] } ] *)