Checks if the sample should be normalized and if so, returns the
normalized sample

@param array $sample

@return array
353126
protected function checkNormalizedSample(array $sample)
    {
        if ($this->normalizer) {
            $samples = [$sample];
            $this->normalizer->transform($samples);
            $sample = $samples[0];
        }

        return $sample;
    }
182881
public function getNormalized(\Exception $exception)
    {
        $stack = $exception->getTrace();
        $trace = [];

        foreach ($stack as $item) {
            $trace[] = [
                'invocation' => $this->getInvocation($item),
                'origin'     => $this->getOrigin($item)
            ];
        }

        return $trace;
    }
1079035
public function transform(array &$samples) : void
    {
        if ($this->categories === null) {
            throw new RuntimeException('Transformer has not been fitted.');
        }

        $templates = [];

        foreach ($this->categories as $column => $categories) {
            $templates[$column] = array_fill(0, count($categories), 0);
        }

        foreach ($samples as &$sample) {
            $vector = [];

            foreach ($this->categories as $column => $categories) {
                $category = $sample[$column];
                $features = $templates[$column];

                if (isset($categories[$category])) {
                    $features[$categories[$category]] = 1;
                }

                $vector = array_merge($vector, $features);

                unset($sample[$column]);
            }

            $sample = array_merge($sample, $vector);
        }
    }
317105
public function transform(array $sample): array
    {
        if (!$this->fit) {
            throw new InvalidOperationException('PCA has not been fitted with respect to original dataset, please run PCA::fit() first');
        }

        if (!is_array($sample[0])) {
            $sample = [$sample];
        }

        $sample = $this->normalize($sample, count($sample[0]));

        return $this->reduce($sample);
    }
851762
public static function normalize(array $array, $default): array
    {
        $normalized = [];

        foreach ($array as $key => $value) {
            if (is_numeric($key)) {
                $key = $value;
                $value = $default;
            }

            $normalized[$key] = $value;
        }

        return $normalized;
    }
272913
protected function predictProbability(array $sample, $label)
    {
        $predicted = $this->predictSampleBinary($sample);

        if (strval($predicted) == strval($label)) {
            $sample = $this->checkNormalizedSample($sample);
            return abs($this->output($sample) - 0.5);
        }

        return 0.0;
    }
649886
public function transform(array &$samples) : void
    {
        if (!$this->r) {
            throw new RuntimeException('Transformer has not been fitted.');
        }

        $samples = Matrix::quick($samples)
            ->matmul($this->r)
            ->asArray();
    }
1053129
protected function _normalizeResult(array $data): array
    {
        $result = [];
        for ($i = 0; $i < $data['count']; $i++) {
            $item = $data[$i];

            // construct label
            preg_match('/^.*?,OU=(.*?),/i', $item['dn'], $match);
            $label = !empty($match[1]) ? $match[1] . ' / ' . $item['cn'][0] : $item['cn'][0];

            $result[$item['dn']] = $label;
        }

        asort($result);

        return $result;
    }
317000
protected function isolationScore(array $sample) : float
    {
        $depth = 0.;

        foreach ($this->forest as $tree) {
            $node = $tree->search($sample);

            $depth += $node ? $node->depth() : EPSILON;
        }

        $depth /= $this->estimators;

        return 2. ** -($depth / $this->pHat);
    }
50187
private function normalize() : array {
    $files = [];

    foreach($_FILES as $key => $file) {
      
      if (!is_array($file['name'])) {
          $files[$key][] = $file;
          continue;
      }

      foreach($file['name'] as $subKey => $name) {
          $files[$key][$subKey] = [
              'name' => $name,
              'type' => $file['type'][$subKey],
              'tmp_name' => $file['tmp_name'][$subKey],
              'error' => $file['error'][$subKey],
              'size' => $file['size'][$subKey]
          ];
      }
    }

    return $files;
  }
834811
protected function membership(array $sample) : array
    {
        $membership = $distances = [];

        foreach ($this->centroids as $centroid) {
            $distances[] = $this->kernel->compute($sample, $centroid);
        }

        $total = array_sum($distances) ?: EPSILON;

        foreach ($distances as $distance) {
            $membership[] = $distance / $total;
        }

        return $membership;
    }
872472
public function nearest(array $sample, int $k = 1) : array
    {
        if ($k < 1) {
            throw new InvalidArgumentException('The number of nearest'
                . " neighbors must be greater than 0, $k given.");
        }

        $neighborhood = $this->search($sample);

        if (!$neighborhood) {
            return [[], []];
        }

        $distances = $labels = [];

        $visited = new SplObjectStorage();

        $stack = [$neighborhood];

        while ($stack) {
            $current = array_pop($stack);

            if ($visited->contains($current)) {
                continue 1;
            }

            $visited->attach($current);

            $parent = $current->parent();

            if ($parent) {
                $stack[] = $parent;
            }

            if ($current instanceof Neighborhood) {
                foreach ($current->samples() as $neighbor) {
                    $distances[] = $this->kernel->compute($sample, $neighbor);
                }

                $labels = array_merge($labels, $current->labels());

                array_multisort($distances, $labels);

                continue 1;
            }

            $target = $distances[$k - 1] ?? INF;

            foreach ($current->children() as $child) {
                if ($visited->contains($child)) {
                    continue 1;
                }

                if ($child instanceof Box) {
                    foreach ($child->sides() as $side) {
                        $distance = $this->kernel->compute($sample, $side);

                        if ($distance < $target) {
                            $stack[] = $child;

                            continue 2;
                        }
                    }
                }

                $visited->attach($child);
            }
        }

        $distances = array_slice($distances, 0, $k);
        $labels = array_slice($labels, 0, $k);

        return [$labels, $distances];
    }
878624
protected function localOutlierFactor(array $sample) : float
    {
        if (empty($this->lrds)) {
            throw new RuntimeException('Local reachability distances have'
                . ' not been computed, must train estimator first.');
        }

        [$indices, $distances] = $this->tree->nearest($sample, $this->k);

        $lrd = $this->localReachabilityDensity($indices, $distances);

        $lrds = [];
        
        foreach ($indices as $index) {
            $lrds[] = $this->lrds[$index];
        }

        $ratios = [];

        foreach ($lrds as $lHat) {
            $ratios[] = $lHat / $lrd;
        }

        return Stats::mean($ratios);
    }
844921
protected function localRegion(array $sample) : array
    {
        $distances = [];

        foreach ($this->samples as $neighbor) {
            $distances[] = $this->kernel->compute($sample, $neighbor);
        }

        asort($distances);

        return array_slice($distances, 0, $this->k, true);
    }
261288
public function transform(array &$samples) : void
    {
        foreach ($samples as &$sample) {
            foreach ($sample as &$feature) {
                if (is_string($feature)) {
                    $feature = strip_tags($feature);
                }
            }
        }
    }
769984
public function shouldSample()
    {
        foreach ($this->samplers as $sampler) {
            if ($sampler->shouldSample() === false) {
                return false;
            }
        }
        return true;
    }
86238
protected function normalizeResult($resultArray)
    {
        $countArr = count($resultArray);
        if ($countArr > 10) {
            $resultArray = array_slice($resultArray, 0, 10);
        }
        else if ($countArr < 10) {
            for ($i = $countArr; $i < self::DEFAULT_RESULT_NUMBER; $i++)
                $resultArray[$i] = self::DEFAULT_PAD_ENTRY;
        }
        return $resultArray;
    }