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); }
/// <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."); }
public void AggregateTimeTest() { TemporalNetwork net = ExampleData.GetTestNetwork3(); net.AggregateTime(3); }
/// <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."); } }
/// <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."); } }