예제 #1
0
 public SummaryStatistics computeConfidenceIntervalForPercent(int percent)
 {
     double hi = halfIntervalFor(zFor(percent));
     double pointEstimate = mean();
     double cLower = pointEstimate - hi;
     double cUpper = pointEstimate + hi;
     SummaryStatistics summary = new SummaryStatistics();
     summary.cLower = cLower;
     summary.cUpper = cUpper;
     summary.pointEstimate = pointEstimate;
     return summary;
 }
예제 #2
0
        public SummaryStatistics computeConfidenceIntervalForPercent(int percent)
        {
            double            hi            = halfIntervalFor(zFor(percent));
            double            pointEstimate = mean();
            double            cLower        = pointEstimate - hi;
            double            cUpper        = pointEstimate + hi;
            SummaryStatistics summary       = new SummaryStatistics();

            summary.cLower        = cLower;
            summary.cUpper        = cUpper;
            summary.pointEstimate = pointEstimate;
            return(summary);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            double numberOfRuns = 1000000.0;

            //generator = new RandomAdapter();
            generator = new UniformGenerator();
            int factor = 3;

            if (args.Length > 0)
            {
                factor       = Convert.ToInt32(args[0]);
                numberOfRuns = Convert.ToDouble(args[1]);
            }

            Console.WriteLine(string.Format("{0} workers used in this run of {1}", factor, numberOfRuns));


            PointEstimate estimate = new PointEstimate();
            Stopwatch     sw       = Stopwatch.StartNew();

            using (var q = new AsyncWorkQueue <double>(factor))
            {
                for (int i = 0; i < factor; i++)
                {
                    var id = i;
                    q.Start(delegate
                    {
                        SpreadsheetGear.IWorkbookSet workbookSet = SpreadsheetGear.Factory.GetWorkbookSet();
                        IWorkbook workbook = workbookSet.Workbooks.Open(@"c:\data\dev\Async\AsyncWorkQueueTest\AsyncWorkQueueTest\excel\helloWorld_template.xls");
                        for (long j = 0; j < numberOfRuns / factor; j++)
                        {
                            try
                            {
                                double annRevenue = generate(30, 70);
                                double annCosts   = generate(5, 20);
                                double numYears   = generate(2, 6);
                                var sheet         = workbook.Worksheets["Hello"];
                                sheet.Cells["AnnRevenue"].Value = Convert.ToDouble(annRevenue);
                                sheet.Cells["AnnCosts"].Value   = Convert.ToDouble(annCosts);
                                sheet.Cells["numYears"].Value   = Convert.ToDouble(numYears);
                                var npvRange = sheet.Cells["npv"];
                                double npv   = (double)npvRange.Value;
                                //Console.WriteLine("annRevenue = " + annRevenue + ", annCosts = " + annCosts + ", numYears = " + numYears+", NPV = "+npv);
                                estimate.nextValueIs(npv);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Process " + id + ", run " + j + ", exception thrown!");
                                Console.WriteLine(e.StackTrace);
                            }
                        }
                        return(0);
                    });
                    Console.WriteLine("Started delegate " + i);
                }

                Console.WriteLine("*** Done queueing.");


                foreach (var result in q.GetResults())
                {
                    if (result.IsError)
                    {
                        //handle / log errors here
                        throw result.Error;
                    }
                }
                SummaryStatistics statistics = estimate.computeConfidenceIntervalForPercent(99);
                sw.Stop();
                Console.WriteLine("Mean: " + statistics.pointEstimate + ", [" + statistics.cLower + ", " + statistics.cUpper + "]");
                Console.WriteLine("Elapsed time = " + sw.Elapsed);
            }



            //Test(new List<int>() { 5, 6, 5, 4, 3, 2, 1 });

            Console.ReadLine();
        }