@param array $samples

@return array
358619
public function predict(array $samples)
    {
        $testSet = DataTransformer::testSet($samples);
        file_put_contents($testSetFileName = $this->varPath.uniqid('phpml', true), $testSet);
        file_put_contents($modelFileName = $testSetFileName.'-model', $this->model);
        $outputFileName = $testSetFileName.'-output';

        $command = sprintf('%ssvm-predict%s %s %s %s', $this->binPath, $this->getOSExtension(), $testSetFileName, $modelFileName, $outputFileName);
        $output = '';
        exec(escapeshellcmd($command), $output);

        $predictions = file_get_contents($outputFileName);

        unlink($testSetFileName);
        unlink($modelFileName);
        unlink($outputFileName);

        if (in_array($this->type, [Type::C_SVC, Type::NU_SVC])) {
            $predictions = DataTransformer::predictions($predictions, $this->targets);
        } else {
            $predictions = explode(PHP_EOL, trim($predictions));
        }

        if (!is_array($samples[0])) {
            return $predictions[0];
        }

        return $predictions;
    }
679731
protected function resample(): array
    {
        $weights = $this->weights;
        $std = StandardDeviation::population($weights);
        $mean = Mean::arithmetic($weights);
        $min = min($weights);
        $minZ = (int) round(($min - $mean) / $std);

        $samples = [];
        $targets = [];
        foreach ($weights as $index => $weight) {
            $z = (int) round(($weight - $mean) / $std) - $minZ + 1;
            for ($i = 0; $i < $z; ++$i) {
                if (random_int(0, 1) == 0) {
                    continue;
                }

                $samples[] = $this->samples[$index];
                $targets[] = $this->targets[$index];
            }
        }

        return [$samples, $targets];
    }
261288
public function transform(array &$samples) : void
    {
        foreach ($samples as &$sample) {
            foreach ($sample as &$feature) {
                if (is_string($feature)) {
                    $feature = strip_tags($feature);
                }
            }
        }
    }
766964
public function zip() : array
    {
        $rows = $this->samples;

        foreach ($rows as $i => &$row) {
            $row[] = $this->labels[$i];
        }

        return $rows;
    }
602165
public function transform(array &$samples) : void
    {
        if ($this->means === null or $this->stddevs === null) {
            throw new RuntimeException('Transformer has not been fitted.');
        }

        foreach ($samples as &$sample) {
            foreach ($this->stddevs as $column => $stddev) {
                $feature = $sample[$column];

                if ($this->center) {
                    $feature -= $this->means[$column];
                }

                $sample[$column] = $feature / $stddev;
            }
        }
    }
253750
static public function mean(array $sample)
    {
        $count = count($sample);
        if ($count === 0) {
            return false;
        }

        $sum = 0;
        foreach ($sample as $s) {
            $sType = gettype($s);

            if ($sType !== 'integer' && $sType !== 'double') {
                // only deal with numeric values.
                return false;
            }

            $sum += $s;
        }

        return $sum / $count;
    }
60247
public function get_samples($sampleids) {
        global $DB;

        list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
        $users = $DB->get_records_select('user', "id $sql", $params);

        $userids = array_keys($users);
        $sampleids = array_combine($userids, $userids);

        $users = array_map(function($user) {
            return ['user' => $user, 'context' => \context_user::instance($user->id)];
        }, $users);

        // No related data attached.
        return [$sampleids, $users];
    }
371021
public function transform(array &$samples) : void
    {
        if ($this->vocabulary === null) {
            throw new RuntimeException('Transformer is not fitted.');
        }

        $templates = [];

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

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

            foreach ($this->vocabulary as $column => $vocabulary) {
                $text = $sample[$column];

                $tokens = $this->tokenizer->tokenize($text);

                $counts = array_count_values($tokens);

                $features = $templates[$column];

                foreach ($counts as $token => $count) {
                    if (isset($vocabulary[$token])) {
                        $features[$vocabulary[$token]] = $count;
                    }
                }

                $vectors[] = $features;

                unset($sample[$column]);
            }

            $sample = array_merge($sample, ...$vectors);
        }
    }
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;
    }
333477
public function samples()
    {
        if ($this->p()->l10n() === false) {
            $origLang = $this->lang();
            $locales  = $this->translator()->availableLocales();
            $sampleId = $this->sampleId();
            foreach ($locales as $langCode) {
                $this->setSampleId($sampleId.'_'.$langCode);
                $this->setLang($langCode);

                yield $this;
            }
            $this->setSampleId($sampleId);
            $this->setLang($origLang);
        } else {
            yield $this;
        }
    }
424986
protected function nearest(array $sample) : array
    {
        $distances = [];

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

        asort($distances);

        $distances = array_slice($distances, 0, $this->k, true);

        $labels = array_intersect_key($this->labels, $distances);

        return [$labels, $distances];
    }
578026
private function getSamplesMatrix(): Matrix
    {
        $samples = [];
        foreach ($this->samples as $sample) {
            array_unshift($sample, 1);
            $samples[] = $sample;
        }

        return new Matrix($samples);
    }
463512
public function sample_array()
   {
      $data = array(
                  'Juliet & Romeo',
                  'some_email@example.com',
                  'This is an example using an Array as a message, without an external template HTML',
                  date('Y-m-d H:i:s'),
                  );

      $mail = new Mail();
      $mail->setMailBody($data);
      $mail->sendMail('Test Sample Array');
      exit('Message Sent!');
   }
967740
public function get_samples($sampleids) {
        global $DB;

        list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
        $courses = $DB->get_records_select('course', "id $sql", $params);

        $courseids = array_keys($courses);
        $sampleids = array_combine($courseids, $courseids);

        $courses = array_map(function($course) {
            return array('course' => $course, 'context' => \context_course::instance($course->id));
        }, $courses);

        // No related data attached.
        return array($sampleids, $courses);
    }
681982
static Collection<Sample> samples(Collection<SampleDTO> samples) {
        return Collections2.transform(samples, DTO_TO_SAMPLE);
    }
623506
protected function getBestNominalSplit(array $samples, array $targets, int $col) : array
    {
        $values = array_column($samples, $col);
        $valueCounts = array_count_values($values);
        $distinctVals= array_keys($valueCounts);

        $split = null;

        foreach (['=', '!='] as $operator) {
            foreach ($distinctVals as $val) {
                list($errorRate, $prob) = $this->calculateErrorRate($targets, $val, $operator, $values);

                if ($split == null || $split['trainingErrorRate'] < $errorRate) {
                    $split = ['value' => $val, 'operator' => $operator,
                        'prob' => $prob, 'column' => $col,
                        'trainingErrorRate' => $errorRate];
                }
            }
        }

        return $split;
    }
1222162
public function transform(array $sample)
    {
        if (!$this->fit) {
            throw new \Exception("KernelPCA has not been fitted with respect to original dataset, please run KernelPCA::fit() first");
        }

        if (is_array($sample[0])) {
            throw new \Exception("KernelPCA::transform() accepts only one-dimensional arrays");
        }

        $pairs = $this->getDistancePairs($sample);

        return $this->projectSample($pairs);
    }