Esempio n. 1
0
 private void spec_zipf_free(ZipfState /*!*/ theState)
 {
     if (theState.table != null)
     {
         theState.table = null;
     }
 }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////////////
        //ZIPF Distribution                                                         *
        ////////////////////////////////////////////////////////////////////////////

        public ZipfState spec_zipf_setup(RandomState rstate, int size, double Z)
        {
            int    i;
            double zipf_sum;

            ZipfState theState = new ZipfState(rstate, size);

            if (theState == null)
            {
                return(null);
            }

            // compute zipf values for samples 1-n
            for (i = 1; i <= size; i++)
            {
                theState.table[i] = Math.Pow(((double)1.0 / ((double)i)), Z);
                //theState.table[i] = 1;   // SPL TOTAL HACK until POW works!!
            }

            // sum the values so we can compute probabilities.
            // at the same time, make the values cumulative
            zipf_sum = 0.0;
            for (i = 1; i <= size; i++)
            {
                zipf_sum         += theState.table[i];
                theState.table[i] = zipf_sum;
            }
            theState.table[size] = 0.0;
            theState.table[0]    = 0.0;

            // compute probability values by dividing by the sum.
            // also reverse the table so we have values starting at 1.0
            //  and descending to 0.0  (this is what spec_zipf needs)
            for (i = 0; i < size; i++)
            {
                theState.table[i] = 1.0 - (theState.table[i] / zipf_sum);
            }


            return(theState);
        }
Esempio n. 3
0
        public int spec_zipf(ZipfState /*!*/ theState)
        {
            double r;
            int    i;

#if NO_ZIPF_SPIKE
            do
            {
#endif
            r = Spec_random(theState.rstate);
            i = 0;
            while (r < theState.table[i])
            {
                i++;
            }
#if NO_ZIPF_SPIKE
        }

        while (i > theState.size)
        {
            ;
        }