org.encog.mathutil

Class VectorAlgebra

• ```public class VectorAlgebra
extends Object```
Basic 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
Author:
Geoffroy Noel
• Constructor Summary

Constructors
Constructor and Description
`VectorAlgebra()`
• Method Summary

Methods
Modifier and Type Method and Description
`void` ```add(double[] v1, double[] v2)```
v1 = v1 + v2
`void` ```clampComponents(double[] v, double maxValue)```
For each components, reset their value to maxValue if their absolute value exceeds it.
`void` ```copy(double[] dst, double[] src)```
dst = src Copy a vector.
`double` ```dotProduct(double[] v1, double[] v2)```
Take the dot product of two vectors.
`void` ```mul(double[] v, double k)```
v = k * v The components of the vector are multiplied by k.
`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.
`void` `neg(double[] v)`
v = -v
`void` `randomise(double[] v)`
v = U(0, 0.1)
`void` ```randomise(double[] v, double maxValue)```
v = U(-1, 1) * maxValue Randomise each component of a vector to [-maxValue, maxValue].
`void` ```sub(double[] v1, double[] v2)```
v1 = v1 - v2
• Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• Constructor Detail

• VectorAlgebra

`public VectorAlgebra()`
• Method Detail

```public void add(double[] v1,
double[] v2)```
v1 = v1 + v2
Parameters:
`v1` - an array of doubles
`v2` - an array of doubles
• sub

```public void sub(double[] v1,
double[] v2)```
v1 = v1 - v2
Parameters:
`v1` - an array of doubles
`v2` - 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 doubles
`src` - 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 doubles
• 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 doubles
`maxValue` - 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.