24 package org.lightjason.agentspeak.action.builtin;
26 import org.apache.commons.math3.distribution.BetaDistribution;
27 import org.apache.commons.math3.distribution.CauchyDistribution;
28 import org.apache.commons.math3.distribution.ChiSquaredDistribution;
29 import org.apache.commons.math3.distribution.ExponentialDistribution;
30 import org.apache.commons.math3.distribution.FDistribution;
31 import org.apache.commons.math3.distribution.GammaDistribution;
32 import org.apache.commons.math3.distribution.GumbelDistribution;
33 import org.apache.commons.math3.distribution.LaplaceDistribution;
34 import org.apache.commons.math3.distribution.LevyDistribution;
35 import org.apache.commons.math3.distribution.LogNormalDistribution;
36 import org.apache.commons.math3.distribution.LogisticDistribution;
37 import org.apache.commons.math3.distribution.NakagamiDistribution;
38 import org.apache.commons.math3.distribution.NormalDistribution;
39 import org.apache.commons.math3.distribution.ParetoDistribution;
40 import org.apache.commons.math3.distribution.TDistribution;
41 import org.apache.commons.math3.distribution.TriangularDistribution;
42 import org.apache.commons.math3.distribution.UniformRealDistribution;
43 import org.apache.commons.math3.distribution.WeibullDistribution;
44 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
45 import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
66 import java.util.ArrayList;
67 import java.util.Collections;
68 import java.util.List;
69 import java.util.stream.Collectors;
70 import java.util.stream.IntStream;
71 import java.util.stream.Stream;
95 m_summarystatistic =
new SummaryStatistics();
96 m_descriptivestatistic =
new DescriptiveStatistics();
98 m_summarystatistic.addValue( 2 );
99 m_summarystatistic.addValue( 5 );
100 m_summarystatistic.addValue( 3 );
101 m_descriptivestatistic.addValue( 3 );
102 m_descriptivestatistic.addValue( 4 );
103 m_descriptivestatistic.addValue( 5 );
112 final List<ITerm> l_return =
new ArrayList<>();
116 Stream.of(
"summary",
"descriptive" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
121 Stream.of(
"summary",
"descriptive" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
125 Assert.assertEquals( l_return.size(), 4 );
126 Assert.assertTrue( l_return.get( 0 ).raw() instanceof SummaryStatistics );
127 Assert.assertTrue( l_return.get( 1 ).raw() instanceof DescriptiveStatistics );
128 Assert.assertTrue( l_return.get( 2 ).raw() instanceof SummaryStatistics );
129 Assert.assertTrue( l_return.get( 3 ).raw() instanceof DescriptiveStatistics );
138 final List<ITerm> l_return =
new ArrayList<>();
139 final DescriptiveStatistics l_statistic1 =
new DescriptiveStatistics();
140 final DescriptiveStatistics l_statistic2 =
new DescriptiveStatistics();
142 IntStream.range( 0, 100 ).peek( l_statistic1::addValue ).forEach( i -> l_statistic2.addValue( i * 10 ) );
147 Stream.of( 50, l_statistic1, l_statistic2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
153 Stream.of( l_statistic1, 25, 75 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
158 Assert.assertEquals( l_return.size(), 4 );
159 Assert.assertArrayEquals(
160 l_return.stream().map( i -> i.<Number>raw().doubleValue() ).toArray(),
161 Stream.of( 49.5, 495, 24.25, 74.75 ).mapToDouble( Number::doubleValue ).boxed().toArray()
173 Stream.of( m_summarystatistic, m_descriptivestatistic ).map(
CRawTerm::from ).collect( Collectors.toList() ),
174 Collections.emptyList()
177 Assert.assertEquals( m_summarystatistic.getSum(), 0, 0 );
178 Assert.assertEquals( m_descriptivestatistic.getSum(), 0, 0 );
187 final List<ITerm> l_return =
new ArrayList<>();
192 "normal",
"ISAAC", 20, 10,
193 "beta",
"SYNCHRONIZEDMERSENNETWISTER", 20, 10,
194 "cauchy",
"SYNCHRONIZEDISAAC", 10, 20,
195 "CHISQUARE",
"INTERNAL", 10,
196 "EXPONENTIAL",
"SYNCHRONIZEDINTERNAL", 5,
197 "F",
"WELL512A", 2, 6,
198 "GAMMA",
"SYNCHRONIZEDWELL512A", 6, 9,
199 "GUMBLE",
"WELL1024A", 2, 7,
200 "LAPLACE",
"SYNCHRONIZEDWELL1024A", 20, 18,
201 "LEVY",
"WELL19937A", 15, 20,
202 "LOGISTIC",
"SYNCHRONIZEDWELL19937A", 10, 17,
203 "LOGNORMAL",
"WELL19937C", 12, 14,
204 "NAKAGAMI",
"SYNCHRONIZEDWELL19937C", 20, 18,
205 "PARETO",
"WELL4449A", 20, 10,
206 "T",
"SYNCHRONIZEDWELL4449A", 10,
207 "TRIANGULAR",
"WELL44497B", 10, 15, 20,
208 "UNIFORM",
"SYNCHRONIZEDWELL44497B", 10, 25,
214 Assert.assertEquals( l_return.size(), 18 );
215 Assert.assertTrue( l_return.get( 0 ).raw() instanceof NormalDistribution );
216 Assert.assertTrue( l_return.get( 1 ).raw() instanceof BetaDistribution );
217 Assert.assertTrue( l_return.get( 2 ).raw() instanceof CauchyDistribution );
218 Assert.assertTrue( l_return.get( 3 ).raw() instanceof ChiSquaredDistribution );
219 Assert.assertTrue( l_return.get( 4 ).raw() instanceof ExponentialDistribution );
220 Assert.assertTrue( l_return.get( 5 ).raw() instanceof FDistribution );
221 Assert.assertTrue( l_return.get( 6 ).raw() instanceof GammaDistribution );
222 Assert.assertTrue( l_return.get( 7 ).raw() instanceof GumbelDistribution );
223 Assert.assertTrue( l_return.get( 8 ).raw() instanceof LaplaceDistribution );
224 Assert.assertTrue( l_return.get( 9 ).raw() instanceof LevyDistribution );
225 Assert.assertTrue( l_return.get( 10 ).raw() instanceof LogisticDistribution );
226 Assert.assertTrue( l_return.get( 11 ).raw() instanceof LogNormalDistribution );
227 Assert.assertTrue( l_return.get( 12 ).raw() instanceof NakagamiDistribution );
228 Assert.assertTrue( l_return.get( 13 ).raw() instanceof ParetoDistribution );
229 Assert.assertTrue( l_return.get( 14 ).raw() instanceof TDistribution );
230 Assert.assertTrue( l_return.get( 15 ).raw() instanceof TriangularDistribution );
231 Assert.assertTrue( l_return.get( 16 ).raw() instanceof UniformRealDistribution );
232 Assert.assertTrue( l_return.get( 17 ).raw() instanceof WeibullDistribution );
243 Stream.of( m_descriptivestatistic, m_summarystatistic, 1, 2, 3 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
244 Collections.emptyList()
247 Assert.assertEquals( m_descriptivestatistic.getN(), 6, 0 );
248 Assert.assertEquals( m_summarystatistic.getN(), 6 );
257 final List<ITerm> l_return =
new ArrayList<>();
264 "max",
"geometricmean",
265 "populationvariance",
"quadraticmean",
266 "secondmoment",
"standarddeviation",
267 "sumlog",
"sumsquare" 272 Assert.assertEquals( l_return.size(), 10 );
273 Assert.assertArrayEquals(
275 m_summarystatistic.getVariance(), m_summarystatistic.getMean(),
276 m_summarystatistic.getMax(), m_summarystatistic.getGeometricMean(),
277 m_summarystatistic.getPopulationVariance(), m_summarystatistic.getQuadraticMean(),
278 m_summarystatistic.getSecondMoment(), m_summarystatistic.getStandardDeviation(),
279 m_summarystatistic.getSumOfLogs(), m_summarystatistic.getSumsq()
292 final List<ITerm> l_return =
new ArrayList<>();
297 m_descriptivestatistic,
299 "max",
"geometricmean",
300 "populationvariance",
"quadraticmean",
301 "standarddeviation",
"sumsquare",
302 "kurtiosis",
"count",
"sum" 307 Assert.assertEquals( l_return.size(), 11 );
308 Assert.assertArrayEquals(
310 m_descriptivestatistic.getVariance(), m_descriptivestatistic.getMean(),
311 m_descriptivestatistic.getMax(), m_descriptivestatistic.getGeometricMean(),
312 m_descriptivestatistic.getPopulationVariance(), m_descriptivestatistic.getQuadraticMean(),
313 m_descriptivestatistic.getStandardDeviation(), m_descriptivestatistic.getSumsq(),
314 m_descriptivestatistic.getKurtosis(), (double) m_descriptivestatistic.getN(), m_descriptivestatistic.getSum()
327 final List<ITerm> l_return =
new ArrayList<>();
331 Stream.of(
new NormalDistribution(), 3 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
335 Assert.assertEquals( l_return.size(), 1 );
336 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List );
337 Assert.assertEquals( l_return.get( 0 ).<List<Number>>raw().size(), 3 );
346 final List<ITerm> l_return =
new ArrayList<>();
350 Stream.of( 5 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
354 Assert.assertEquals( l_return.size(), 1 );
355 Assert.assertTrue( l_return.get( 0 ).raw() instanceof List );
356 Assert.assertEquals( l_return.get( 0 ).<List<Number>>raw().size(), 5 );
365 final List<ITerm> l_return =
new ArrayList<>();
369 Stream.of(
"min", m_summarystatistic, m_descriptivestatistic ).map(
CRawTerm::from ).collect( Collectors.toList() ),
373 Assert.assertEquals( l_return.size(), 2 );
374 Assert.assertEquals( m_summarystatistic.getMin(), l_return.get( 0 ).<Double>raw(), 0 );
375 Assert.assertEquals( m_descriptivestatistic.getMin(), l_return.get( 1 ).<Double>raw(), 0 );
384 final List<ITerm> l_return = Collections.synchronizedList(
new ArrayList<>() );
386 IntStream.range( 0, 5000 )
391 Stream.of( Stream.of(
"a",
"b" ).collect( Collectors.toList() ), Stream.of( 4.5, 3.5 ).collect( Collectors.toList() ), 1 )
398 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"a" ) / l_return.size(),
404 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"b" ) / l_return.size(),
417 final List<ITerm> l_return = Collections.synchronizedList(
new ArrayList<>() );
419 IntStream.range( 0, 6500 )
424 Stream.of( Stream.of(
"a",
"b" ).collect( Collectors.toList() ), Stream.of( 4.5, 3.5 ).collect( Collectors.toList() ), 0.5 )
431 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"a" ) / l_return.size(),
437 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"b" ) / l_return.size(),
449 final List<ITerm> l_return = Collections.synchronizedList(
new ArrayList<>() );
451 IntStream.range( 0, 6500 )
456 Stream.of( Stream.of(
"c",
"d" ).collect( Collectors.toList() ), Stream.of( 3, 7 ).collect( Collectors.toList() ) )
462 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"c" ) / l_return.size(),
468 (
double) Collections.frequency( l_return.stream().map(
ITerm::raw ).collect( Collectors.toList() ),
"d" ) / l_return.size(),
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
gets multiple statistic values of a single statistic object.
final void randomsimple()
test random simple
final void randomsample()
test add random sample
create a (set) of simple random values.
action to clears the statistic.
returns for any static object a percentile value.
returns percentile value.
base test class with helpers
action to push a values to the statistic object.
final void exponentialselectionlazy()
test exponential selection with lazy parameter
IContext EMPTYPLAN
empty context with plan
test for statistics actions
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
gets a single statistic value of multiple statistic objects.
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
creates a distribution object.
action to create a statistic.
execution context with local data
final void percentile()
test percentile
final void initialize()
initialize
final void singlestatisticvalue()
test single statistics value
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void linearselection()
test linear selection
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
action to define a exponential fitness-proportinate-selection mechanism.
final void clear()
test clear
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void descriptivemultiplestatisticvalue()
test multiple statistics value of descriptive
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void createdistribution()
test create distribution
< T > T raw()
cast to any raw value type
final void summarymultiplestatisticvalue()
test multiple statistics value of summary
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final void exponentialselectionstrict()
test exponential selection with strict parameter
action to define a fitness-proportinate-selection mechanism.
final void createstatistics()
test create statistics
SummaryStatistics m_summarystatistic
testing summary statistic
create a (set) of random values.
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
final void addstatisticvalue()
test add statistics value
DescriptiveStatistics m_descriptivestatistic
testing descriptive statistic
term structure for simple datatypes
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation