Calculates artithmetic Average.
@access		public
@static
@param		array		$values			Array of Values.
@param		int			$accuracy		Accuracy of Result
@return		float
439220
public static function arithmetic( $values, $accuracy = NULL )
	{
		Deprecation::getInstance()
			->setErrorVersion( '0.8.5' )
			->setExceptionVersion( '0.9' )
			->message( sprintf(
				'Please use %s (%s) instead',
				'public library "CeusMedia/Math"',
			 	'https://packagist.org/packages/ceus-media/math'
			) );
		$sum	= 0;
		foreach( $values as $value )
			$sum	+= $value;
		$result	= $sum / count( $values );
		if( $accuracy >= 0 )
			$result	= round( $result, $accuracy );
		return $result;
	}
744999
public static function round($i, $precision = 0){

		$precision = pow(10,$precision);
		$i = $i*$precision;

		$ceil = ceil($i);
		$floor = floor($i);
		if( ($ceil - $i) <= ($i - $floor) ){
			return $ceil/$precision;
		}else{
			return $floor/$precision;
		}
	}
758927
protected function aggregateValues(array $values)
    {
        $min = $values[0];

        foreach ($values as $value) {
            if ($value < $min) {
                $min = $value;
            }
        }

        return $min;
    }
1162099
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        if (count($predictions) !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $classes = array_unique(array_merge($predictions, $labels));

        $truePos = $trueNeg = $falsePos = $falseNeg = array_fill_keys($classes, 0);

        foreach ($predictions as $i => $prediction) {
            $label = $labels[$i];

            if ($prediction === $label) {
                $truePos[$prediction]++;

                foreach ($classes as $class) {
                    if ($class !== $prediction) {
                        $trueNeg[$class]++;
                    }
                }
            } else {
                $falsePos[$prediction]++;
                $falseNeg[$label]++;
            }
        }

        return Stats::mean(
            array_map([$this, 'mcc'], $truePos, $trueNeg, $falsePos, $falseNeg)
        );
    }
1358004
public function average()
    {
        $flat = $this->flatten();

        $avg = array();
        foreach ($flat as $metric => $values) {
            $avg[$metric] = (float) number_format(array_sum($values) / count($values), 2, '.', '');
        }

        return $avg;
    }
130384
public static double Mean( int[] values ) {
        int     hits;
        long    total = 0;
        double  mean = 0;

        // for all values
        for ( int i = 0, n = values.length; i < n; i++ ) {
            hits = values[i];
            // accumulate mean
            mean += i * hits;
            // accumalate total
            total += hits;
        }
        return ( total == 0 ) ? 0 : mean / total;
    }
786992
def accuracy(input:Tensor, targs:Tensor)->Rank0Tensor:
    ""
    n = targs.shape[0]
    input = input.argmax(dim=-1).view(n,-1)
    targs = targs.view(n,-1)
    return (input==targs).float().mean()
1156416
public static function mad(array $values, ?float $median = null) : float
    {
        $median = $median ?? self::median($values);

        $deviations = [];

        foreach ($values as $value) {
            $deviations[] = abs($value - $median);
        }

        return self::median($deviations);
    }
915122
def average_precision(truth, recommend):
    
    if len(truth) == 0:
        if len(recommend) == 0:
            return 1.
        return 0.

    tp = accum = 0.
    for n in range(recommend.size):
        if recommend[n] in truth:
            tp += 1.
            accum += (tp / (n + 1.))
    return accum / truth.size
1035596
private function getRatio(string $value) : float
    {
        if (strpos($value, '%') !== false) {
            $result = ((float)str_replace('%', '', $value)) / 100;
        } else {
            $result = $value;
        }

        return (float)$result;
    }
428881
public static function stdev(array $values, $sample = false)
    {
        $variance = self::variance($values, $sample);

        return \sqrt($variance);
    }
621598
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        if (count($predictions) !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $errors = [];

        foreach ($predictions as $i => $prediction) {
            $errors[] = abs($labels[$i] - $prediction);
        }

        return -Stats::median($errors);
    }
678750
def calc_deviation(values, average):
    
    size = len(values)
    if size < 2:
        return 0
    calc_sum = 0.0

    for number in range(0, size):
        calc_sum += math.sqrt((values[number] - average) ** 2)
    return math.sqrt((1.0 / (size - 1)) * (calc_sum / size))
899174
public static function average(array $array, int $decimals = 0)
    {
        $count = Arr::size($array);

        if ( ! $count) {
            return 0;
        }

        if ( ! is_int($decimals)) {
            $decimals = 0;
        }

        return round(array_sum($array) / $count, $decimals);
    }
454624
public static double average(List<? extends Number> values) {
        if (values == null || values.isEmpty()) return 0D;

        double sum = 0D;
        for (Number v : values) sum += v.doubleValue();

        return sum / values.size();
    }
130994
public function getPercentage( $accuracy = 0 )
	{
		if( !$this->count )
			return 0;
		return round( $this->found / $this->count * 100, $accuracy );
	}
11667
public function average($decimals = 0)
    {
        $count = \count($this->getArray(), \COUNT_NORMAL);

        if (!$count) {
            return 0;
        }

        if (!\is_int($decimals)) {
            $decimals = 0;
        }

        return \round(\array_sum($this->getArray()) / $count, $decimals);
    }