public Walker(MultilayerNetwork multilayerNetwork, double jumpProbability, double[][] layerTransitions)
        {
            mathUtils = MathUtils.Instance;//new MathUtils();

            mnet        = multilayerNetwork;
            jump        = jumpProbability;
            transitions = layerTransitions;
            layerIds    = new Dictionary <int, int>();

            justJumped = true;
            noAction   = true;

            var   i         = 0;
            Layer flattened = mnet.GetLayer("flattenedNetwork");
            var   layers    = new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            }));

            foreach (var layer in layers)
            {
                layerIds.Add(layer.Id, i);
                i++;
            }
        }
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        /// Returns exclusive neighborhood of given actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get exclusive neighborhood of.</param>
        /// <param name="layer">Layer to calculate exclusive neighborhood on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Exclusive neighborhood of given actor on given layer with specific edgemode.</returns>
        public int ExclusiveNeighborhood(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            Layer flattened = mnet.GetLayer("flattened");
            // All layers except the layers in parameter.
            var layers = new HashSet <Layer> {
                layer
            };
            var layerSupplement = new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            }).Except(layers));
            var a = Neighbors(mnet, actor, layers, edgeMode);
            var b = Neighbors(mnet, actor, layerSupplement, edgeMode);

            var aMinusB = new HashSet <Actor>(a.Except(b));

            return(aMinusB.Count);
        }
Beispiel #4
0
        /// <summary>
        /// Returns exclusive relevance of the actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get exclusive relevance of.</param>
        /// <param name="layer">Layer to calculate exclusive relevance on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Exclusive relevance of the actor on given layer with specific edgemode.</returns>
        public double ExclusiveRelevance(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            Layer flattened = mnet.GetLayer("flattened");
            var   test      = new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            }));
            double allLayers = NeighborhoodCentrality(mnet, actor, new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            })), edgeMode);
            double selectedLayers = ExclusiveNeighborhood(mnet, actor, layer, edgeMode);

            if (allLayers == 0)
            {
                return(0);
            }

            return(selectedLayers / allLayers);
        }