Skip to content

Commit

Permalink
cleaning one of the notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
smautner committed Aug 30, 2015
1 parent 3adc5bf commit 8530739
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions graphlearn/graphlearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def sample(self, graph_iter,

similarity=-1,
n_samples=None,
estimate_flowback = False,
batch_size=10,
n_jobs=0,
max_cycle_size=False,
Expand All @@ -168,6 +169,7 @@ def sample(self, graph_iter,
select_cip_max_tries=20,
burnin=0,


generator_mode=False,
omit_seed=True,
keep_duplicates=False):
Expand All @@ -188,7 +190,7 @@ def sample(self, graph_iter,
:param n_steps: how many samplesteps are conducted
:param burnin: do this many steps before collecting samples
:param max_cycle_size: max allowed size (slow)
:estimate_flowback: True to calculate new and old options
# sampling strategy
:param target_orig_cip: we will use the estimator to determine weak regions in the graph that need
improvement
Expand All @@ -210,6 +212,12 @@ def sample(self, graph_iter,
:return: yield graphs
"""
self.estimate_backflow = estimate_flowback
if self.estimate_backflow:
print 'WARNING you set estimate backflow. the implementation is a little sketchy ' \
'so dont try this with weired graphs. '



self.similarity = similarity

Expand Down Expand Up @@ -404,7 +412,6 @@ def _sample_init(self, graph):
graph = self.vectorizer._edge_to_vertex_transform(graph)
if self.max_core_size_diff > -1:
self.seed_size = len(graph)

self._score(graph)
self._sample_notes = ''
self._sample_path_score_set = set()
Expand Down Expand Up @@ -522,16 +529,50 @@ def _propose_graph(self, graph):
graph_new = core_substitution(graph, original_cip.graph, candidate_cip.graph)

if self.feasibility_checker.check(graph_new):


graph_clean(graph_new)
# postproc may fail
tmp= self.postprocessor.postprocess(graph_new)
if tmp:
self.reverse_direction_probability(graph,tmp,original_cip)
logger.debug("_propose_graph: iteration %d ; core %d of %d ; original_cips tried %d" %
(self.step, attempt, choices, orig_cip_ctr))


return tmp
if self.quick_skip_orig_cip:
break

def reverse_direction_probability(self,graph,graph_new,cip):

# it is sufficient to look at the old cip, since the interface ids shoud be the same in the new graph..


def ops(g,cip):
# possible operations for stuff
counter=0
for n,d in cip.graph.nodes(data=True):
if 'edge' not in d and 'interface' in d:
cip=extract_core_and_interface(n, g, [cip.thickness], [cip.radius], vectorizer=self.vectorizer,
hash_bitmask=self.hash_bitmask, filter=self.node_entity_check)
if cip:
cip=cip[0]
if cip.interface_hash in self.lsgg.productions:
counter+=len(self.lsgg.productions[cip.interface_hash])
return counter

if self.estimate_backflow:
value=len(graph) / float(len(graph_new))
print 'flow1: %f' % value
one=ops(graph, cip)
two=ops(graph_new,cip)
print one,two
value+= one/float(two)
graph.graph['flowback'] = value
print 'flow: %f' % value


def _select_cips(self, cip, graph):
"""
:param cip: the cip we selected from the graph
Expand Down

0 comments on commit 8530739

Please sign in to comment.