/// <summary>
 /// Fills values in the two-dimensional array of bits which define the connectedness
 /// of clusters between each other.
 /// </summary>
 /// <param name="treeMatrix">Two-dimensional array of bits which define the connectedness
 /// of clusters between each other.</param>
 /// <param name="mu">Density parameter.</param>
 private void GenerateData(BitArray[][] treeMatrix, Double mu)
 {
     for (int currentLevel = 0; currentLevel < container.Level; ++currentLevel)
     {
         if (treeMatrix[currentLevel].Length > 0)
         {
             uint branchSize = container.Branches[currentLevel][0];
             int  counter = 0, nodeNumber = 0;
             for (int i = 0; i < treeMatrix[currentLevel].Length; i++)
             {
                 for (int j = 0; j < treeMatrix[currentLevel][i].Length; j++)
                 {
                     if (counter == (branchSize * (branchSize - 1) / 2))
                     {
                         ++nodeNumber;
                         counter    = 0;
                         branchSize = container.Branches[currentLevel][nodeNumber];
                     }
                     double k = rand.NextDouble();
                     if (k <= (1 / Math.Pow(container.CountLeaves(currentLevel, nodeNumber), mu)))
                     {
                         treeMatrix[currentLevel][i][j] = true;
                     }
                     else
                     {
                         treeMatrix[currentLevel][i][j] = false;
                     }
                     ++counter;
                 }
             }
         }
     }
 }
        /// <summary>
        /// Calculates the distribution of degrees of vertices that belong to the given cluster.
        /// </summary>
        /// <param name="numberNode">The index of cluster.</param>
        /// <param name="currentLevel">The level of cluster.</param>
        /// <returns>Distribution of degrees of vertices that belong to the given cluster.</returns>
        private SortedDictionary <Double, Double> DegreeDistributionInCluster(int numberNode,
                                                                              int currentLevel)
        {
            if (currentLevel == container.Level)
            {
                SortedDictionary <Double, Double> returned = new SortedDictionary <Double, Double>();
                returned[0] = 1;
                return(returned);
            }
            else
            {
                BitArray node = container.TreeNode(currentLevel, numberNode);

                SortedDictionary <Double, Double> arraysReturned = new SortedDictionary <Double, Double>();
                SortedDictionary <Double, Double> array          = new SortedDictionary <Double, Double>();
                int branchSize     = (int)container.Branches[currentLevel][numberNode];
                int branchStartPnt = container.FindBranches(currentLevel, numberNode);

                for (int i = 0; i < branchSize; ++i)
                {
                    array = DegreeDistributionInCluster(branchStartPnt + i, currentLevel + 1);
                    int countAjacentsNodes = container.CountConnectedBlocks(node, branchSize, i);
                    foreach (KeyValuePair <Double, Double> kvt in array)
                    {
                        Double key = kvt.Key;
                        for (int j = 0; j < branchSize; ++j)
                        {
                            int counter = 0;
                            if (container.AreConnectedTwoBlocks(node, branchSize, i, j))
                            {
                                key += container.CountLeaves(currentLevel + 1,
                                                             branchStartPnt + j);
                                ++counter;
                            }
                            if (counter == countAjacentsNodes)
                            {
                                break;
                            }
                        }

                        if (arraysReturned.ContainsKey(key))
                        {
                            arraysReturned[key] += kvt.Value;
                        }
                        else
                        {
                            arraysReturned.Add(key, kvt.Value);
                        }
                    }
                }

                return(arraysReturned);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Fills values in the two-dimensional array of bits which define the connectedness
 /// of clusters between each other.
 /// </summary>
 /// <param name="treeMatrix">Two-dimensional array of bits which define the connectedness
 /// of clusters between each other.</param>
 /// <param name="mu">Density parameter.</param>
 private void GenerateData(BitArray[][] treeMatrix, Double mu)
 {
     for (int currentLevel = 0; currentLevel < container.Level; ++currentLevel)
     {
         if (treeMatrix[currentLevel].Length > 0)
         {
             List <EdgesAddedOrRemoved> edgesOnCurrentLevel = new List <EdgesAddedOrRemoved>();
             int branchSize = container.Branches[currentLevel][0];
             int counter = 0, nodeNumber = 0;
             for (int i = 0; i < treeMatrix[currentLevel].Length; i++)
             {
                 for (int j = 0; j < treeMatrix[currentLevel][i].Length; j++)
                 {
                     if (counter == (branchSize * (branchSize - 1) / 2))
                     {
                         ++nodeNumber;
                         counter    = 0;
                         branchSize = container.Branches[currentLevel][nodeNumber];
                     }
                     double k = rand.NextDouble();
                     if (k <= (1 / Math.Pow(container.CountLeaves(currentLevel, nodeNumber), mu)))
                     {
                         treeMatrix[currentLevel][i][j] = true;
                         edgesOnCurrentLevel.Add(new EdgesAddedOrRemoved(i, j, true));
                     }
                     else
                     {
                         treeMatrix[currentLevel][i][j] = false;
                     }
                     ++counter;
                 }
             }
             GenerationSteps.Add(edgesOnCurrentLevel);
         }
     }
 }