Ejemplo n.º 1
0
        private void CalculateDegreeWithCustomMeasure(EdgeWeightCriteria weightCriteria, _Graph previousGraph, bool edgeWeightFlag, bool nodeWeightFlag)
        {
            // must update this according to newly added class EdgeInfo
            // it was complex that is why I am leaving it as it is, in case we use this, then I will change it according to EdgeInfo

            int       countEdges = 0;
            Hashtable edgeList;

            float degreeCentrality;
            float positiveEdgeSum     = 0;
            float negitiveEdgeProduct = 1;
            float previousEdgeWeight  = 0;

            for (int node = 0; node < _NodeList.Count; node++)
            {
                edgeList   = (Hashtable)_AdjucencyList[node];
                countEdges = edgeList.Count;

                degreeCentrality = (countEdges / (float)(_NodeList.Count - 1));

                // following is for calculating sum of positive edges and product of negitive edge with respect to previous graph

                float weight = 0;

                bool weightFailed = false;

                foreach (int key in edgeList.Keys)
                {
                    if (weightCriteria == EdgeWeightCriteria.TWEET_BASED)
                    {
                        if (((EdgeInfo)edgeList[key]).TweetWeight > 0)
                        {
                            positiveEdgeSum += ((EdgeInfo)edgeList[key]).TweetWeight;
                        }
                        else
                        {
                            // need to search specific node in previous graph, because NodeList index are not same in current and previous graph
                            // following is not working correct
                            previousEdgeWeight   = ((EdgeInfo)((Hashtable)previousGraph._AdjucencyList[node])[key]).TweetWeight;
                            negitiveEdgeProduct *= (previousEdgeWeight - ((EdgeInfo)(edgeList[key])).TweetWeight) / previousEdgeWeight;
                        }
                    }
                    else if (weightCriteria == EdgeWeightCriteria.USER_BASED)
                    {
                        if (((EdgeInfo)edgeList[key]).UserWeight > 0)
                        {
                            positiveEdgeSum += ((EdgeInfo)edgeList[key]).UserWeight;
                        }
                        else
                        {
                            // need to search specific node in previous graph, because NodeList index are not same in current and previous graph
                            // following is not working correct
                            previousEdgeWeight   = ((EdgeInfo)((Hashtable)previousGraph._AdjucencyList[node])[key]).UserWeight;
                            negitiveEdgeProduct *= (previousEdgeWeight - ((EdgeInfo)(edgeList[key])).UserWeight) / previousEdgeWeight;
                        }
                    }
                    else if (weightCriteria == EdgeWeightCriteria.ACCUMULATIVE)
                    {
                        // for accumulative, both user and tweet weight must be greater than 0, then Weight will be greater than zero

                        //if (((EdgeInfo)edgeList[key]).Weight > 0)
                        //    positiveEdgeSum += ((EdgeInfo)edgeList[key]).Weight;
                        //else
                        //{
                        //    // need to search specific node in previous graph, because NodeList index are not same in current and previous graph
                        //    // following is not working correct
                        //    previousEdgeWeight = ((EdgeInfo)((Hashtable)previousGraph._AdjucencyList[node])[key]).Weight;
                        //    negitiveEdgeProduct *= (previousEdgeWeight - ((EdgeInfo)(edgeList[key])).Weight) / previousEdgeWeight;
                        //}
                    } // end of else if weightCriteria == EdgeWeightCriteria.ACCUMULATIVE
                }     // end of foreach (int key in edgeList.Keys)

                _CenteralityScores.Add(new KeyValuePair <int, float>(node, degreeCentrality * positiveEdgeSum * negitiveEdgeProduct));
            } // end of for (int node = 0; node < _NodeList.Count; node++)
        }
Ejemplo n.º 2
0
        public void CalculateDegreeCentrality(CentralityMeasure measure, EdgeWeightCriteria weightCriteria, _Graph previousGraph, bool edgeWeightFlag, bool nodeWeightFlag)
        {
            // add functions to calculate all sort of centrality based on measure
            // change this logic

            if (measure == CentralityMeasure.DEGREE_WITH_POSITIVE_EDGES)
            {
                CalculateDegreeWithPositiveEdges(weightCriteria, edgeWeightFlag, nodeWeightFlag);
            }
            else if (measure == CentralityMeasure.DEGREE_WITH_ALL_EDGES)
            {
                CalculateDegreeWithAllEdges(weightCriteria, edgeWeightFlag, nodeWeightFlag);
            }
            else if (measure == CentralityMeasure.CUSTOM_MEASURE)
            {
                CalculateDegreeWithCustomMeasure(weightCriteria, previousGraph, edgeWeightFlag, nodeWeightFlag);
            }
        }