Skip to content

Commit

Permalink
Add code to skip random neighborhood in NCP
Browse files Browse the repository at this point in the history
  • Loading branch information
dgleich committed Nov 6, 2018
1 parent d05e389 commit 865c97e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 13 additions & 5 deletions localgraphclustering/ncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def approxPageRank(self,
localmin_ratio: float = 0.5,
neighborhood_ratio: float = 0.1,
neighborhoods: bool = True,
random_neighborhoods: bool = True,
timeout: float = 1000,
spectral_args: Dict = {},
deep: bool = False,
Expand Down Expand Up @@ -481,10 +482,14 @@ def approxPageRank(self,
del kwargs['ratio']

deeptimeout = timeout # save the timeout in case we also run the deep params
nruns = 1
if random_neighborhoods:
nruns += 1
if localmins:
nruns += 1

log = SimpleLogForLongComputations(120, "approxPageRank:%s"%(methodname))


if neighborhoods:
self.add_random_neighborhood_samples(
method=_evaluate_set,
Expand All @@ -501,9 +506,11 @@ def approxPageRank(self,
methodname="%s_localmin:rho=%.0e"%(methodname, rho*10),
neighborhoods=True,
ratio=localmin_ratio,
timeout=timeout/(3*len(rholist)),**kwargs)
timeout=timeout/(nruns*len(rholist)),**kwargs)
log.log("localmin rho=%.1e"%(rho))
timeout -= timeout/3 # reduce the time left...
timeout -= timeout/nruns # reduce the time left...
nruns -= 1


for rho in rholist:
if myratio is not None:
Expand All @@ -512,10 +519,10 @@ def approxPageRank(self,
method=functools.partial(
spectral_clustering,**spectral_args,alpha=alpha,rho=rho,method=method),
methodname="%s:rho=%.0e"%(methodname, rho),
timeout=timeout/(2*len(rholist)), **kwargs)
timeout=timeout/(nruns*len(rholist)), **kwargs)
log.log("random_node rho=%.1e"%(rho))

timeout -= timeout/2 # reduce the time left...
timeout -= timeout/nruns # reduce the time left...

for rho in rholist:
if myratio is not None:
Expand Down Expand Up @@ -549,6 +556,7 @@ def approxPageRank(self,
self.approxPageRank(gamma=deepgamma,rholist=deeprhos,
localmins=localmins, localmin_ratio=localmin_ratio,
neighborhoods=False, neighborhood_ratio=neighborhood_ratio,
random_neighborhoods=random_neighborhoods,
timeout = deeptimeout, spectral_args=spectral_args, deep=False,
methodname_prefix=deepmethodname_prefix,
**kwargs)
Expand Down
4 changes: 4 additions & 0 deletions localgraphclustering/tests/test_ncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def test_ncp_sets():
def test_apr_deep():
G = load_example_graph()
df = lgc.NCPData(G).approxPageRank(ratio=1, gamma=0.1, rholist=[1e-2, 1e-3], deep=True)

def test_apr_only_node_samples():
G = load_example_graph()
df = lgc.NCPData(G).approxPageRank(ratio=1, gamma=0.1, rholist=[1e-2, 1e-3], random_neighborhoods=False, localmins=False)

@pytest.mark.long_tests
def test_ncp_crd_big():
Expand Down

0 comments on commit 865c97e

Please sign in to comment.