Skip to content

Commit

Permalink
Merge pull request #107 from LucaCappelletti94/updated_BoostNE
Browse files Browse the repository at this point in the history
Resolved compatibility issue with sklearn in BoostNE
  • Loading branch information
benedekrozemberczki authored Aug 10, 2022
2 parents 5202541 + b2aec9c commit ff89009
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions karateclub/node_embedding/neighbourhood/boostne.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import math
import random
import numpy as np
import networkx as nx
from scipy import sparse
from sklearn.decomposition import NMF
from karateclub.estimator import Estimator
from inspect import getfullargspec


class BoostNE(Estimator):
Expand Down Expand Up @@ -128,9 +127,34 @@ def _fit_and_score_NMF(self, new_residuals):
* **scores** *(COO Scipy matrix)* - The residual scores.
* **W** *(Numpy array)* - The embedding matrix.
"""
model = NMF(
n_components=self.dimensions, init="random", verbose=False, alpha=self.alpha
)

parameter_names = getfullargspec(NMF).args

if "alpha" in parameter_names:
model = NMF(
n_components=self.dimensions,
init="random",
alpha=self.alpha,
verbose=False,
)
elif "alpha_W" in parameter_names:
model = NMF(
n_components=self.dimensions,
init="random",
alpha_W=self.alpha,
verbose=False,
)
else:
raise NotImplementedError(
"The version of Scikit-learn installed "
"on this device is not currently supported. "
"More specifically, in older version of the NMF "
"method a parameter called `alpha` was available "
"and it has been replaced with a second parameter "
"called `alpha_W`. In the installed version neither "
"parameters were found, and it is therefore unclear "
"as to how we should proceed."
)

W = model.fit_transform(new_residuals)
H = model.components_
Expand Down

0 comments on commit ff89009

Please sign in to comment.