24 package org.lightjason.agentspeak.action.builtin.math.blas.matrix;
26 import cern.colt.matrix.tdouble.DoubleMatrix1D;
27 import cern.colt.matrix.tdouble.DoubleMatrix2D;
28 import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix1D;
29 import cern.jet.math.tdouble.DoubleMult;
38 import javax.annotation.Nonnegative;
39 import javax.annotation.Nonnull;
40 import java.util.List;
41 import java.util.Random;
42 import java.util.concurrent.ThreadLocalRandom;
43 import java.util.stream.Collectors;
44 import java.util.stream.IntStream;
83 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return )
85 final Random l_random = ThreadLocalRandom.current();
86 final List<ITerm> l_arguments =
CCommon.
flatten( p_argument ).collect( Collectors.toList() );
89 final List<DoubleMatrix1D> l_eigenvector = IntStream
90 .range( 0, l_arguments.size() - 1 )
93 .map( i ->
new double[l_arguments.get( i ).<DoubleMatrix2D>raw().rows()] )
94 .map( DenseDoubleMatrix1D::new )
95 .peek( i -> IntStream.range( 0, Long.valueOf( i.size() ).intValue() ).forEach( j -> i.setQuick( j, l_random.nextDouble() ) ) )
96 .collect( Collectors.toList() );
99 IntStream.range( 0, l_arguments.get( 0 ).<Number>raw().intValue() )
100 .forEach( i -> IntStream
101 .range( 0, l_arguments.size() )
106 l_eigenvector.get( j ).assign(
DENSEALGEBRA.mult( l_arguments.get( j + 1 ).<DoubleMatrix2D>raw(), l_eigenvector.get( j ) ) );
107 l_eigenvector.get( j ).assign( DoubleMult.div(
DENSEALGEBRA.norm2( l_eigenvector.get( j ) ) ) );
110 l_eigenvector.stream()
112 .forEach( p_return::add );
calculates the largest eigenvector with perron-frobenius theorem.
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
execution context with local data
static final DenseDoubleAlgebra DENSEALGEBRA
dense algebra
final int minimalArgumentNumber()
minimum number of arguments
static Stream< ITerm > flatten( @Nonnull final Collection<? extends ITerm > p_terms)
flat term-in-term collection into a straight term list
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
static final long serialVersionUID
serial id
blas algebra operations e.g.
term structure for simple datatypes