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.DiscreteDistribution;
22 import org.apache.commons.statistics.distribution.GeometricDistribution;
23 import picocli.CommandLine.ArgGroup;
24 import picocli.CommandLine.Command;
25 import picocli.CommandLine.Option;
26
27
28
29
30 @Command(name = "geometric",
31 aliases = {"geo"},
32 description = "Geometric distribution.",
33 subcommands = {
34 GeometricCommand.Check.class,
35 GeometricCommand.PMF.class,
36 GeometricCommand.LPMF.class,
37 GeometricCommand.CDF.class,
38 GeometricCommand.SF.class,
39 GeometricCommand.ICDF.class,
40 GeometricCommand.ISF.class,
41 })
42 class GeometricCommand extends AbstractDistributionCommand {
43
44
45 private abstract static class BaseCommand extends AbstractDiscreteDistributionCommand {
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 = {"-p", "--probability"},
54 arity = "1..*",
55 split = ",",
56 description = {"probability of success (default: ${DEFAULT-VALUE})."})
57 private double[] p = {0.2, 0.5, 0.8};
58 }
59
60
61 static final class Options extends DiscreteDistributionOptions {
62
63 private Options() {
64 min = 0;
65 max = 10;
66 }
67 }
68
69 @Override
70 protected List<Distribution<DiscreteDistribution>> getDistributions() {
71
72 final ArrayList<Distribution<DiscreteDistribution>> list = new ArrayList<>();
73 for (final double prob : params.p) {
74 final DiscreteDistribution d = GeometricDistribution.of(prob);
75 list.add(new Distribution<>(d, "p=" + prob));
76 }
77 return list;
78 }
79 }
80
81
82 private abstract static class ProbabilityCommand extends BaseCommand {
83
84 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
85 private Options distributionOptions = new Options();
86
87 @Override
88 protected DistributionOptions getDistributionOptions() {
89 return distributionOptions;
90 }
91 }
92
93
94 private abstract static class InverseProbabilityCommand extends BaseCommand {
95
96 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
97 private InverseDiscreteDistributionOptions distributionOptions = new InverseDiscreteDistributionOptions();
98
99 @Override
100 protected DistributionOptions getDistributionOptions() {
101 return distributionOptions;
102 }
103 }
104
105
106 @Command(name = "check",
107 hidden = true,
108 description = "Geometric distribution verification checks.")
109 static class Check extends ProbabilityCommand {}
110
111
112 @Command(name = "pmf",
113 aliases = {"pdf"},
114 description = "Geometric distribution PMF.")
115 static class PMF extends ProbabilityCommand {}
116
117
118 @Command(name = "lpmf",
119 aliases = {"lpdf"},
120 description = "Geometric distribution natural logarithm of the PMF.")
121 static class LPMF extends ProbabilityCommand {}
122
123
124 @Command(name = "cdf",
125 description = "Geometric distribution CDF.")
126 static class CDF extends ProbabilityCommand {}
127
128
129 @Command(name = "sf",
130 description = "Geometric distribution survival probability.")
131 static class SF extends ProbabilityCommand {}
132
133
134 @Command(name = "icdf",
135 description = "Geometric distribution inverse CDF.")
136 static class ICDF extends InverseProbabilityCommand {}
137
138
139 @Command(name = "isf",
140 description = "Geometric distribution inverse SF.")
141 static class ISF extends InverseProbabilityCommand {}
142 }