コード例 #1
0
        public void AbsoluteTimeTest()
        {
            TemporalNetwork test = ExampleData.GetTestNetwork3();

            // Default behavior is relative time
            test.ReduceToTwoPaths();

            Assert.IsTrue(test.TwoPathWeights.ContainsKey("a,c,e") && test.TwoPathWeights["a,c,e"] == 1);

            test = ExampleData.GetTestNetwork3();
            test.ReduceToTwoPaths(false, true);

            Assert.IsFalse(test.TwoPathWeights.ContainsKey("a,c,e"));
        }
コード例 #2
0
        public void TimeReversalTest()
        {
            TemporalNetwork test = ExampleData.GetTestNetwork();

            test.ReduceToTwoPaths(true);

            Assert.AreEqual(test.TwoPathCount, 10, "Number of paths in time-reversed temporal network is incorrect!");
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: Fn_T2.cs プロジェクト: scone-snu/TemporalNetworks
        /// <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.");
        }
コード例 #5
0
        public void ReduceToTwoPathsTest()
        {
            TemporalNetwork test = ExampleData.GetTestNetwork();

            test.ReduceToTwoPaths();

            // There should be 12 two paths
            Assert.AreEqual(test.TwoPathCount, 12);

            // And 21 edges
            Assert.AreEqual(test.EdgeCount, 21);

            // The stripped network should contain 20 time steps
            Assert.AreEqual(test.Length, 20);

            Assert.AreEqual(test.MaxGranularity, 1);

            Assert.AreEqual(test.MinGranularity, 2);

            // The aggregate network should contain 8 weighted edges with a cumulative weight that matches 2 * twoPathCount
            Assert.AreEqual(test.AggregateNetwork.EdgeCount, 8);
            Assert.AreEqual(test.AggregateNetwork.CumulativeWeight, 22);

            // The second-order aggregate network should countain edges representing 6 different two-paths ...
            Assert.AreEqual(test.SecondOrderAggregateNetwork.EdgeCount, 6);
            // ... with a total weight of 11
            Assert.AreEqual(test.SecondOrderAggregateNetwork.CumulativeWeight, 11);

            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(c;e)", "(e;f)")], 5.5d);
            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(g;e)", "(e;f)")], 0.5d);
            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(e;f)", "(f;e)")], 1d);
            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(f;e)", "(e;b)")], 1d);
            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(a;e)", "(e;g)")], 2d);
            Assert.AreEqual(test.SecondOrderAggregateNetwork[new Tuple <string, string>("(b;e)", "(e;g)")], 1d);

            // Check whether all the weights are correctly computed ...
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("e", "f")], 7, "The weight of egde (e,f) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("e", "b")], 1, "The weight of egde (e,b) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("b", "e")], 1, "The weight of egde (b,e) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("g", "e")], 1d / 2d, "The weight of egde (g,e) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("e", "g")], 3, "The weight of egde (e,g) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("f", "e")], 2, "The weight of egde (f,e) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("a", "e")], 2, "The weight of egde (a,e) in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("c", "e")], 5 + 1d / 2d, "The weight of egde (c,e) in the aggregate network is wrong!");

            Assert.AreEqual(test.AggregateNetwork.MaxWeight, 7, "The maximum weight in the aggregate network is wrong!");
            Assert.AreEqual(test.AggregateNetwork.MinWeight, 0.5d, "The minimum weight in the aggregate network is wrong!");

            test = ExampleData.GetTestNetwork2();
            test.ReduceToTwoPaths();

            Assert.AreEqual(test.TwoPathCount, 7);

            Assert.AreEqual(test.Length, 3);

            Assert.AreEqual(test.MaxGranularity, 1);

            Assert.AreEqual(test.MinGranularity, 3);

            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("a", "b")], 1);
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("b", "c")], 1d + 1d / 6d + 1d / 6d + 1d / 6d);
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("d", "c")], 1d / 2d);
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("c", "d")], 1d / 3d);
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("c", "b")], 1d / 3d);
            Assert.AreEqual(test.AggregateNetwork[new Tuple <string, string>("c", "a")], 1d / 3d);
        }
コード例 #6
0
        /// <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.");
        }
コード例 #7
0
        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.");
        }
コード例 #8
0
        static void Main(string[] args)
        {
            /// Create a simple temporal network consisting of 11 repeated two-paths (this network corresponds two Fig. 2 (right part) in the paper)
            TemporalNetwork temporal_net = new TemporalNetwork();

            int k = 0;

            for (int i = 0; i < 100; i++)
            {
                // Add edges according to two paths
                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                // Note that the next added edge additionally continues a two-path e -> f -> e
                temporal_net.AddTemporalEdge(k++, "f", "e");
                temporal_net.AddTemporalEdge(k++, "e", "b");

                // An additional edge that should be filtered during preprocessing ...
                temporal_net.AddTemporalEdge(k++, "e", "b");

                // And one case where we have multiple edges in a single time step
                temporal_net.AddTemporalEdge(k, "g", "e");
                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "b", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");
            }

            // Preprocess two-paths and the aggregate network of the temporal network, if this is skipped it will be done automatically when the aggregate network is computed for the first time
            Console.Write("Preparing temporal network...");
            temporal_net.ReduceToTwoPaths();
            Console.WriteLine(" done.");

            // Aggregate the temporal network
            WeightedNetwork aggregate_net = temporal_net.AggregateNetwork;

            // Compute and output betweenness preference of v
            Console.WriteLine("Betw. pref. of e in empirical network = \t\t{0:0.00000}",
                    BetweennessPref.GetBetweennessPref(temporal_net, "e"));

            // Create a random temporal network which only preserves the aggregate network (and destroys bet. pref.)
            TemporalNetwork microstate_random = TemporalNetworkEnsemble.ShuffleEdges(temporal_net, temporal_net.Length);

            microstate_random.ReduceToTwoPaths();

            // Create a random temporal network that preserves both the aggregate network and betw. pref.
            TemporalNetwork microstate_betweennessPref = TemporalNetworkEnsemble.ShuffleTwoPaths(temporal_net, temporal_net.Length);

            microstate_betweennessPref.ReduceToTwoPaths();

            // Compute and output betweenness preference of v in random temporal network
            Console.WriteLine("Betw. pref. of e with shuffled edges = \t\t\t{0:0.00000}",
                    BetweennessPref.GetBetweennessPref(microstate_random, "e"));

            // Compute and output betweenness preference of v in temporal network preserving betw. pref.
            Console.WriteLine("Betw. pref. of e with shuffled two paths = \t\t{0:0.00000}",
                    BetweennessPref.GetBetweennessPref(microstate_betweennessPref, "e"));

            // Compute the betweenness preference matrices of the networks
            Dictionary<string, int> ind_pred;
            Dictionary<string, int> ind_succ;
            double[,] m1 = BetweennessPref.GetBetweennessPrefMatrix(temporal_net, "e", out ind_pred, out ind_succ, normalized: false);

            double[,] m2 = BetweennessPref.GetBetweennessPrefMatrix(microstate_betweennessPref, "e", out ind_pred, out ind_succ, normalized: false);

            // Get the betweenness preference distribution
            IEnumerable<double> dist = BetweennessPref.GetBetweennessPrefDist(temporal_net);
        }
コード例 #9
0
        /// <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.");
            }
        }
コード例 #10
0
        static void Main(string[] args)
        {
            /// Create a simple temporal network consisting of 11 repeated two-paths (this network corresponds two Fig. 2 (right part) in the paper)
            TemporalNetwork temporal_net = new TemporalNetwork();

            int k = 0;

            for (int i = 0; i < 100; i++)
            {
                // Add edges according to two paths
                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "a", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                // Note that the next added edge additionally continues a two-path e -> f -> e
                temporal_net.AddTemporalEdge(k++, "f", "e");
                temporal_net.AddTemporalEdge(k++, "e", "b");

                // An additional edge that should be filtered during preprocessing ...
                temporal_net.AddTemporalEdge(k++, "e", "b");

                // And one case where we have multiple edges in a single time step
                temporal_net.AddTemporalEdge(k, "g", "e");
                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "b", "e");
                temporal_net.AddTemporalEdge(k++, "e", "g");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");

                temporal_net.AddTemporalEdge(k++, "c", "e");
                temporal_net.AddTemporalEdge(k++, "e", "f");
            }

            // Preprocess two-paths and the aggregate network of the temporal network, if this is skipped it will be done automatically when the aggregate network is computed for the first time
            Console.Write("Preparing temporal network...");
            temporal_net.ReduceToTwoPaths();
            Console.WriteLine(" done.");

            // Aggregate the temporal network
            WeightedNetwork aggregate_net = temporal_net.AggregateNetwork;

            // Compute and output betweenness preference of v
            Console.WriteLine("Betw. pref. of e in empirical network = \t\t{0:0.00000}",
                              BetweennessPref.GetBetweennessPref(temporal_net, "e"));

            // Create a random temporal network which only preserves the aggregate network (and destroys bet. pref.)
            TemporalNetwork microstate_random = TemporalNetworkEnsemble.ShuffleEdges(temporal_net, temporal_net.Length);

            microstate_random.ReduceToTwoPaths();

            // Create a random temporal network that preserves both the aggregate network and betw. pref.
            TemporalNetwork microstate_betweennessPref = TemporalNetworkEnsemble.ShuffleTwoPaths(temporal_net, temporal_net.Length);

            microstate_betweennessPref.ReduceToTwoPaths();

            // Compute and output betweenness preference of v in random temporal network
            Console.WriteLine("Betw. pref. of e with shuffled edges = \t\t\t{0:0.00000}",
                              BetweennessPref.GetBetweennessPref(microstate_random, "e"));

            // Compute and output betweenness preference of v in temporal network preserving betw. pref.
            Console.WriteLine("Betw. pref. of e with shuffled two paths = \t\t{0:0.00000}",
                              BetweennessPref.GetBetweennessPref(microstate_betweennessPref, "e"));

            // Compute the betweenness preference matrices of the networks
            Dictionary <string, int> ind_pred;
            Dictionary <string, int> ind_succ;

            double[,] m1 = BetweennessPref.GetBetweennessPrefMatrix(temporal_net, "e", out ind_pred, out ind_succ, normalized: false);

            double[,] m2 = BetweennessPref.GetBetweennessPrefMatrix(microstate_betweennessPref, "e", out ind_pred, out ind_succ, normalized: false);

            // Get the betweenness preference distribution
            IEnumerable <double> dist = BetweennessPref.GetBetweennessPrefDist(temporal_net);
        }
コード例 #11
0
        /// <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.");
            }
        }