# Vector (MDX++)

icCube MDX support for vector objects allows to perform fundamental operations of numerical linear algebra. Several ways of constructing vectors are available via the MDX Vector(), VectorA(), VectorK() and VectorN() functions.

### Operators

The MDX operators have been extended to support basic arithmetic operations (i.e., addition, multiplication, division, power) and comparison (i.e., equality, comparison). Some basic examples :

VectorN(2,3) + 2 = VectorN(4,5)

VectorN(2,3) - 2 = VectorN(0,1)

VectorN(2,3) * 2 = VectorN(4,6)

VectorN(2,3) / 2 = VectorN(1,3/2)

VectorN(2,3) * VectorN(1,2) = VectorN(2*1,3*2)

VectorN(2,3) ^ VectorN(1,2) = 2*1 + 3*2 = 8 , the 'scalar or dot product'

### OO Methods

The notation *vector -> method( ... )* allows for accessing the methods
of the vector. The conversion of the parameters (as well as the result) is handled
automatically by the MDX engine. As an example, the following code returns the arithmetic
mean of the amount of sales for all the countries:

Vector( [Geography].[Geo].[Country].members, [Measures].[Amount] ) -> mean()

#### copy()

Returns a copy of the vector.

#### corr(Vector b)

Returns a scalar value with the Pearson correlation between the two vectors.

#### cumSum()

Returns a scalar with the cumulative sum. cumSum = a + a+b + a+b+c -> {a,b,c,...}.

#### first()

Returns the first element of the vector (Double. Nan if empty vector).

#### fft()

Returns a vector with the fourier fast forward transformation of the vector (absolute value of the complex value).

#### geometricMean()

Returns the geometric mean (exp( 1/n (sum of logs) )) of the elements of the vector.

#### get(double n)

Returns the n-th element of the vector. If value is a numeric smaller than 1.0 returns the 'n * (length - 1)' element.

#### head(double size)

Returns a vector with the first 'size' elements. If value is less than 1.0 return the 'size *( length() + 1)' first elements.

#### hist(double start, double stop)

Returns the number of elements of the vector between start (inclusive) and stop (exclusive). A null value for start means -inf whereas a null value for stop means +inf.

#### last()

Returns the last element of the vector (Double. Nan if empty vector).

#### length()

Returns the number of elements of the vector.

#### max()

Returns the maximum of the elements of the vector.

#### mean()

Returns the arithmetic mean of the elements of the vector.

#### median()

Returns the median of the elements of the vector. This is the same as percentile(50.0)

#### min()

Returns the minimum of the elements of the vector.

#### norm()

Returns the Euclidean norm (i.e., the square root of the sum of the squares).

#### round(int precision)

Returns a vector with all values rounded to the specified number of decimal places (values are rounded using the ROUND_HALF_UP method)

#### percentile(double p)

Returns an estimate of the `p`

th percentile of the values in the vector ( 100.0 equals 100% ).

#### pAbs()

Returns a Vector with for each position the Absolute value. Vi = Abs( Ai )

#### pDif(Vector b)

Returns a Vector with for each position the Absolute value of the difference. Vi = Abs( Ai - Bi )

#### phist(double start, double stop)

Returns hist(start,stop) / length.

#### pMax(Vector b)

Returns a Vector with for each position the maximum of both vectors. Vi = Max( Ai, Bi )

#### pMin(Vector b)

Returns a Vector with for each position the minimum of both vectors. Vi = Min( Ai, Bi )

#### product()

Returns the product of the values in the vector.

#### reverse()

Returns a vector with the order of the elements reversed (from last to first).

#### scale()

Returns a vector with all values scaled between 0.0 and 1.0. ( NewVi = Vi - Min(V) / Max(V) - Min(V) )

#### sumOn(OlapDoubleVectorEntity p)

Returns the sum of all values for each position defined by the the vector V. ForEach(P) { value += V->get(Pi); }. Positions, Pi, outside bound are ignored.

#### sort()

Returns a vector with the values sorted in ascending order.

#### parallelSort()

Returns a vector with the values sorted in ascending order using parallelSort if available (JDK8+).

#### stdev()

Returns the standard deviation of the values in the vector (square root of the variance).

#### sum()

Returns the sum of the values in the vector.

#### sumLog()

Returns the sum of the natural logs of the values in the vector.

#### sumSq()

Returns the sum of the squares of the values in the vector.

#### tail(double size)

Returns a vector with the last 'size' elements. If value is less than 1.0 return the 'size *( length() + 1)' last elements.

#### value(index)

Returns the value of the {index} element of the vector.

#### variance()

Returns the variance (sum((x_i - mean)^2) / (n - 1)) of the values in the vector.

### Set Operators

#### unique()

Returns the list sorted of unique values.

#### setUnion(OlapDoubleVectorEntity v2)

The union of two vector, V ∪ V2. Return a vector that is the result of adding all values v2 to the vector. Use unique() if you don't want to have the same value twice.

#### setIntersect(OlapDoubleVectorEntity v2)

The intersection of two vectors, V ∩ V2. Returns a list that is the result of filtering out the values that are not found in the vector v2. Use unique() if you don't want to have the same value twice, but remember that if the vector V is unique the result will be unique too.

#### setMinus(OlapDoubleVectorEntity v2)

The difference between two vectors, V \ V2. Returns a list that is the result of filtering out the values that are found in the vector v. Use unique() if you don't want to have the same value twice, but remember that if the vector V is unique the result will be unique too.