cdlib.readwrite.write_lifecycle_json¶
- cdlib.readwrite.write_lifecycle_json(lifecycle: LifeCycle, path: str, compress: bool = False)¶
Save lifecycle structure to JSON file.
- Parameters:
lifecycle – a LifeCycle object
path – output filename
compress – wheter to copress the JSON, default False
- Returns:
a JSON formatted string representing the object
- 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")