/// <summary> /// Checks whether the weighted aggregate representation of two temporal networks match /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet match [temporal_network_a] [temporal_network_b]"); return; } string file_1 = args[1]; string file_2 = args[2]; Console.Write("Reading temporal network 1 ..."); TemporalNetwork temp_net_1 = TemporalNetwork.ReadFromFile(file_1); Console.WriteLine("done."); Console.Write("Reading temporal network 1 ..."); TemporalNetwork temp_net_2 = TemporalNetwork.ReadFromFile(file_2); Console.WriteLine("done."); Console.WriteLine("Comparing weighted aggregate networks ..."); WeightedNetwork net_1 = temp_net_1.AggregateNetwork; WeightedNetwork net_2 = temp_net_2.AggregateNetwork; if (net_1.Equals(net_2)) { Console.WriteLine("Both networks are identical."); } else { Console.WriteLine("The networks are NOT identical."); } }
public static void Run(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: TempNet stats [temporal_network_file] [aggregationWindow=1] [undirected=false] [absoluteTime=false]"); return; } bool undirected = false; bool absoluteTime = false; int aggregationWindow = 1; if (args.Length >= 3) { aggregationWindow = Int32.Parse(args[2]); } if (args.Length >= 4) { undirected = Boolean.Parse(args[3]); } if (args.Length >= 5) { absoluteTime = Boolean.Parse(args[4]); } Console.Write("Reading temporal network as {0} network...", undirected?"undirected":"directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], undirected: undirected); Console.WriteLine("done."); int interactions_total = temp_net.EdgeCount; Console.WriteLine("\nOriginal Temporal network"); Console.WriteLine("================="); Console.WriteLine("Number of nodes: \t{0}", temp_net.VertexCount); Console.WriteLine("Number of time steps: \t{0}", temp_net.Length); Console.WriteLine("Number of interactions: \t{0}", interactions_total); Console.WriteLine("Highest granularity \t{0} edges per time step", temp_net.MaxGranularity); Console.WriteLine("Lowest granularity \t{0} edges per time step", temp_net.MinGranularity); temp_net.AggregateTime(aggregationWindow); temp_net.ReduceToTwoPaths(false, absoluteTime); Console.WriteLine("Fraction of two-path interactions \t{0:0.00}", (double)temp_net.AggregateNetwork.CumulativeWeight / (double)interactions_total); Console.WriteLine("\nAggregate network (only nodes and edges contributing to two-paths)"); Console.WriteLine("=================================================================="); Console.WriteLine("Number of nodes: \t{0}", temp_net.AggregateNetwork.VertexCount); Console.WriteLine("Number of interactions: \t{0}", temp_net.AggregateNetwork.CumulativeWeight); Console.WriteLine("Number of two-paths: \t{0}", temp_net.TwoPathCount); Console.WriteLine("Number of edges in aggregate net \t{0}", temp_net.AggregateNetwork.EdgeCount); Console.WriteLine("Max in-degree in aggregate net \t{0}", temp_net.AggregateNetwork.MaxIndeg); Console.WriteLine("Max out-degree in aggregate net \t{0}", temp_net.AggregateNetwork.MaxOutdeg); Console.WriteLine("Max weight in aggregate net \t{0}", temp_net.AggregateNetwork.MaxWeight); Console.WriteLine("Min weight in aggregate net \t{0}", temp_net.AggregateNetwork.MinWeight); Console.WriteLine("Max rel. weight in aggregate net \t{0:0.00000}", (double)temp_net.AggregateNetwork.MaxWeight / (double)temp_net.AggregateNetwork.CumulativeWeight); Console.WriteLine("Min rel. weight in aggregate net \t{0:0.00000}", (double)temp_net.AggregateNetwork.MinWeight / (double)temp_net.AggregateNetwork.CumulativeWeight); }
public void LoadTemporalNetworkTest() { TemporalNetwork net = ExampleData.GetTestNetwork(); TemporalNetwork.SaveToFile("test.net", net); TemporalNetwork net2 = TemporalNetwork.ReadFromFile("test.net"); Assert.AreEqual(net, net2); }
/// <summary> /// Parallely computes the betweenness preference distribution of a given temporal network /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet T2 [temporal_network_file] [output_file] [aggregationWndow=1] [undirected=false]"); return; } string out_file = args[2]; if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } bool undirected = false; int aggregationWindow = 1; if (args.Length >= 4) { aggregationWindow = int.Parse(args[3]); } if (args.Length >= 5) { undirected = Boolean.Parse(args[4]); } Console.Write("Reading temporal network as {0} network...", undirected ? "undirected" : "directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], undirected: undirected); Console.WriteLine(" done."); Console.WriteLine("Applying aggregation window, length = {0}, time steps before = {1}", aggregationWindow, temp_net.Length); temp_net.AggregateTime(aggregationWindow); Console.WriteLine("done, time steps after = {0}", temp_net.Length); Console.Write("Building aggregate networks ..."); temp_net.ReduceToTwoPaths(); Console.WriteLine(" done."); Console.Write("Writing transition matrix ..."); WriteTwopathTransitionMatrix(temp_net, out_file); Console.WriteLine("done."); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("\nUsage: Visualize [network-file] [iterations=50]\n"); return; } string network_file = args[0]; int iterations = args.Length >= 2 ? int.Parse(args[1]) : 50; // Load the temporal and aggregate network Console.Write("Loading temporal network ..."); TemporalNetwork net = TemporalNetwork.ReadFromFile(network_file); Console.WriteLine("done"); Console.Write("Computing aggregate network ..."); WeightedNetwork agg = net.AggregateNetwork; Console.WriteLine("done"); // Change the colors NetworkColorizer colors = new NetworkColorizer(); colors.DefaultBackgroundColor = Color.White; colors.DefaultVertexColor = Color.DarkBlue; colors.DefaultEdgeColor = Color.Black; Renderer.CurvedEdges = true; RenderableTempNet temp_net = new RenderableTempNet(net); // Start rendering ... Renderer.Start(temp_net, new FRLayout(iterations), colors); // Asynchronously compute the layout ... Renderer.Layout.DoLayout(); Application.Run(new VisualizationController(temp_net)); }
public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet filter [temporal_network_original] [filter_file] [temporal_network_new] [undirected=true]"); return; } string file_orig = args[1]; string filter = args[2]; string file_new = args[3]; bool undirected = true; if (args.Length >= 5) { undirected = Boolean.Parse(args[4]); } Console.Write("Reading temporal network as {0} network...", undirected?"undirected":"directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(file_orig, undirected: undirected); Console.WriteLine("done."); string[] filtered_edges = System.IO.File.ReadAllLines(filter); foreach (string x in filtered_edges) { if (x.Contains(";")) { string[] comps = x.Split(';'); temp_net.Remove(new Tuple <string, string>(comps[0], comps[1])); } } TemporalNetwork.SaveToFile(file_new, temp_net); }
/// <summary> /// Runs an SI spreading process on a temporal network and outputs the dynamics of the infection size /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet spreading [temporal_network_file] [output_file]"); return; } string out_file = args[2]; if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network as directed..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1]); // Prevent the network from being reduced to two paths temp_net.StripEdgesToTwoPaths = false; Console.WriteLine("done."); Console.Write("Running SI spreading on temporal network with {0} time steps ...", temp_net.Length); string times = null; string output = SISpreading.RunSpreading(temp_net, out times, 1d); Console.WriteLine(" done."); if (output != null) { Console.Write("Finished path discovery. Writing path length matrix"); System.IO.File.WriteAllText(out_file, output); System.IO.File.WriteAllText(out_file + ".times", times); Console.WriteLine("done."); } }
public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet tikz [temporal_network_file] [output_file]"); return; } string out_file = args[2]; if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network ..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1]); Console.WriteLine("done."); Console.Write("Exporting to tikz..."); TikzExporter.CreateTikzUnfolding(out_file, null, temp_net); Console.WriteLine(" done."); }
public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet visualize [temporal_network_file] [output_png] [square=TRUE] [border=5]"); return; } string out_file = args[2]; bool square = true; int border = 5; if (args.Length >= 4) { square = bool.Parse(args[3]); } if (args.Length >= 5) { border = int.Parse(args[4]); } if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network ..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1]); Console.WriteLine("done."); CreateBitmap(temp_net, out_file, square, border); Console.WriteLine(" done."); }
/// <summary> /// Runs a random walk process on an aggregate networks and outputs the dynamics of the infection size /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet rw [network_file] [output_file] [RWMode=static_first] [aggregationWindow=1] [steps=1000]"); Console.WriteLine("\t where RWMode can be ... "); Console.WriteLine("\t static_first\t Performs a random walk on the aggregate network that considers betweenness preferences computed from the temporal network"); Console.WriteLine("\t static_second\t ..."); return; } string out_file = args[2]; RandomWalkMode mode = RandomWalkMode.StaticFirstOrder; int runs = 1; int length = 1000; int aggregationWindow = 1; if (args.Length >= 4) { if (args[3] == "static_second") { mode = RandomWalkMode.StaticSecondOrder; } else { Console.WriteLine("Unknown walk mode '{0}'", args[3]); } } if (args.Length >= 5) { aggregationWindow = int.Parse(args[4]); } if (args.Length >= 6) { runs = int.Parse(args[5]); } if (args.Length >= 7) { length = int.Parse(args[6]); } if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network as undirected network..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], true); Console.WriteLine("done."); if (aggregationWindow != 1) { Console.WriteLine("Applying aggregation window, length = {0}, time steps before = {1}", aggregationWindow, temp_net.Length); temp_net.AggregateTime(aggregationWindow); Console.WriteLine("done, time steps after = {0}", temp_net.Length); } Console.Write("Building aggregate network..."); WeightedNetwork aggregateNet = temp_net.AggregateNetwork; Console.WriteLine("done."); Console.WriteLine("Starting random walk ..."); Dictionary <int, double> tvd = new Dictionary <int, double>(); RandomWalk walk = new RandomWalk(temp_net, mode); for (int t = 0; t < length; t++) { walk.Step(); tvd[t] = walk.TVD; Console.WriteLine("Node = {0}, step = {1}, tvd={2:0.000}", walk.CurrentNode, t, tvd[t]); } Console.Write("Writing time series of total variation distance ..."); StringBuilder sb = new StringBuilder(); foreach (var step in tvd) { sb.AppendLine(string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat, "{0} {1}", step.Key, step.Value)); } System.IO.File.WriteAllText(out_file + ".dat", sb.ToString()); Console.WriteLine(" done."); }
/// <summary> /// Parallely computes the betweenness preference distribution of a given temporal network /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet distribution [temporal_network_file] [output_file] [aggregationWndow=1] [undirected=false]"); return; } string out_file = args[2]; if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } bool undirected = false; int aggregationWindow = 1; if (args.Length >= 4) aggregationWindow = int.Parse(args[3]); if (args.Length >= 5) undirected = Boolean.Parse(args[4]); Console.Write("Reading temporal network as {0} network...", undirected ? "undirected" : "directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], undirected:undirected); Console.WriteLine(" done."); Console.WriteLine("Applying aggregation window, length = {0}, time steps before = {1}", aggregationWindow, temp_net.Length); temp_net.AggregateTime(aggregationWindow); Console.WriteLine("done, time steps after = {0}", temp_net.Length); Console.Write("Preparing temporal network ..."); temp_net.ReduceToTwoPaths(); Console.WriteLine(" done."); double nodeNum = temp_net.AggregateNetwork.VertexCount; double current = 0d; double last_perc = 0d; Console.WriteLine("Computing betweenness preference for {0} nodes ...", nodeNum); // Parallely compute betweenness preference for all nodes #if DEBUG foreach(string v in temp_net.AggregateNetwork.Vertices) #else Parallel.ForEach<string>(temp_net.AggregateNetwork.Vertices, v => #endif { double betweennessPref = BetweennessPref.GetBetweennessPref(temp_net, v); // Synchronized access to file and to counters ... if(temp_net.AggregateNetwork.GetIndeg(v)>0 && temp_net.AggregateNetwork.GetOutdeg(v)>0) lock (out_file) { System.IO.File.AppendAllText(out_file, v + " " + string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat, "{0:0.000000}\n", betweennessPref)); current++; if (100 * current / nodeNum >= last_perc + 5d) { last_perc = 100 * current / nodeNum; Console.WriteLine("Completed for {0} nodes [{1:0.0} %]", current, last_perc); } } } #if !DEBUG ); #endif Console.WriteLine("done."); }
/// <summary> /// Runs a random walk process on an aggregate networks and outputs the dynamics of the infection size /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet rw [network_file] [output_file] [WalkType=random] [aggregationWindow=1] [runs=1] [length=100000]"); Console.WriteLine("\t where WalkType can be ... "); Console.WriteLine("\t bwp_pres\t Performs a random walk on the aggregate network that considers betweenness preferences computed from the temporal network"); Console.WriteLine("\t bwp_null\t ..."); return; } string out_file = args[2]; string type = "bwp_pres"; int runs = 1; int length = 100000; int aggregationWindow = 1; if (args.Length >= 4) { type = args[3]; } if (args.Length >= 5) { aggregationWindow = int.Parse(args[4]); } if (args.Length >= 6) { runs = int.Parse(args[5]); } if (args.Length >= 7) { length = int.Parse(args[6]); } if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network as undirected network..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], true); Console.WriteLine("done."); if (aggregationWindow != 1) { Console.WriteLine("Applying aggregation window, length = {0}, time steps before = {1}", aggregationWindow, temp_net.Length); temp_net.AggregateTime(aggregationWindow); Console.WriteLine("done, time steps after = {0}", temp_net.Length); } Console.Write("Building aggregate network..."); WeightedNetwork aggregateNet = temp_net.AggregateNetwork; Console.WriteLine("done."); for (int r = 2000; r <= 2000 + runs; r++) { Console.WriteLine("Running Random walk [{0}] in mode [{1}] ...", r, type); IDictionary <int, double> tvd = null; if (type == "bwp_pres") { tvd = RandomWalk.RunRW_BWP(temp_net, length, null_model: false); } else if (type == "bwp_null") { tvd = RandomWalk.RunRW_BWP(temp_net, length, null_model: true); } else { Console.WriteLine("\nError: RWType {0} unknown", type); return; } Console.Write("Writing time series of total variation distance ..."); StringBuilder sb = new StringBuilder(); foreach (var step in tvd) { sb.AppendLine(string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat, "{0} {1}", step.Key, step.Value)); } System.IO.File.WriteAllText(out_file + "_r_" + r + ".dat", sb.ToString()); Console.WriteLine(" done."); } }
public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet scc [temporal_network_original] [temporal_network_new] [undirected=false] [absolutTime=false]"); return; } string file_orig = args[1]; string file_new = args[2]; bool undirected = false; bool absoluteTime = false; if (args.Length >= 4) { undirected = Boolean.Parse(args[3]); } if (args.Length >= 5) { absoluteTime = Boolean.Parse(args[4]); } Console.Write("Reading temporal network as {0} network...", undirected?"undirected":"directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(file_orig, undirected: undirected); Console.WriteLine("done."); Console.Write("Extracting two paths and reducing original sequence..."); temp_net.ReduceToTwoPaths(false, absoluteTime); Console.WriteLine("done."); Console.Write("Building second order aggregate network..."); WeightedNetwork net = temp_net.SecondOrderAggregateNetwork; Console.WriteLine("done."); Console.Write("Extracting largest SCC..."); net.ReduceToLargestStronglyConnectedComponent(); Console.WriteLine("done."); Console.WriteLine("SCC has {0} nodes", net.VertexCount); Console.WriteLine("Filtering disconnected edges in temporal network ... "); foreach (var t in temp_net.Keys) { // Iterate through all edges in this time step foreach (var edge in temp_net[t].ToArray()) { string node = "(" + edge.Item1 + ";" + edge.Item2 + ")"; // If this edge is not a node in the second order network if (!net.Vertices.Contains(node)) { temp_net[t].Remove(edge); } } } Console.WriteLine("done."); Console.Write("Saving new temporal network ... "); TemporalNetwork.SaveToFile(file_new, temp_net); Console.WriteLine("done."); }
/// <summary> /// Outputs a simple example temporal network /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TempNet aggregate [temporal_network_file] [output_file] [aggregationWindow=1] [weighted_aggregate_networks=false]"); return; } string out_file = args[2]; bool two_path = false; int aggregationWindow = 1; if (args.Length >= 4) { aggregationWindow = int.Parse(args[3]); } if (args.Length >= 5) { two_path = bool.Parse(args[4]); } if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } Console.Write("Reading temporal network as undirected..."); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[1], undirected: true); Console.WriteLine(" done."); Console.WriteLine(temp_net.Length); Console.Write("Applying agggregation window [{0}] ...", aggregationWindow); temp_net.AggregateTime(aggregationWindow); Console.WriteLine("done."); Console.WriteLine(temp_net.Length); Console.Write("Reducing to two path networks ..."); temp_net.ReduceToTwoPaths(); Console.WriteLine("done."); if (!two_path) { Console.Write("Saving temporal network ..."); TemporalNetwork.SaveToFile(out_file, temp_net); Console.WriteLine(" done."); } else { //WeightedNetwork net = new WeightedNetwork(); //foreach(string tp in temp_net.TwoPathWeights.Keys) //{ // string[] comps = tp.Split(','); // net.AddEdge(comps[0], comps[2], EdgeType.Directed, temp_net.TwoPathWeights[tp]); //} Console.Write("Saving weighted first-order aggregate network ..."); WeightedNetwork.SaveToFile(out_file + ".1.edges", temp_net.AggregateNetwork); Console.WriteLine(" done."); Console.Write("Saving weighted second-order aggregate network ..."); WeightedNetwork.SaveToFile(out_file + ".2.edges", temp_net.SecondOrderAggregateNetwork); Console.WriteLine(" done."); } }
/// <summary> /// Creates randomized temporal networks based on a shuffling of edges or two-paths /// </summary> /// <param name="args"></param> public static void Run(string[] args) { if (args.Length < 4) { Console.WriteLine("Usage: TempNet shuffle [what] [original_net_file] [output_file] [undirected=false] [length=0]"); Console.WriteLine("... where [what] is ..."); Console.WriteLine("\t 'twopaths' \t Shuffle the two-paths in the original network. Preserves the aggregate network and the betweenness preference distribution."); Console.WriteLine("\t 'edges' \t Shuffles the edges in the original network. Preserves the aggregate network only."); Console.WriteLine(""); return; } string shuffling = args[1]; string out_file = args[3]; if (!CmdlTools.PromptExistingFile(out_file)) { Console.WriteLine("User opted to exit."); return; } bool undirected = false; if (args.Length >= 5) { undirected = bool.Parse(args[4]); } int length = 0; if (args.Length == 6) { length = int.Parse(args[5]); } TemporalNetwork output = null; Console.Write("Reading temporal network as {0} network...", undirected ? "undirected" : "directed"); TemporalNetwork temp_net = TemporalNetwork.ReadFromFile(args[2], undirected: undirected); Console.WriteLine(" done."); Console.Write("Extracting two paths and building aggregate network..."); temp_net.ReduceToTwoPaths(); Console.WriteLine(" done."); if (shuffling == "twopaths") { Console.Write("Shuffling two paths ..."); output = TemporalNetworkEnsemble.ShuffleTwoPaths(temp_net, length); Console.WriteLine(" done."); } else if (shuffling == "edges") { Console.Write("Shuffling edges ..."); output = TemporalNetworkEnsemble.ShuffleEdges(temp_net, length); Console.WriteLine(" done."); } else { Console.WriteLine("{0} is not a valid parameter!", shuffling); } if (output != null) { Console.Write("Saving temporal network to {0}...", out_file); TemporalNetwork.SaveToFile(out_file, output); Console.WriteLine(" done."); } }