Sum of the vector squared values

@param array $vector

@return number
328772
private function sumSquared(array $vector) {
        return array_reduce(
            $vector, 
            function($v, $w) { return $v += $this->square($w); }
        );
    }
835234
public function variance()
    {
        if ($this->n === 0) {
            throw new RuntimeException('Variance is not defined for vectors'
            . ' with less than 1 element.');
        }

        $ssd = $this->subtract($this->mean())
            ->square()
            ->sum();

        return $ssd / $this->n;
    }
369851
public static function sum( $arr, $key = null ) 
	{	
		if( !is_array( $arr ) ) 
		{
			throw new \InvalidArgumentException('CCArr::sum - first argument has to be an array.');
		}

		$sum = 0;

		if ( is_string( $key ) && CCArr::is_multi( $arr ) ) 
		{
			$arr = CCArr::pick( $key, $arr );
		}

		foreach ( $arr as $item ) 
		{
			if ( is_numeric( $item ) ) 
			{
				$sum += $item;	
			}
		}

		return $sum;
	}
1245332
public static double[] yVals(double[] vector) {
        double[] y = new double[vector.length / 2];
        int count = 0;
        for (int i = 0; i < vector.length; i++) {
            if (i % 2 == 0)
                y[count++] = vector[i];
        }
        return y;
    }
1075019
public function sum(string $column): int
    {
        $sum = $this->queryRelate->getQuery()->sum($column);

        $this->resetQueryRelate();

        return $sum;
    }
65107
public static function distance2(Vector $vector1, Vector $vector2) : float {
        $value = 0;
        $count = count($vector1);
        for ($i = 0;$i<$count;$i++) {
            $value += ($vector1[$i] - $vector2[$i]) * ($vector1[$i] - $vector2[$i]);
        }
        return $value;
    }
1108339
public static function SumTablix($a){
        $result = 0;
        for ($i = 0; $i < count($a); $i++) {
            $result=$result+$a[$i];
        }
        return $result;
    }
390469
public function sum($property) {
		$sum = 0;
		
		foreach ($this->_map as $key) {
			$item = $this->_data[$key];
			
			if (isset($item[$property])) {
				$sum += $item[$property];
			}
		}
		
		return $sum;
	}
930595
public function sum($column)
    {
        return $this->column($column)->reduce(function ($carry, $item) {
            $carry += $item;

            return $carry;
        });
    }
1332974
public function sum($colName)
    {
        $sum = 0;
        foreach ($this->rows as $row) {
            $sum+=$row[$colName];
        }
        return $sum;
    }
1074861
public static double sum(DoubleVector v) {
        double sum = 0;
        if (v instanceof SparseVector) {
            for (int nz : ((SparseVector)v).getNonZeroIndices())
                sum += v.get(nz);
        }
        else {
            int len = v.length();
            for (int i = 0; i < len; ++i)
                sum += v.get(i);
        }
        return sum;
    }
1301520
public double dot(Vector v)
	{
		return (x * v.x) + (y * v.y) + (z * v.z);
	}
511911
static function parseVector($vector)
    {
        $vectorInputs = array();
        $vector = preg_replace('/^' . self::$vectorHead . '[\\' . self::$metricSeparator . ']?/', '', $vector);
        $metrics = explode(self::$metricSeparator, $vector);
        if (count($metrics)) {
            foreach ($metrics as $metric) {
                if (!empty($metric)) {
                    list($name, $value) = explode(self::$valueSeparator, $metric);
                    $vectorInputs[$name] = $value;
                }
            }
        }
        return $vectorInputs;
    }
1174426
public function sum($column)
    {
        $result = $this->getBuilder()->sum($column);

        // Reset query builder
        $this->resetBuilder();

        return $result ?: 0;
    }
205450
public function sum($cb = null)
    {
        $sum = 0;

        $this->recursive(
            $this->storage,
            function ($value) use (& $sum) {
                if (is_numeric($value)) {
                    $sum += $value;
                }
            }
        );

        if ($cb !== null) {
            call_user_func_array($cb, [$sum]);
        }

        return $sum;
    }
60985
public static function calculateDeterminant($matrix) : float {
        // The ´rows´ args is the only needed one. Determinants can only be calculated
        // from a square matrix. Hence we use the row as size for both row and column.
        $determinant = 0;
        $rcCount     = count($matrix);
        if ($rcCount !== count($matrix[0])) {
            throw new InvalidArgumentException(
                "Can only calculate determinant from square matrix (same amount of rows as columns)."
            );
        }

        // If only one element, return the value from it.
        if ($rcCount === 1) {
            return $matrix[0][0];
        }

        $sign = 1;
        // Go through each element in first row.
        for ($counter=0;$counter<$rcCount;$counter++) {
            // Create a cofactor sub-matrix ($rcCount-1 in size).
            $subMatrix = self::getSubMatrix($matrix, 0, $counter);
            // Calculate the determinant of the sub-matrix.
            $determinant += $sign * $matrix[0][$counter] * self::calculateDeterminant($subMatrix);
            $sign         = -$sign;
        }

        return $determinant;
    }
190206
public function compute(array $a, array $b) : float
    {
        $a = Vector::quick($a);
        $b = Vector::quick($b);

        return 1. - ($a->dot($b) / ($a->l2Norm() * $b->l2Norm()));
    }