-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from sjsrey/spenc
Add spenc as a lib rather than using via an import
- Loading branch information
Showing
6 changed files
with
701 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
from ..BaseClass import BaseSpOptHeuristicSolver | ||
import numpy as np | ||
from warnings import warn | ||
from spenc import SPENC | ||
from .spenclib import SPENC | ||
|
||
|
||
class Spenc(BaseSpOptHeuristicSolver): | ||
""" | ||
Spatially encouraged spectral clustering. | ||
:cite:`wolf2018` | ||
""" | ||
def __init__(self, gdf, w, attrs_name, n_clusters=5, random_state=None, gamma=1): | ||
""" | ||
Parameters | ||
---------- | ||
gdf : geopandas.GeoDataFrame | ||
w : libpywal.weights.W instance | ||
spatial weights matrix | ||
attrs_name : list | ||
Strings for attribute names (cols of ``geopandas.GeoDataFrame``). | ||
n_clusters : int, optional, default: 5 | ||
The number of clusters to form. | ||
gamma: int, default:1 | ||
""" | ||
self.gdf = gdf | ||
self.w = w | ||
self.attrs_name = attrs_name | ||
self.n_clusters = n_clusters | ||
self.gamma = gamma | ||
self.random_state = random_state | ||
|
||
def solve(self): | ||
"""Solve the spenc""" | ||
data = self.gdf | ||
X = data[self.attrs_name].values | ||
#_import_tryer("spenc", "SPENC", "spenc") | ||
model = SPENC(n_clusters=self.n_clusters, random_state=self.random_state, gamma=self.gamma) | ||
model.fit(X, self.w.sparse) | ||
self.labels_ = model.labels_ | ||
""" | ||
Spatially encouraged spectral clustering. | ||
:cite:`wolf2018` | ||
""" | ||
|
||
def __init__(self, gdf, w, attrs_name, n_clusters=5, random_state=None, | ||
gamma=1): | ||
""" | ||
Parameters | ||
---------- | ||
gdf : geopandas.GeoDataFrame | ||
w : libpywal.weights.W instance | ||
spatial weights matrix | ||
attrs_name : list | ||
Strings for attribute names (cols of ``geopandas.GeoDataFrame``). | ||
n_clusters : int, optional, default: 5 | ||
The number of clusters to form. | ||
gamma: int, default:1 | ||
""" | ||
self.gdf = gdf | ||
self.w = w | ||
self.attrs_name = attrs_name | ||
self.n_clusters = n_clusters | ||
self.gamma = gamma | ||
self.random_state = random_state | ||
|
||
def solve(self): | ||
"""Solve the spenc""" | ||
data = self.gdf | ||
X = data[self.attrs_name].values | ||
model = SPENC(n_clusters=self.n_clusters, | ||
random_state=self.random_state, | ||
gamma=self.gamma) | ||
model.fit(X, self.w.sparse) | ||
self.labels_ = model.labels_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .abstracts import SPENC |
Oops, something went wrong.