public void QuantilePerformanceTest() { int n = 10; var sw0 = new Stopwatch(); var sw1 = new Stopwatch(); const int reps = 1000; while (n <= 1000000) { for (int i = 0; i < reps; i++) { var xs = RandomEnumerable.SampleRandomNumbers(0, 10000, n + 1).Select(x => (double)x).ToArray(); sw0.Start(); var q0 = Median(xs); // sorting sw0.Stop(); sw1.Start(); var q1 = xs.Median(); // selection sw1.Stop(); Assert.AreEqual(q0, q1, 1E-9); } Console.WriteLine("{0,-10} {1,-10} {2,-10}", n, sw0.ElapsedMilliseconds, sw1.ElapsedMilliseconds); n = n * 10; } }
protected IEnumerable <int> GenerateRowsToEvaluate(double percentageOfRows) { IEnumerable <int> rows; int samplesStart = EvaluationPartitionParameter.ActualValue.Start; int samplesEnd = EvaluationPartitionParameter.ActualValue.End; int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; if (samplesEnd < samplesStart) { throw new ArgumentException("Start value is larger than end value."); } if (percentageOfRows.IsAlmost(1.0)) { rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart); } else { int seed = RandomParameter.ActualValue.Next(); int count = (int)((samplesEnd - samplesStart) * percentageOfRows); if (count == 0) { count = 1; } rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count); } return(rows.Where(i => i < testPartitionStart || testPartitionEnd <= i)); }
protected IEnumerable <int> GenerateRowsToEvaluate() { int seed = RandomParameter.ActualValue.Next(); int samplesStart = ValidationPartitionParameter.ActualValue.Start; int samplesEnd = ValidationPartitionParameter.ActualValue.End; int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; if (samplesEnd < samplesStart) { throw new ArgumentException("Start value is larger than end value."); } int count = (int)((samplesEnd - samplesStart) * RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value); if (count == 0) { count = 1; } return(RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count) .Where(i => i < testPartitionStart || testPartitionEnd <= i)); }
protected IEnumerable <int> GenerateRowsToEvaluate(double percentageOfRows) { IEnumerable <int> rows; int samplesStart = EvaluationPartitionParameter.ActualValue.Start; int samplesEnd = EvaluationPartitionParameter.ActualValue.End; int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; if (samplesEnd < samplesStart) { throw new ArgumentException("Start value is larger than end value."); } if (percentageOfRows.IsAlmost(1.0)) { rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart); } else { int seed = RandomParameter.ActualValue.Next(); int count = (int)((samplesEnd - samplesStart) * percentageOfRows); if (count == 0) { count = 1; } rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count); } rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i); if (ValidRowIndicatorParameter.ActualValue != null) { string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value; var problemData = ProblemDataParameter.ActualValue; var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar); rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0)); } return(rows); }