MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / Edge

Class Edge

numpy_ml/utils/graphs.py:12–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class Edge(object):
13 def __init__(self, fr, to, w=None):
14 """
15 A generic directed edge object.
16
17 Parameters
18 ----------
19 fr: int
20 The id of the vertex the edge goes from
21 to: int
22 The id of the vertex the edge goes to
23 w: float, :class:`Object` instance, or None
24 The edge weight, if applicable. If weight is an arbitrary Object it
25 must have a method called 'sample' which takes no arguments and
26 returns a random sample from the weight distribution. If `w` is
27 None, no weight is assumed. Default is None.
28 """
29 self.fr = fr
30 self.to = to
31 self._w = w
32
33 def __repr__(self):
34 return "{} -> {}, weight: {}".format(self.fr, self.to, self._w)
35
36 @property
37 def weight(self):
38 return self._w.sample() if hasattr(self._w, "sample") else self._w
39
40 def reverse(self):
41 """Reverse the edge direction"""
42 return Edge(self.t, self.f, self.w)
43
44
45#######################################################################

Callers 4

from_networkxFunction · 0.90
reverseMethod · 0.85
random_unweighted_graphFunction · 0.85

Calls

no outgoing calls

Tested by 1

from_networkxFunction · 0.72