예제 #1
0
        private void CalculateDegreeWithAllEdges(EdgeWeightCriteria weightCriteria, bool edgeWeightFlag, bool nodeWeightFlag)
        {
            // all edges will be considered even with "zero" weight
            // right now it is not weighted edge calculation, just considering degrees
            // NEED TO IMPLEMENT WEIGHTED EDGE CODE ///
            int countEdges = 0;

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

                _CenteralityScores.Add(new KeyValuePair <int, float>(node, (countEdges / (float)(_NodeList.Count - 1))));
            }
        }
예제 #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);
            }
        }
예제 #3
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++)
        }
예제 #4
0
        private void CalculateDegreeWithPositiveEdges(EdgeWeightCriteria weightCriteria, bool edgeWeightFlag, bool nodeWeightFlag)
        {
            // right now it is not weighted edge calculation, just considering positive degrees
            int       countEdges = 0;
            Hashtable edgeList;
            int       positiveNodeCount = 0;
            int       countEdgeWeights  = 0;

            //int nodeIndex = IndexOfNode(_NodeList, new NodeInfo("#bravsarg", 1));

            for (int node = 0; node < _NodeList.Count; node++)
            {
                if (_NodeList[node].NodeWeight > 0)
                {
                    positiveNodeCount++;
                }

                edgeList = (Hashtable)_AdjucencyList[node];

                foreach (int key in edgeList.Keys)
                {
                    if (weightCriteria == EdgeWeightCriteria.TWEET_BASED)
                    {
                        if (((EdgeInfo)edgeList[key]).TweetWeight > 0)
                        {
                            countEdges++;
                            countEdgeWeights += ((EdgeInfo)edgeList[key]).TweetWeight;
                        }
                    }
                    else if (weightCriteria == EdgeWeightCriteria.USER_BASED)
                    {
                        if (((EdgeInfo)edgeList[key]).UserWeight > 0)
                        {
                            countEdges++;
                            countEdgeWeights += ((EdgeInfo)edgeList[key]).UserWeight;
                        }
                    }
                    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)
                        //{
                        //    countEdges++;
                        //    countEdgeWeights += (int)((EdgeInfo)edgeList[key]).Weight;
                        //}
                    }
                }

                int tempEdgesValue;
                int tempNodeValue;

                if (edgeWeightFlag)
                {
                    tempEdgesValue = countEdgeWeights;
                }
                else
                {
                    tempEdgesValue = countEdges;
                }

                if (nodeWeightFlag)
                {
                    tempNodeValue = positiveNodeCount;
                }
                else
                {
                    tempNodeValue = _NodeList.Count - 1;
                }

                _CenteralityScores.Add(new KeyValuePair <int, float>(node, (tempEdgesValue / (float)tempNodeValue)));

                //reset edge count for next node
                countEdges = 0;
            }
        }