24 package org.lightjason.agentspeak.action.builtin.math.statistic;
26 import org.apache.commons.math3.distribution.AbstractRealDistribution;
27 import org.apache.commons.math3.distribution.BetaDistribution;
28 import org.apache.commons.math3.distribution.CauchyDistribution;
29 import org.apache.commons.math3.distribution.ChiSquaredDistribution;
30 import org.apache.commons.math3.distribution.ExponentialDistribution;
31 import org.apache.commons.math3.distribution.FDistribution;
32 import org.apache.commons.math3.distribution.GammaDistribution;
33 import org.apache.commons.math3.distribution.GumbelDistribution;
34 import org.apache.commons.math3.distribution.LaplaceDistribution;
35 import org.apache.commons.math3.distribution.LevyDistribution;
36 import org.apache.commons.math3.distribution.LogNormalDistribution;
37 import org.apache.commons.math3.distribution.LogisticDistribution;
38 import org.apache.commons.math3.distribution.NakagamiDistribution;
39 import org.apache.commons.math3.distribution.NormalDistribution;
40 import org.apache.commons.math3.distribution.ParetoDistribution;
41 import org.apache.commons.math3.distribution.TDistribution;
42 import org.apache.commons.math3.distribution.TriangularDistribution;
43 import org.apache.commons.math3.distribution.UniformRealDistribution;
44 import org.apache.commons.math3.distribution.WeibullDistribution;
45 import org.apache.commons.math3.random.ISAACRandom;
46 import org.apache.commons.math3.random.JDKRandomGenerator;
47 import org.apache.commons.math3.random.MersenneTwister;
48 import org.apache.commons.math3.random.RandomGenerator;
49 import org.apache.commons.math3.random.SynchronizedRandomGenerator;
50 import org.apache.commons.math3.random.Well1024a;
51 import org.apache.commons.math3.random.Well19937a;
52 import org.apache.commons.math3.random.Well19937c;
53 import org.apache.commons.math3.random.Well44497a;
54 import org.apache.commons.math3.random.Well44497b;
55 import org.apache.commons.math3.random.Well512a;
65 import javax.annotation.Nonnegative;
66 import javax.annotation.Nonnull;
67 import java.util.AbstractMap;
68 import java.util.Arrays;
69 import java.util.Collections;
70 import java.util.List;
71 import java.util.Locale;
73 import java.util.stream.Collectors;
74 import java.util.stream.IntStream;
168 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return )
170 final List<ITerm> l_arguments =
CCommon.
flatten( p_argument ).collect( Collectors.toList() );
172 IntStream.range( 0, l_arguments.size() )
174 .mapToObj( i ->
new AbstractMap.SimpleImmutableEntry<>( i, l_arguments.get( i ).<String>raw() ) )
176 .map( i ->
new AbstractMap.SimpleImmutableEntry<>( i.getKey(),
EDistribution.
from( i.getValue() ) ) )
184 if ( ( i.getKey() < l_arguments.size() - 1 ) && (
CCommon.
rawvalueAssignableTo( l_arguments.get( i.getKey() + 1 ), String.class ) ) )
187 l_generator =
EGenerator.
from( l_arguments.get( i.getKey() + 1 ).<String>raw() );
200 .skip( i.getKey() + 1 + l_skip )
201 .limit( i.getValue().getArgumentNumber() )
202 .map(
ITerm::<Number>raw )
203 .mapToDouble( Number::doubleValue )
209 .forEach( p_return::add );
242 private static final Set<String> NAMES = Collections.unmodifiableSet(
244 .map( i -> i.name().toUpperCase( Locale.ROOT ) )
245 .collect( Collectors.toSet() )
260 m_arguments = p_arguments;
272 return EDistribution.valueOf( p_value.trim().toUpperCase( Locale.ROOT ) );
281 public static boolean exist( @Nonnull
final String p_value )
283 return NAMES.contains( p_value.trim().toUpperCase( Locale.ROOT ) );
304 public final AbstractRealDistribution
get( @Nonnull
final RandomGenerator p_generator,
final double[] p_arguments )
309 return new BetaDistribution( p_generator, p_arguments[0], p_arguments[1] );
312 return new CauchyDistribution( p_generator, p_arguments[0], p_arguments[1] );
315 return new ChiSquaredDistribution( p_generator, p_arguments[0] );
318 return new ExponentialDistribution( p_generator, p_arguments[0] );
321 return new FDistribution( p_generator, p_arguments[0], p_arguments[1] );
324 return new GammaDistribution( p_generator, p_arguments[0], p_arguments[1] );
327 return new GumbelDistribution( p_generator, p_arguments[0], p_arguments[1] );
330 return new LaplaceDistribution( p_generator, p_arguments[0], p_arguments[1] );
333 return new LevyDistribution( p_generator, p_arguments[0], p_arguments[1] );
336 return new LogisticDistribution( p_generator, p_arguments[0], p_arguments[1] );
339 return new LogNormalDistribution( p_generator, p_arguments[0], p_arguments[1] );
342 return new NakagamiDistribution(
343 p_generator, p_arguments[0], p_arguments[1],
344 NakagamiDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY
348 return new NormalDistribution( p_generator, p_arguments[0], p_arguments[1] );
351 return new ParetoDistribution( p_generator, p_arguments[0], p_arguments[1] );
354 return new TDistribution( p_generator, p_arguments[0] );
357 return new TriangularDistribution( p_generator, p_arguments[0], p_arguments[1], p_arguments[2] );
360 return new UniformRealDistribution( p_generator, p_arguments[0], p_arguments[1] );
363 return new WeibullDistribution( p_generator, p_arguments[0], p_arguments[1] );
404 return EGenerator.valueOf( p_value.trim().toUpperCase( Locale.ROOT ) );
413 public final RandomGenerator
get()
417 case MERSENNETWISTER:
418 return new MersenneTwister();
420 case SYNCHRONIZEDMERSENNETWISTER:
421 return new SynchronizedRandomGenerator(
new MersenneTwister() );
424 return new ISAACRandom();
426 case SYNCHRONIZEDISAAC:
427 return new SynchronizedRandomGenerator(
new ISAACRandom() );
430 return new JDKRandomGenerator();
432 case SYNCHRONIZEDINTERNAL:
433 return new SynchronizedRandomGenerator(
new JDKRandomGenerator() );
436 return new Well512a();
438 case SYNCHRONIZEDWELL512A:
439 return new SynchronizedRandomGenerator(
new Well512a() );
442 return new Well1024a();
444 case SYNCHRONIZEDWELL1024A:
445 return new SynchronizedRandomGenerator(
new Well1024a() );
448 return new Well19937a();
450 case SYNCHRONIZEDWELL19937A:
451 return new SynchronizedRandomGenerator(
new Well19937a() );
454 return new Well19937c();
456 case SYNCHRONIZEDWELL19937C:
457 return new SynchronizedRandomGenerator(
new Well19937c() );
460 return new Well44497a();
462 case SYNCHRONIZEDWELL4449A:
463 return new SynchronizedRandomGenerator(
new Well44497a() );
466 return new Well44497b();
468 case SYNCHRONIZEDWELL44497B:
469 return new SynchronizedRandomGenerator(
new Well44497b() );
base class of build-in actions for setting name by package/classname (without prefix character) ...
static EGenerator from( @Nonnull final String p_value)
additional factory
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
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
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
final RandomGenerator get()
returns a number generator
final int getArgumentNumber()
return number of arguments
creates a distribution object.
CCreateDistribution()
ctor
execution context with local data
static Stream< ITerm > flatten( @Nonnull final Collection<? extends ITerm > p_terms)
flat term-in-term collection into a straight term list
static EDistribution from( @Nonnull final String p_value)
additional factory
static final long serialVersionUID
serial id
static< T > boolean rawvalueAssignableTo( @Nonnull final T p_value, @Nonnull final Class<?>... p_class)
checks a term value for assignable class
result for an immutable fuzzy value
SYNCHRONIZEDMERSENNETWISTER
EDistribution(final int p_arguments)
ctor
final int minimalArgumentNumber()
minimum number of arguments
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
class for any helper calls
static boolean exist( @Nonnull final String p_value)
checks if a name exists within the enum
final int m_arguments
number of arguments
term structure for simple datatypes