Ejemplo n.º 1
0
        public virtual void Run( )
        {
            var options = ProgressBarOptions.Default;

            options.EnableTaskBarProgress = true;

            using (var pbar = new ProgressBar(V.Runs, "Simulating", options))
            {
                ParallelEnumerable
                .Range(0, V.Runs)
                .ForAll(i =>
                {
                    var iteration = new TIteration( );
                    iteration.Init(V, StrategyCollection);
                    iteration.Run( );

                    lock ( SyncLock )
                    {
                        ++Wins[iteration.Winner];
                        ++TimeStepsCount[iteration.TimeStepsPassed];
                        ConfidenceIntervalStats?.AddRun(iteration.GenerationHistory);
                    }

                    if (iteration.TimeStepsPassed > 2)
                    {
                        HeritabilitySummaries.Add(iteration.Heritability);
                    }

                    // ReSharper disable once AccessToDisposedClosure
                    pbar.Tick( );
                }
                        );
            }

            var clean = HeritabilitySummaries
                        .Where(x => !x.Values.Any(double.IsNaN))
                        .ToList( );

            for (var i = 0; i < HeritabilityMean.ValueCount; i++)
            {
                var index = i;
                (HeritabilityMean.Values[index], HeritabilitySd.Values[index]) =
                    clean.Select(x => x.Values[index]).MeanStandardDeviation( );
            }

            PrintHeritabilitySummaries("Heritability.csv");
            if (V.IncludeConfidenceIntervals)
            {
                PrintConfidenceIntervals("ConfidenceIntervals.txt");
            }
        }
Ejemplo n.º 2
0
        public virtual void Run( )
        {
            var options = ProgressBarOptions.Default;

            options.EnableTaskBarProgress = true;

            using (var pbar = new ProgressBar(V.Runs, "Simulating", options))
            {
                ParallelEnumerable
                .Range(0, V.Runs)
                .ForAll(i =>
                {
                    var adjustmentRules = new TAdjustmentRules( );
                    var iteration       = new TIteration( );
                    iteration.Init(V, adjustmentRules);
                    iteration.Run( );

                    lock ( SyncLock )
                    {
                        ++Wins[iteration.Winner];
                        ++GenerationsCount[iteration.GenerationsPassed];
                        ConfidenceIntervalStats?.Add(iteration.GenerationHistory);
                    }

                    if (iteration.GenerationsPassed > 2)
                    {
                        HeritabilitySummaries.Add(iteration.Heritability);
                    }

                    // ReSharper disable once AccessToDisposedClosure
                    pbar.Tick( );
                }
                        );
            }

            for (var i = 0; i < HeritabilityMean.ValueCount; i++)
            {
                var index = i;
                (HeritabilityMean.Values[index], HeritabilitySd.Values[index]) =
                    HeritabilitySummaries.Select(x => x.Values[index]).MeanStandardDeviation( );
            }

            if (V.IncludeConfidenceIntervals)
            {
                PrintConfidenceIntervals("ConfidenceIntervals.txt");
            }
        }