1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.statistics.examples.distribution;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import org.apache.commons.statistics.distribution.ContinuousDistribution;
22 import org.apache.commons.statistics.distribution.LogUniformDistribution;
23 import picocli.CommandLine.ArgGroup;
24 import picocli.CommandLine.Command;
25 import picocli.CommandLine.Option;
26
27
28
29
30 @Command(name = "logunif",
31 aliases = {"reciprocal"},
32 description = "Log uniform distribution.",
33 subcommands = {
34 LogUniformCommand.Check.class,
35 LogUniformCommand.PDF.class,
36 LogUniformCommand.LPDF.class,
37 LogUniformCommand.CDF.class,
38 LogUniformCommand.SF.class,
39 LogUniformCommand.ICDF.class,
40 LogUniformCommand.ISF.class,
41 })
42 class LogUniformCommand extends AbstractDistributionCommand {
43
44
45 private abstract static class BaseCommand extends AbstractContinuousDistributionCommand {
46
47 @ArgGroup(validate = false, heading = "Distribution parameters:%n", order = 1)
48 private Params params = new Params();
49
50
51 static class Params {
52
53 @Option(names = {"-a", "--lower"},
54 paramLabel = "a",
55 arity = "1..*",
56 split = ",",
57 description = {"lower bound (default: ${DEFAULT-VALUE})."})
58 private double[] lower = {1, 2};
59
60
61 @Option(names = {"-b", "--upper"},
62 paramLabel = "b",
63 arity = "1..*",
64 split = ",",
65 description = {"upper bound (default: ${DEFAULT-VALUE})."})
66 private double[] upper = {4, 6};
67 }
68
69
70 static final class Options extends ContinuousDistributionOptions {
71
72 private Options() {
73 min = -5;
74 max = 5;
75 }
76 }
77
78 @Override
79 protected List<Distribution<ContinuousDistribution>> getDistributions() {
80 double[] lower = params.lower;
81 double[] upper = params.upper;
82 final int n = DistributionUtils.validateLengths(lower.length, upper.length);
83
84 lower = DistributionUtils.expandToLength(lower, n);
85 upper = DistributionUtils.expandToLength(upper, n);
86
87
88 final ArrayList<Distribution<ContinuousDistribution>> list = new ArrayList<>();
89 for (int i = 0; i < n; i++) {
90 final ContinuousDistribution d = LogUniformDistribution.of(lower[i], upper[i]);
91 list.add(new Distribution<>(d, "a=" + lower[i] + ",b=" + upper[i]));
92 }
93 return list;
94 }
95 }
96
97
98 private abstract static class ProbabilityCommand extends BaseCommand {
99
100 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
101 private Options distributionOptions = new Options();
102
103 @Override
104 protected DistributionOptions getDistributionOptions() {
105 return distributionOptions;
106 }
107 }
108
109
110 private abstract static class InverseProbabilityCommand extends BaseCommand {
111
112 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
113 private InverseContinuousDistributionOptions distributionOptions = new InverseContinuousDistributionOptions();
114
115 @Override
116 protected DistributionOptions getDistributionOptions() {
117 return distributionOptions;
118 }
119 }
120
121
122 @Command(name = "check",
123 hidden = true,
124 description = "Log uniform distribution verification checks.")
125 static class Check extends ProbabilityCommand {}
126
127
128 @Command(name = "pdf",
129 description = "Log uniform distribution PDF.")
130 static class PDF extends ProbabilityCommand {}
131
132
133 @Command(name = "lpdf",
134 description = "Log uniform distribution natural logarithm of the PDF.")
135 static class LPDF extends ProbabilityCommand {}
136
137
138 @Command(name = "cdf",
139 description = "Log uniform distribution CDF.")
140 static class CDF extends ProbabilityCommand {}
141
142
143 @Command(name = "sf",
144 description = "Log uniform distribution survival probability.")
145 static class SF extends ProbabilityCommand {}
146
147
148 @Command(name = "icdf",
149 description = "Log uniform distribution inverse CDF.")
150 static class ICDF extends InverseProbabilityCommand {}
151
152
153 @Command(name = "isf",
154 description = "Log uniform distribution inverse SF.")
155 static class ISF extends InverseProbabilityCommand {}
156 }