24 package org.lightjason.agentspeak.action.builtin.math.statistic;
34 import javax.annotation.Nonnegative;
35 import javax.annotation.Nonnull;
36 import java.util.List;
37 import java.util.Random;
38 import java.util.stream.Collectors;
39 import java.util.stream.Stream;
74 @SuppressWarnings(
"unchecked" )
76 @Nonnull final List<
ITerm> p_argument, @Nonnull final List<
ITerm> p_return )
80 final List<Object> l_items = p_argument.get( 0 ).<List<Object>>raw().stream()
82 .collect( Collectors.toList() );
83 final List<Double> l_weight = this.
weight(
85 p_argument.get( 1 ).<List<?>>raw().stream()
88 .map( Number::doubleValue )
90 p_argument.subList( 2, p_argument.size() )
93 if ( ( l_items.isEmpty() ) || ( l_items.size() != l_weight.size() ) )
97 double l_random = m_random.nextDouble() * l_weight.stream().mapToDouble( i -> i ).sum();
98 for (
int i = 0; i < l_weight.size(); i++ )
100 l_random -= l_weight.get( i );
109 p_return.add(
CRawTerm.
from( l_items.get( l_items.size() - 1 ) ) );
122 protected abstract List<Double>
weight( @Nonnull
final List<?> p_items, @Nonnull
final Stream<Double> p_values, @Nonnull
final List<ITerm> p_argument );
base class of build-in actions for setting name by package/classname (without prefix character) ...
abstract class for creating a selection one element of a list based on a fitness weight ...
static final long serialVersionUID
serial id
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
abstract List< Double > weight( @Nonnull final List<?> p_items, @Nonnull final Stream< Double > p_values, @Nonnull final List< ITerm > p_argument)
modifies the weights
final int minimalArgumentNumber()
minimum number of arguments
execution context with local data
static List< ITerm > replaceFromContext( @Nonnull final IContext p_context, @Nonnull final Collection<? extends ITerm > p_terms)
replace variables with context variables
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
result for an immutable fuzzy value
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
final Random m_random
random instance
int additionalArgumentNumber()
number of additional parameter
term structure for simple datatypes