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.ExponentialDistribution;
23 import picocli.CommandLine.ArgGroup;
24 import picocli.CommandLine.Command;
25 import picocli.CommandLine.Option;
26
27
28
29
30 @Command(name = "exp",
31 description = "Exponential distribution.",
32 subcommands = {
33 ExpCommand.Check.class,
34 ExpCommand.PDF.class,
35 ExpCommand.LPDF.class,
36 ExpCommand.CDF.class,
37 ExpCommand.SF.class,
38 ExpCommand.ICDF.class,
39 ExpCommand.ISF.class,
40 })
41 class ExpCommand extends AbstractDistributionCommand {
42
43
44 private abstract static class BaseCommand extends AbstractContinuousDistributionCommand {
45
46 @ArgGroup(validate = false, heading = "Distribution parameters:%n", order = 1)
47 private Params params = new Params();
48
49
50 static class Params {
51
52 @Option(names = {"-m", "--mean", "--scale"},
53 arity = "1..*",
54 split = ",",
55 description = {"mean (scale) (default: ${DEFAULT-VALUE})."})
56 private double[] mean = {2, 1, 2.0 / 3};
57 }
58
59
60 static final class Options extends ContinuousDistributionOptions {
61
62 private Options() {
63 min = 0;
64 max = 5;
65 }
66 }
67
68 @Override
69 protected List<Distribution<ContinuousDistribution>> getDistributions() {
70
71 final ArrayList<Distribution<ContinuousDistribution>> list = new ArrayList<>();
72 for (final double m : params.mean) {
73 final ContinuousDistribution d = ExponentialDistribution.of(m);
74 list.add(new Distribution<>(d, "mean=" + m));
75 }
76 return list;
77 }
78 }
79
80
81 private abstract static class ProbabilityCommand extends BaseCommand {
82
83 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
84 private Options distributionOptions = new Options();
85
86 @Override
87 protected DistributionOptions getDistributionOptions() {
88 return distributionOptions;
89 }
90 }
91
92
93 private abstract static class InverseProbabilityCommand extends BaseCommand {
94
95 @ArgGroup(validate = false, heading = "Evaluation options:%n", order = 2)
96 private InverseContinuousDistributionOptions distributionOptions = new InverseContinuousDistributionOptions();
97
98 @Override
99 protected DistributionOptions getDistributionOptions() {
100 return distributionOptions;
101 }
102 }
103
104
105 @Command(name = "check",
106 hidden = true,
107 description = "Exponential distribution verification checks.")
108 static class Check extends ProbabilityCommand {}
109
110
111 @Command(name = "pdf",
112 description = "Exponential distribution PDF.")
113 static class PDF extends ProbabilityCommand {}
114
115
116 @Command(name = "lpdf",
117 description = "Exponential distribution natural logarithm of the PDF.")
118 static class LPDF extends ProbabilityCommand {}
119
120
121 @Command(name = "cdf",
122 description = "Exponential distribution CDF.")
123 static class CDF extends ProbabilityCommand {}
124
125
126 @Command(name = "sf",
127 description = "Exponential distribution survival probability.")
128 static class SF extends ProbabilityCommand {}
129
130
131 @Command(name = "icdf",
132 description = "Exponential distribution inverse CDF.")
133 static class ICDF extends InverseProbabilityCommand {}
134
135
136 @Command(name = "isf",
137 description = "Exponential distribution inverse SF.")
138 static class ISF extends InverseProbabilityCommand {}
139 }