-
Notifications
You must be signed in to change notification settings - Fork 3
/
feta.py
92 lines (77 loc) · 2.87 KB
/
feta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import warnings
warnings.filterwarnings("ignore")
from json import JSONEncoder
class FetaObject:
def __init__(self,data,action,obms=None,operation=None):
self.Data = data
self.Action = action
self.ObjectModel = obms
self.OperationModel = operation
class DataObject:
def __init__(self,infile, intype="NNT", outtype="NNT", outfile = None, directed=False, sampled=False, sampleprop=1.0):
self.GraphInputFile=infile
self.GraphInputType=intype
self.GraphOutputType=outtype
self.GraphOutputFile=outfile
self.Directed=directed
self.SampleIncomingGraph=sampled
self.SampleProportion=sampleprop
class Action:
def __init__(self,fmm=None,grow=None, measure=None):
self.FitMixedModel = fmm
self.Grow = grow
self.Measure = measure
class Measure:
def __init__(self, start, end, interval, fname, stats = ["NoNodes", "NoLinks", "AverageDegree", "MaxDegree","Singletons","MeanSquaredDegree", "Assortativity", "Clustering", "TriangleCount"]):
self.Start = start
self.MaxTime = end
self.Interval = interval
self.Statistics = stats
self.FileName = fname
class Grow:
def __init__(self, start, end=None, maxnodes=None, interval=10000):
self.Start = start
self.MaxTime = end
self.MaxNodes= maxnodes
self.Interval = interval
class FitMixedModel:
def __init__(self, start, end, interval, granularity=100, debug = False):
self.StartTime = start
self.MaxTime = end
self.Interval = interval
self.Granularity = granularity
self.DebugMode = debug
class OperationModel:
def __init__(self, name, start=None, file=None, initialdeg=None):
self.Name = name
self.Start = start
self.FileName = file
self.InitialDegree=initialdeg
class ObjectModel:
def __init__(self, start, end, components):
self.Start = start
self.End = end
self.Components = components
class ObjectModelComponent:
def __init__(self, name, weight=None):
self.ComponentName = name
self.Weight = weight
class FetaEncoder(JSONEncoder):
def default(self,o):
d = o.__dict__
return del_none(d)
def del_none(d):
"""
Delete keys with the value ``None`` in a dictionary, recursively.
This alters the input so you may wish to ``copy`` the dict first.
"""
# For Python 3, write `list(d.items())`; `d.items()` won’t work
# For Python 2, write `d.items()`; `d.iteritems()` won’t work
for key, value in list(d.items()):
if value is None:
del d[key]
elif isinstance(value, dict):
del_none(value)
return d # For convenience
###
name_to_model = {"Degree":"DegreeModelComponent", "Random":"RandomAttachment", "TriangleClosure": "TriangleClosure", "TriangleClosure2":"TriangleClosure2"}