Пример #1
0
        /// <summary>
        /// Returns clustering coefficient of the given node.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="node">Node to calculate clustering coefficient on.</param>
        /// <returns>Clustering coefficient of the given node.</returns>
        public double ClusteringCoefficient(MultilayerNetwork mnet, Node node)
        {
            // Edges between neighbors.
            // How well connected are they.
            double edgesCount = 0;
            // Get all neighbors of the node.
            var neighbors = mnet.Neighbors(node, EdgeMode.InOut);
            // Degree of the node.
            var neighborsCount = neighbors.Count;

            if (neighborsCount <= 1)
            {
                return(0);
            }

            // Go through all neighbors of our node.
            // And check how well connected they are between each other.
            foreach (var n1 in neighbors)
            {
                foreach (var n2 in neighbors)
                {
                    if (n1 == n2)
                    {
                        continue;
                    }
                    if (mnet.GetEdge(n1, n2) != null)
                    {
                        edgesCount++;
                    }
                }
            }

            return((edgesCount) / (neighborsCount * (neighborsCount - 1)));
        }
Пример #2
0
        /// <summary>
        /// Moves the walker
        /// </summary>
        /// <returns>Node where walker moved onto.</returns>
        public Node Next()
        {
            if (mathUtils.Test(jump))
            {
                current    = Utils.Extensions.GetAtRandom(mnet.GetNodes());
                justJumped = true;
                noAction   = false;
            }
            else
            {
                Layer flattened   = mnet.GetLayer("flattenedNetwork");
                var   layerId     = layerIds[current.Layer.Id];
                var   layerIdTest = mathUtils.Test(transitions, layerId);
                var   newLayer    = mnet.GetLayers().Except(new HashSet <Layer>()
                {
                    flattened
                }).ElementAt(layerIdTest);

                if (current.Layer == newLayer)
                {
                    // Inside same layer.
                    var neigh = mnet.Neighbors(current, EdgeMode.Out);
                    if (neigh.Count == 0)
                    {
                        // Cant move.
                        // No action.
                        noAction = true;
                        return(current);
                    }

                    var rand = mathUtils.GetRandomInt(neigh.Count);
                    current    = neigh.ElementAt(rand);
                    justJumped = false;
                    noAction   = false;
                }
                else
                {
                    // Changing to another node with this actor.
                    var nextNode = mnet.GetNode(current.Actor, newLayer);
                    if (nextNode == null)
                    {
                        // No other nodes with this actor.
                        noAction = true;
                        return(current);
                    }

                    current    = nextNode;
                    justJumped = false;
                    noAction   = false;
                }
            }

            return(current);
        }
Пример #3
0
        /// <summary>
        /// Returns degree on provided layer.
        /// </summary>
        /// <param name="mnet">Multlayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layer">Single Layer.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Degree of the Actor.</returns>
        public int Degree(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode)
        {
            var degree = 0;

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // We go through all his neighbors, and if the neighbor is on the provided layer
                    // we increase his degree by 1.
                    if (neighbor.Layer == layer)
                    {
                        degree += 1;
                    }
                }
            }

            return(degree);
        }
Пример #4
0
        private MathUtils mathUtils = MathUtils.Instance; //new MathUtils();


        #region Degree

        /// <summary>
        /// Returns degree of the actor on provided layers.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layers">HashSet of layers.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Degree of the Actor.</returns>
        public int Degree(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode)
        {
            var degree = 0;

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // If there is a layer with this neighbor it means, that this NODE has this neighbor
                    // on this layer, so we increase his degree by 1.
                    if (layers.Contains(neighbor.Layer))
                    {
                        degree += 1;
                    }
                }
            }

            return(degree);
        }
Пример #5
0
        /// <summary>
        /// Returns neighbors of given actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get neighbors of.</param>
        /// <param name="layer">Layer to get neighbors on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Neighbors of given actor on given layer with specific edgemode.</returns>
        private HashSet <Actor> Neighbors(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            // Empty hashset to add checked actors.
            var neighbors = new HashSet <Actor>();

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // If there is a layer with this neighbor it means, that this NODE has this neighbor
                    // on this layer, so we increase his degree by 1 IF actor on this node is still available.
                    if (layer == neighbor.Layer)
                    {
                        neighbors.Add(neighbor.Actor);
                    }
                }
            }

            return(neighbors);
        }