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.TDistribution;
23 import picocli.CommandLine.ArgGroup;
24 import picocli.CommandLine.Command;
25 import picocli.CommandLine.Option;
26
27
28
29
30 @Command(name = "t",
31 description = "T distribution.",
32 subcommands = {
33 TCommand.Check.class,
34 TCommand.PDF.class,
35 TCommand.LPDF.class,
36 TCommand.CDF.class,
37 TCommand.SF.class,
38 TCommand.ICDF.class,
39 TCommand.ISF.class,
40 })
41 class TCommand 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 = {"-v", "--df", "--degrees-of-freedom"},
53 arity = "1..*",
54 split = ",",
55 description = {"degrees of freedom (default: ${DEFAULT-VALUE})."})
56 private double[] df = {1, 2, 5, 1e10};
57 }
58
59
60 static final class Options extends ContinuousDistributionOptions {
61
62 private Options() {
63 min = -5;
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 degreesOfFreedom : params.df) {
73 final ContinuousDistribution d = TDistribution.of(degreesOfFreedom);
74 list.add(new Distribution<>(d, "df=" + degreesOfFreedom));
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 = "T distribution verification checks.")
108 static class Check extends ProbabilityCommand {}
109
110
111 @Command(name = "pdf",
112 description = "T distribution PDF.")
113 static class PDF extends ProbabilityCommand {}
114
115
116 @Command(name = "lpdf",
117 description = "T distribution natural logarithm of the PDF.")
118 static class LPDF extends ProbabilityCommand {}
119
120
121 @Command(name = "cdf",
122 description = "T distribution CDF.")
123 static class CDF extends ProbabilityCommand {}
124
125
126 @Command(name = "sf",
127 description = "T distribution survival probability.")
128 static class SF extends ProbabilityCommand {}
129
130
131 @Command(name = "icdf",
132 description = "T distribution inverse CDF.")
133 static class ICDF extends InverseProbabilityCommand {}
134
135
136 @Command(name = "isf",
137 description = "T distribution inverse SF.")
138 static class ISF extends InverseProbabilityCommand {}
139 }