public void RandomAllRanges() { for (int n = 3; n < 20; n++) { var data = new UniformDistribution(0, 100).Random(42).Next(n); Output.WriteLine("[DATA] " + string.Join("; ", data)); var buffer = new double[data.Length]; var rqq = new Rqq(data); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { for (int k = 0; k < j - i; k++) { double actual = rqq.Select(i, j, k); Array.Copy(data, i, buffer, 0, j - i + 1); Array.Sort(buffer, 0, j - i + 1); double expected = buffer[k]; Output.WriteLine($"n = {n}, i = {i}, j = {j}, k = {k}, expected = {expected}, actual = {actual}"); if (actual != expected) { DumpRqqTree(rqq); } Assert.Equal(expected, actual); } } } } }
private void DumpRqqTree([NotNull] Rqq rqq) { using var memoryStream = new MemoryStream(); using var sw = new StreamWriter(memoryStream); rqq.DumpTreeAscii(sw, true); Output.WriteLine(Encoding.UTF8.GetString(memoryStream.ToArray(), 0, (int)memoryStream.Length)); }
public void SuperEtalon() { var rqq = new Rqq(new double[] { 6, 2, 0, 7, 9, 3, 1, 8, 5, 4 }); double actual = rqq.Select(2, 8, 4); Assert.Equal(7, actual); }
public CostCalculator([NotNull] double[] data, RqqPeltChangePointDetector detector) { this.detector = detector; quantileLeft = new double[QuantileCount]; quantileRight = new double[QuantileCount]; Penalty = Sensitivity; rqq = new Rqq(data); }
private void Check([NotNull] double[] data) { var rqq = new Rqq(data); using var memoryStream = new MemoryStream(); using var sw = new StreamWriter(memoryStream); rqq.DumpTreeAscii(sw, true); output.WriteLine(Encoding.UTF8.GetString(memoryStream.ToArray(), 0, (int)memoryStream.Length)); }
public void Run() { var data = new double[] { 6, 2, 0, 7, 9, 3, 1, 8, 5, 4 }; var rqq = new Rqq(data); Console.WriteLine(rqq.DumpTreeAscii()); Console.WriteLine(); for (int i = 0; i < data.Length; i++) { Console.WriteLine($"sorted[{i}] = {rqq.Select(0, data.Length - 1, i)}"); } }
public void Test01() { var rqq = new Rqq(new double[] { 0, 0, 0, 0, 0, 100, 100, 100, 100 }); DumpRqqTree(rqq); var probabilities = Enumerable.Range(0, 10).Select(x => (Probability)(x * 1.0 / 9.0)).ToArray(); foreach (var probability in probabilities) { Assert.Equal(0, rqq.GetQuantile(0, 4, probability)); Assert.Equal(100, rqq.GetQuantile(5, 8, probability)); } }
public CostCalculator([NotNull] double[] data, double penalty, int quantileCount) { this.quantileCount = quantileCount; probs = new double[quantileCount]; factors = new double[quantileCount]; quantileLeft = new double[quantileCount]; quantileRight = new double[quantileCount]; Penalty = penalty; rqq = new Rqq(data); for (int i = 0; i < quantileCount; i++) { probs[i] = i * 1.0 / (quantileCount - 1); int group = i / 5; factors[i] = Math.Max(1 - group * 0.1, 0); } }
public RqqSelectorAdapter([NotNull] double[] values) { Rqq = new Rqq(values); n = values.Length; }