Пример #1
0
        } // end foreach

        /*  EndCalculation  --  Complete calculation and return results.  */

        public EntCalcResult EndCalculation()
        {
            int i;

            /* Complete calculation of serial correlation coefficient */

            scct1 = scct1 + scclast * sccu0;
            scct2 = scct2 * scct2;
            scc   = totalc * scct3 - scct2;
            if (scc == 0.0)
            {
                scc = -100000;
            }
            else
            {
                scc = (totalc * scct1 - scct2) / scc;
            }

            /* Scan bins and calculate probability for each bin and
             *                         Chi-Square distribution */

            cexp = totalc / (binary ? 2.0 : 256.0); /* Expected count per bin */
            for (i = 0; i < (binary ? 2 : 256); i++)
            {
                prob[i]  = (double)ccount[i] / totalc;
                a        = ccount[i] - cexp;
                chisq    = chisq + (a * a) / cexp;
                datasum += ((double)i) * ccount[i];
            }

            /* Calculate entropy */

            for (i = 0; i < (binary ? 2 : 256); i++)
            {
                if (prob[i] > 0.0)
                {
                    ent += prob[i] * log2(1 / prob[i]);
                }
            }

            /* Calculate Monte Carlo value for PI from percentage of hits
             *                         within the circle */

            montepi = 4.0 * (((double)inmont) / mcount);

            /* Calculate probability of observed distribution occurring from
             *                         the results of the Chi-Square test */

            double chip = Math.Sqrt(2.0 * chisq) - Math.Sqrt(2.0 * (binary ? 1 : 255.0) - 1.0);

            a = Math.Abs(chip);
            for (i = 9; i >= 0; i--)
            {
                if (chsqt[1, i] < a)
                {
                    break;
                }
            }
            chip = (chip >= 0.0) ? chsqt[0, i] : 1.0 - chsqt[0, i];

            double compReductionPct = ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0);

            /* Return results */
            var result = new EntCalcResult
            {
                Entropy                        = ent,
                ChiSquare                      = chisq,
                ChiProbability                 = chip,
                Mean                           = datasum / totalc,
                ExpectedMeanForRandom          = binary ? 0.5 : 127.5,
                MonteCarloPiCalc               = montepi,
                MonteCarloErrorPct             = (Math.Abs(Math.PI - montepi) / Math.PI),
                SerialCorrelation              = scc,
                OptimumCompressionReductionPct = compReductionPct,
                OccuranceCount                 = ccount,
                NumberOfSamples                = totalc
            };

            return(result);
        }
Пример #2
0
    } // end foreach


    /*  EndCalculation  --  Complete calculation and return results.  */
    public EntCalcResult EndCalculation()
    {
      int i;

      /* Complete calculation of serial correlation coefficient */

      scct1 = scct1 + scclast * sccu0;
      scct2 = scct2 * scct2;
      scc = totalc * scct3 - scct2;
      if (scc == 0.0) 
      {
        scc = -100000;
      } 
      else 
      {
        scc = (totalc * scct1 - scct2) / scc;
      }

      /* Scan bins and calculate probability for each bin and
         Chi-Square distribution */

      cexp = totalc / (binary ? 2.0 : 256.0);  /* Expected count per bin */
      for (i = 0; i < (binary ? 2 : 256); i++) 
      {
        prob[i] = (double) ccount[i] / totalc;
        a = ccount[i] - cexp;
        chisq = chisq + (a * a) / cexp;
        datasum += ((double) i) * ccount[i];
      }

      /* Calculate entropy */

      for (i = 0; i < (binary ? 2 : 256); i++) 
      {
        if (prob[i] > 0.0) 
        {
          ent += prob[i] * log2(1 / prob[i]);
        }
      }

      /* Calculate Monte Carlo value for PI from percentage of hits
         within the circle */

      montepi = 4.0 * (((double) inmont) / mcount);


      /* Calculate probability of observed distribution occurring from
         the results of the Chi-Square test */

      double chip = Math.Sqrt(2.0 * chisq) - Math.Sqrt(2.0 * (binary ? 1 : 255.0) - 1.0);
      a = Math.Abs(chip);
      for (i = 9; i >= 0; i--) 
      {
        if (chsqt[1,i] < a) 
        {
          break;
        }
      }
      chip = (chip >= 0.0) ? chsqt[0,i] : 1.0 - chsqt[0,i];

      double compReductionPct = ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0);

      /* Return results */
      EntCalcResult result = new EntCalcResult();
      result.Entropy = ent;
      result.ChiSquare = chisq;
      result.ChiProbability = chip;
      result.Mean = datasum / totalc;
      result.ExpectedMeanForRandom = binary ? 0.5 : 127.5;
      result.MonteCarloPiCalc = montepi;
      result.MonteCarloErrorPct = (Math.Abs(Math.PI - montepi) / Math.PI);
      result.SerialCorrelation = scc;
      result.OptimumCompressionReductionPct = compReductionPct;
      result.OccuranceCount = this.ccount;
      result.NumberOfSamples = this.totalc;
      return result;
    }