Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
0beaf5bb
Commit
0beaf5bb
authored
Apr 14, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using OPTICS clustering instead of DBSCAN
parent
54a425e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
clusterer.py
...ction-microservice/app/processing/clustering/clusterer.py
+2
-2
run_clustering.py
...ub/community-detection-microservice/app/run_clustering.py
+10
-2
No files found.
src/data-hub/community-detection-microservice/app/processing/clustering/clusterer.py
View file @
0beaf5bb
import
json
import
json
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
sklearn.cluster
import
DBSCAN
from
sklearn.cluster
import
DBSCAN
,
OPTICS
from
typing
import
List
,
Dict
,
Any
,
TypeVar
from
typing
import
List
,
Dict
,
Any
,
TypeVar
from
deprecated
import
deprecated
from
deprecated
import
deprecated
...
@@ -59,7 +59,7 @@ class Clusterer:
...
@@ -59,7 +59,7 @@ class Clusterer:
if
features
is
None
or
len
(
features
)
==
0
:
if
features
is
None
or
len
(
features
)
==
0
:
return
features
# trash in trash out
return
features
# trash in trash out
dbsc
=
DBSCAN
(
eps
=
self
.
epsilon
,
min_samples
=
self
.
min_points
)
dbsc
=
OPTICS
()
#
DBSCAN(eps = self.epsilon, min_samples = self.min_points)
dbsc
=
dbsc
.
fit
(
features
)
dbsc
=
dbsc
.
fit
(
features
)
labels
=
dbsc
.
labels_
labels
=
dbsc
.
labels_
...
...
src/data-hub/community-detection-microservice/app/run_clustering.py
View file @
0beaf5bb
...
@@ -4,6 +4,7 @@ modules_path = '../../../modules/'
...
@@ -4,6 +4,7 @@ modules_path = '../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
sys
.
path
.
insert
(
1
,
modules_path
)
import
json
from
db.entities
import
*
from
db.entities
import
*
from
typing
import
List
,
Dict
,
Tuple
from
typing
import
List
,
Dict
,
Tuple
from
db.repository
import
Repository
,
AgiRepository
from
db.repository
import
Repository
,
AgiRepository
...
@@ -21,11 +22,13 @@ def run_generic_clustering():
...
@@ -21,11 +22,13 @@ def run_generic_clustering():
all_layers
:
List
[
Layer
]
=
repo
.
get_layers
()
all_layers
:
List
[
Layer
]
=
repo
.
get_layers
()
for
layer
in
all_layers
:
for
layer
in
all_layers
:
if
layer
.
properties
is
None
or
len
(
layer
.
properties
)
==
0
:
continue
print
(
f
"Clustering {layer.layer_name}"
)
print
(
f
"Clustering {layer.layer_name}"
)
clusters
=
run_clustering_for_layer
(
layer
)
clusters
=
run_clustering_for_layer
(
layer
)
cluster_set
=
ClusterSet
(
layer
.
layer_name
,
clusters
)
cluster_set
=
ClusterSet
(
layer
.
layer_name
,
clusters
)
repo
.
add
_clusterset
(
cluster_set
)
store
_clusterset
(
cluster_set
)
def
run_clustering_for_layer
(
layer
:
Layer
)
->
List
[
Cluster
]:
def
run_clustering_for_layer
(
layer
:
Layer
)
->
List
[
Cluster
]:
...
@@ -38,6 +41,11 @@ def run_clustering_for_layer(layer: Layer) -> List[Cluster]:
...
@@ -38,6 +41,11 @@ def run_clustering_for_layer(layer: Layer) -> List[Cluster]:
return
[
Cluster
(
key
,
value
)
for
key
,
value
in
res
.
items
()]
return
[
Cluster
(
key
,
value
)
for
key
,
value
in
res
.
items
()]
def
store_clusterset
(
cluster_set
:
ClusterSet
):
repo
.
add_clusterset
(
cluster_set
)
# with open(f'clusterset_{cluster_set.layer_name}.txt', 'w') as file:
# file.write(json.dumps(cluster_set.to_serializable_dict()))
def
run_location_clustering
():
def
run_location_clustering
():
user_clusterer
=
Clusterer
()
user_clusterer
=
Clusterer
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment