org.encog.mathutil
Class VectorAlgebra
- java.lang.Object
-
- org.encog.mathutil.VectorAlgebra
-
public class VectorAlgebra extends java.lang.ObjectBasic vector algebra operators. Vectors are represented as arrays of doubles. This class was created to support the calculations in the PSO algorithm. This class is thread safe. Contributed by: Geoffroy Noel https://github.com/goffer-looney
-
-
Constructor Summary
Constructors Constructor and Description VectorAlgebra()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(double[] v1, double[] v2)v1 = v1 + v2voidclampComponents(double[] v, double maxValue)For each components, reset their value to maxValue if their absolute value exceeds it.voidcopy(double[] dst, double[] src)dst = src Copy a vector.doubledotProduct(double[] v1, double[] v2)Take the dot product of two vectors.voidmul(double[] v, double k)v = k * v The components of the vector are multiplied by k.voidmulRand(double[] v, double k)v = k * U(0,1) * v The components of the vector are multiplied by k and a random number.voidneg(double[] v)v = -vvoidrandomise(double[] v)v = U(0, 0.1)voidrandomise(double[] v, double maxValue)v = U(-1, 1) * maxValue Randomise each component of a vector to [-maxValue, maxValue].voidsub(double[] v1, double[] v2)v1 = v1 - v2
-
-
-
Method Detail
-
add
public void add(double[] v1, double[] v2)v1 = v1 + v2- Parameters:
v1- an array of doublesv2- an array of doubles
-
sub
public void sub(double[] v1, double[] v2)v1 = v1 - v2- Parameters:
v1- an array of doublesv2- an array of doubles
-
neg
public void neg(double[] v)
v = -v- Parameters:
v- an array of doubles
-
mulRand
public void mulRand(double[] v, double k)v = k * U(0,1) * v The components of the vector are multiplied by k and a random number. A new random number is generated for each component. Thread-safety depends on Random.nextDouble()- Parameters:
v- an array of doubles.k- a scalar.
-
mul
public void mul(double[] v, double k)v = k * v The components of the vector are multiplied by k.- Parameters:
v- an array of doubles.k- a scalar.
-
copy
public void copy(double[] dst, double[] src)dst = src Copy a vector.- Parameters:
dst- an array of doublessrc- an array of doubles
-
randomise
public void randomise(double[] v)
v = U(0, 0.1)- Parameters:
v- an array of doubles
-
randomise
public void randomise(double[] v, double maxValue)v = U(-1, 1) * maxValue Randomise each component of a vector to [-maxValue, maxValue]. thread-safety depends on Random.nextDouble().- Parameters:
v- an array of doublesmaxValue- the max value
-
clampComponents
public void clampComponents(double[] v, double maxValue)For each components, reset their value to maxValue if their absolute value exceeds it.- Parameters:
v- an array of doublesmaxValue- if -1 this function does nothing
-
dotProduct
public double dotProduct(double[] v1, double[] v2)Take the dot product of two vectors.- Parameters:
v1- The first vector.v2- The second vector.- Returns:
- The dot product.
-
-
DMelt 3.0 © DataMelt by jWork.ORG