cdlib.readwrite.read_lifecycle_json

cdlib.readwrite.read_lifecycle_json(path: str, compress: bool = False) object

从JSON文件读取生命周期。

Parameters:
  • path – 输入文件名

  • compress – 文件是否为压缩格式,默认为 False

Returns:

一个生命周期对象

Example:

>>> from cdlib import LifeCycle, TemporalClustering
>>> from cdlib import algorithms
>>> from networkx.generators.community import LFR_benchmark_graph
>>> from cdlib.readwrite import write_lifecycle_json, read_lifecycle_json
>>> tc = TemporalClustering()
>>> for t in range(0, 10):
>>>     g = LFR_benchmark_graph(
>>>             n=250,
>>>             tau1=3,
>>>             tau2=1.5,
>>>             mu=0.1,
>>>             average_degree=5,
>>>             min_community=20,
>>>             seed=10,
>>>     )
>>>     coms = algorithms.louvain(g)  # here any CDlib algorithm can be applied
>>>     tc.add_clustering(coms, t)
>>>
>>> events = LifeCycle(tc)
>>> events.compute_events("facets")
>>> write_lifecycle_json(events, "lifecycle.json")
>>> events = read_lifecycle_json("lifecycle.json")