예제 #1
0
        /// <summary>
        /// <summary>
        public static void TestQuantileCalculation(String[] args)
        {
            int size = int.Parse(args[0]);
            int b = int.Parse(args[1]);
            int k = int.Parse(args[2]);
            //cern.it.util.Log.enableLogging(args[3].Equals("log"));
            int chunks = int.Parse(args[4]);
            Boolean computeExactQuantilesAlso = args[5].Equals("exact");
            Boolean doShuffle = args[6].Equals("shuffle");
            double epsilon = Double.Parse(args[7]);
            double delta = Double.Parse(args[8]);
            int quantiles = int.Parse(args[9]);
            long max_N = long.Parse(args[10]);



            Console.WriteLine("free=" + Cern.Colt.Karnel.FreePhysicalMemorySize);
            Console.WriteLine("total=" + Cern.Colt.Karnel.TotalVisibleMemorySize);

            double[] phis = { 0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999, 1.0 };
            //int quantiles = phis.Length;

            Timer timer = new Timer();
            Timer timer2 = new Timer();
            IDoubleQuantileFinder approxFinder;

            approxFinder = QuantileFinderFactory.NewDoubleQuantileFinder(false, max_N, epsilon, delta, quantiles, null);
            Console.WriteLine(approxFinder);
            //new UnknownApproximateDoubleQuantileFinder(b,k);
            //approxFinder = new ApproximateDoubleQuantileFinder(b,k);
            /*
            double[] returnSamplingRate = new double[1];
            long[] result = ApproximateQuantileFinder.computeBestBandK(size*chunks, epsilon, delta, quantiles, returnSamplingRate);
            approxFinder = new ApproximateQuantileFinder((int) result[0], (int) result[1]);
            Console.WriteLine("epsilon="+epsilon);
            Console.WriteLine("delta="+delta);
            Console.WriteLine("samplingRate="+returnSamplingRate[0]);
            */


            IDoubleQuantileFinder exactFinder = QuantileFinderFactory.NewDoubleQuantileFinder(false, -1, 0.0, delta, quantiles, null);
            Console.WriteLine(exactFinder);

            DoubleArrayList list = new DoubleArrayList(size);

            for (int chunk = 0; chunk < chunks; chunk++)
            {
                list.Clear();
                int d = chunk * size;
                timer2.Start();
                for (int i = 0; i < size; i++)
                {
                    list.Add((double)(i + d));
                }
                timer2.Stop();



                //Console.WriteLine("unshuffled="+list);
                if (doShuffle)
                {
                    Timer timer3 = new Timer();
                    timer3.Start();

                    list.Shuffle();
                    Console.WriteLine("shuffling took " + timer3.Interval.ToString());

                    timer3.Stop();
                }
                //Console.WriteLine("shuffled="+list);
                //list.sort();
                //Console.WriteLine("sorted="+list);

                timer.Start();
                approxFinder.AddAllOf(list);
                timer.Stop();

                if (computeExactQuantilesAlso)
                {
                    exactFinder.AddAllOf(list);
                }

            }
            Console.WriteLine("list.Add() took" + timer2);
            Console.WriteLine("approxFinder.Add() took" + timer);

            //Console.WriteLine("free="+Cern.Colt.Karnel.FreePhysicalMemorySize);
            //Console.WriteLine("total="+Cern.Colt.Karnel.TotalVisibleMemorySize);

            timer.Stop();
            timer.Start();

            //approxFinder.close();
            DoubleArrayList approxQuantiles = approxFinder.QuantileElements(new DoubleArrayList(phis));

            Console.WriteLine(timer.Display);
            timer.Stop();

            Console.WriteLine("Phis=" + new DoubleArrayList(phis));
            Console.WriteLine("ApproxQuantiles=" + approxQuantiles);

            //Console.WriteLine("MaxLevel of full buffers="+maxLevelOfFullBuffers(approxFinder.bufferSet));

            //Console.WriteLine("total buffers filled="+ approxFinder.totalBuffersFilled);
            //Console.WriteLine("free="+Cern.Colt.Karnel.FreePhysicalMemorySize);
            //Console.WriteLine("total="+Cern.Colt.Karnel.TotalVisibleMemorySize);


            if (computeExactQuantilesAlso)
            {
                Console.WriteLine("Comparing with exact quantile computation...");

                timer.Reset();

                //exactFinder.close();
                DoubleArrayList exactQuantiles = exactFinder.QuantileElements(new DoubleArrayList(phis));
                Console.WriteLine(timer.Display);

                timer.Stop();

                Console.WriteLine("ExactQuantiles=" + exactQuantiles);


                //double[] errors1 = errors1(exactQuantiles.ToArray(), approxQuantiles.ToArray());
                //Console.WriteLine("Error1="+new DoubleArrayList(errors1));

                /*
                DoubleArrayList buffer = new DoubleArrayList((int)exactFinder.Count);
                exactFinder.forEach(
                    new cern.colt.function.DoubleFunction() {
                        public void apply(double element) {
                            buffer.Add(element);
                        }
                    }
                );
                */


                DoubleArrayList observedEpsilons = ObservedEpsilonsAtPhis(new DoubleArrayList(phis), (ExactDoubleQuantileFinder)exactFinder, approxFinder, epsilon);
                Console.WriteLine("observedEpsilons=" + observedEpsilons);

                double element = 1000.0f;


                Console.WriteLine("exact phi(" + element + ")=" + exactFinder.Phi(element));
                Console.WriteLine("apprx phi(" + element + ")=" + approxFinder.Phi(element));

                Console.WriteLine("exact elem(phi(" + element + "))=" + exactFinder.QuantileElements(new DoubleArrayList(new double[] { exactFinder.Phi(element) })));
                Console.WriteLine("apprx elem(phi(" + element + "))=" + approxFinder.QuantileElements(new DoubleArrayList(new double[] { approxFinder.Phi(element) })));
            }
        }