Beispiel #1
0
        public vektor(int size)
        {
            root        = new element();
            leaf        = new element();
            heap        = new modmaxheap(size);
            leaf.parent = root;

            root.left  = leaf;
            root.right = leaf;
            support    = 0;
        }
Beispiel #2
0
        public int support; // number of nodes in the tree

        #endregion Fields

        #region Constructors

        public vektor(int size)
        {
            root = new element();
            leaf = new element();
            heap = new modmaxheap(size);
            leaf.parent   = root;

            root.left	= leaf;
            root.right    = leaf;
            support		= 0;
        }
Beispiel #3
0
        // ------------------------------------------------------------------------------------ //
        // ------------------------------------------------------------------------------------ //
        // ------------------------------------------------------------------------------------ //
        // FUNCTION DEFINITIONS --------------------------------------------------------------- //

        void buildDeltaQMatrix()
        {
            // Given that we've now populated a sparse (unordered) adjacency matrix e (e),
            // we now need to construct the intial dQ matrix according to the definition of dQ
            // which may be derived from the definition of modularity Q:
            //    Q(t) = \sum_{i} (e_{ii} - a_{i}^2) = Tr(e) - ||e^2||
            // thus dQ is
            //    dQ_{i,j} = 2* ( e_{i,j} - a_{i}a_{j} )
            //    where a_{i} = \sum_{j} e_{i,j} (i.e., the sum over the ith row)
            // To create dQ, we must insert each value of dQ_{i,j} into a binary search tree,
            // for the jth column. That is, dQ is simply an array of such binary search trees,
            // each of which represents the dQ_{x,j} adjacency vector. Having created dQ as
            // such, we may happily delete the matrix e in order to free up more memory.
            // The next step is to create a max-heap data structure, which contains the entries
            // of the following form (value, s, t), where the heap-key is 'value'. Accessing the
            // root of the heap gives us the next dQ value, and the indices (s,t) of the vectors
            // in dQ which need to be updated as a result of the merge.


            // First we compute e_{i,j}, and the compute+store the a_{i} values. These will be used
            // shortly when we compute each dQ_{i,j}.
            edge current;


            double eij = (double)(0.5 / gparm.m);                               // intially each e_{i,j} = 1/m

            for (int i = 1; i < gparm.maxid; i++)
            {                                   // for each row
                if (e[i].so != 0)
                {                               //    ensure it exists
                    current = e[i];             //    grab first edge
                    a[i]    = eij;              //    initialize a[i]
                    while (current.next != null)
                    {                           //    loop through remaining edges
                        a[i]   += eij;          //       add another eij
                        current = current.next; //
                    }
                    Q[0] += -1.0 * a[i] * a[i]; // calculate initial value of Q
                }
            }

            // now we create an empty (ordered) sparse matrix dq[]
            dq = new nodenub[gparm.maxid];      // initialize dq matrix
            for (int i = 0; i < gparm.maxid; i++)
            {                                   //
                //dq[i].heap_ptr;							// no pointer in the heap at first
                if (e[i].so != 0)
                {
                    dq[i].v = new vektor(2 + (int)(gparm.m * a[i]));
                }
                else
                {
                    dq[i].v = null;
                }
            }
            h = new modmaxheap(gparm.n);                                                // allocate max-heap of size = number of nodes

            // Now we do all the work, which happens as we compute and insert each dQ_{i,j} into
            // the corresponding (ordered) sparse vector dq[i]. While computing each dQ for a
            // row i, we track the maximum dQmax of the row and its (row,col) indices (i,j). Upon
            // finishing all dQ's for a row, we insert the tuple into the max-heap hQmax. That
            // insertion returns the itemaddress, which we then store in the nodenub heap_ptr for
            // that row's vector.
            double dQ;
            tuple  dQmax = new tuple();                                                                         // for heaping the row maxes

            //tuple itemaddress;
            // stores address of item in maxheap


            for (int i = 1; i < gparm.maxid; i++)
            {
                if (e[i].so != 0)
                {
                    current       = e[i];                                          // grab first edge
                    dQ            = 2.0 * (eij - (a[current.so] * a[current.si])); // compute its dQ
                    dQmax.m       = dQ;                                            // assume it is maximum so far
                    dQmax.i       = current.so;                                    // store its (row,col)
                    dQmax.j       = current.si;                                    //
                    dQmax.enabled = true;
                    dq[i].v.insertItem(current.si, dQ);                            // insert its dQ
                    while (current.next != null)
                    {                                                              //
                        current = current.next;                                    // step to next edge
                        dQ      = 2.0 * (eij - (a[current.so] * a[current.si]));   // compute new dQ
                        if (dQ > dQmax.m)
                        {                                                          // if dQ larger than current max
                            dQmax.m = dQ;                                          //    replace it as maximum so far
                            dQmax.j = current.si;                                  //    and store its (col)
                        }
                        dq[i].v.insertItem(current.si, dQ);                        // insert it into vector[i]
                    }
                    dq[i].heap_ptr = h.insertItem(dQmax);                          // store the pointer to its loc in heap
                }
            }

            e     = null;
            elist = null;

            // free-up adjacency matrix memory in two shots
            //
            return;
        }