Example #1
0
        public void PrintConfidenceIntervals(string fileName)
        {
            ConfidenceIntervalStats.Compute( );
            ConfidenceIntervalStats.PrintToCsv("ConfidenceIntervals.csv");

            var properties = new[]
            {
                "Quality",
                "Variance Quality",
                "Covariance Quality",
                "Reproduction",
                "Variance Reproduction",
                "Covariance Reproduction"
            };

            var ci = "\n\n\nHeritability Confidence Intervals:\n\n";

            for (var i = 0; i < properties.Length; i++)
            {
                var property = properties[i];
                var interval = Utility.CalculateConfidenceInterval(
                    HeritabilitySummaries.Select(x => x.Values[i]).ToList( ),
                    V.Z);
                ci += $"{property,-33}: {interval}\n";
            }

            var lines = ci.Split('\n').Select(x => x.TrimEnd( ));

            File.WriteAllLines(fileName, lines);
        }
Example #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");
            }
        }