public static void TestQuantileTrap() { Xoshiro256StarStar rand = new Xoshiro256StarStar(8675309); const int numberOfDists = 10; //const double meanOfNormals = 50; //const double stdDevOfNormals = 0.002; double Shape() => 2 *rand.NextDouble() - 1; double Scale() => 0.002 *rand.NextDouble() + 0; double Location() => 180 *rand.NextDouble(); IDistributionWrapper[] dists = new IDistributionWrapper[numberOfDists]; for (int i = 0; i < dists.Length; i++) { //dists[i] = new WrappedDistribution(new Normal(rand.NextDouble() * meanOfNormals * 2, 0 + Math.Abs(rand.NextDouble() * stdDevOfNormals)), -100, 200); // Bounds are unused here dists[i] = new WrappedDistribution(new GEV(Location(), Scale(), Shape(), rand), -100, 100); } double[] exact = DiscardProbabilityComputation.ComplementsTrapezoid(dists, 50000); Console.WriteLine("Exact:"); for (int i = 0; i < exact.Length; i++) { Console.WriteLine($"{i}: {dists[i].GetWrappedDistribution()} 1-P(D_i) = {exact[i]}"); } exact = DiscardProbabilityComputation.ComplementsMonteCarloMaximizing(dists); Console.WriteLine("MC:"); for (int i = 0; i < exact.Length; i++) { Console.WriteLine($"{i}: {dists[i].GetWrappedDistribution()} 1-P(D_i) = {exact[i]}"); } double[] est; int[] its = new int[] { 10, 20, 30, 40, 50, 75, 100, 200, 500, 1000, 2000, 20000 }; for (int i = 0; i < its.Length; i++) { int size = its[i]; est = DiscardProbabilityComputation.ComplementsQuantileTrapRule(dists, size); Console.WriteLine($"Size {size}:"); for (int j = 0; j < est.Length; j++) { Console.WriteLine($"{j}: {dists[j].GetWrappedDistribution()} 1-P(D_i) = {est[j]}"); } } }
public static void TestGEVComplementComputations() { double ep = Math.Pow(2, -50); double complementEp = 1.0 - ep; int testSize = 20; //GEV[] dists = new GEV[] { new GEV(0,200,-1), new GEV(0,100,-1) }; GEV[] dists = new GEV[testSize]; Random rand = new Xoshiro256StarStar(8675309); for (int i = 0; i < dists.Length; i++) { dists[i] = new GEV(rand.NextDouble(), rand.NextDouble(), -rand.NextDouble(), rand); } IDistributionWrapper[] wrappedDists = new IDistributionWrapper[dists.Length]; for (int i = 0; i < dists.Length; i++) { wrappedDists[i] = new WrappedDistribution(dists[i], dists[i].InverseCumulativeDistribution(ep), dists[i].InverseCumulativeDistribution(complementEp)); } double[] complements = DiscardProbabilityComputation.ComplementsClenshawCurtisAutomatic(wrappedDists); double[] complemetnsTrap = DiscardProbabilityComputation.ComplementsTrapezoid(wrappedDists, 10000); double[] mcComplements = DiscardProbabilityComputation.ComplementsMonteCarlo(wrappedDists, iterations: 10000000); double totalc = 0; double totalmc = 0; double totalTrap = 0; for (int i = 0; i < complements.Length; i++) { GEV dist = dists[i]; Program.logger.WriteLine($"Distribution Scale: {dist.scale} Loc {dist.location} Shape {dist.shape} " + $"1-P(D) {complements[i]} MC {mcComplements[i]} Trap {complemetnsTrap[i]}"); totalc += complements[i]; totalmc += mcComplements[i]; totalTrap += complemetnsTrap[i]; } Program.logger.WriteLine($"Total probability: {totalc} Total by MC: {totalmc} Total by Trap 10k: {totalTrap}"); }