_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q26800
Parser.parseUnknown
train
private function parseUnknown(&$var, BasicObject $o) { $o->type = 'unknown'; $this->applyPlugins($var, $o, self::TRIGGER_SUCCESS); return $o; }
php
{ "resource": "" }
q26801
Parser.applyPlugins
train
private function applyPlugins(&$var, BasicObject &$o, $trigger) { $break_stash = $this->parse_break; /** @var bool Psalm bug workaround */ $this->parse_break = false; $plugins = array(); if (isset($this->plugins[$o->type][$trigger])) { $plugins = $this->plugins...
php
{ "resource": "" }
q26802
Plugin.renderLockedHeader
train
public function renderLockedHeader(BasicObject $o, $content) { $header = '<dt class="kint-parent kint-locked">'; if (RichRenderer::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) { $header .= '<span class="kint-access-path-trigger" title="Show access path">&rlarr;</span>'; ...
php
{ "resource": "" }
q26803
ColorRepresentation.hslToRgb
train
public static function hslToRgb($h, $s, $l) { if (\min($h, $s, $l) < 0) { throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0'); } if ($h > 360 || \max($s, $l) > 100) { throw new InvalidArgumentException('The parameters for hslToR...
php
{ "resource": "" }
q26804
ColorRepresentation.rgbToHsl
train
public static function rgbToHsl($red, $green, $blue) { if (\min($red, $green, $blue) < 0) { throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0'); } if (\max($red, $green, $blue) > 0xFF) { throw new InvalidArgumentException('The p...
php
{ "resource": "" }
q26805
ColorRepresentation.hueToRgb
train
private static function hueToRgb($m1, $m2, $hue) { $hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue); if ($hue * 6 < 1) { return $m1 + ($m2 - $m1) * $hue * 6; } if ($hue * 2 < 1) { return $m2; } if ($hue * 3 < 2) { retur...
php
{ "resource": "" }
q26806
BasicObject.blank
train
public static function blank($name = null, $access_path = null) { $o = new self(); $o->name = $name; $o->access_path = $access_path; return $o; }
php
{ "resource": "" }
q26807
DocstringRepresentation.getDocstringWithoutComments
train
public function getDocstringWithoutComments() { if (!$this->contents) { return null; } $string = \substr($this->contents, 3, -2); $string = \preg_replace('/^\\s*\\*\\s*?(\\S|$)/m', '\\1', $string); return \trim($string); }
php
{ "resource": "" }
q26808
XmlPlugin.xmlToDOMDocument
train
protected static function xmlToDOMDocument($var, $parent_path) { // There's no way to check validity in DOMDocument without making errors. For shame! if (!self::xmlToSimpleXML($var, $parent_path)) { return null; } $xml = new DOMDocument(); $xml->loadXML($var); ...
php
{ "resource": "" }
q26809
Mozscape.getPageAuthority
train
public static function getPageAuthority($url = false) { $data = static::getCols('34359738368', $url); return (parent::noDataDefaultValue() == $data) ? $data : $data['upa']; }
php
{ "resource": "" }
q26810
Mozscape.getDomainAuthority
train
public static function getDomainAuthority($url = false) { $data = static::getCols('68719476736', Helper\Url::parseHost($url)); return (parent::noDataDefaultValue() == $data) ? $data : $data['pda']; }
php
{ "resource": "" }
q26811
Mozscape.getMozRank
train
public static function getMozRank($url = false) { $data = static::getCols('16384', $url); return (parent::noDataDefaultValue() == $data) ? $data : $data['umrp']; }
php
{ "resource": "" }
q26812
Mozscape.getMozRankRaw
train
public static function getMozRankRaw($url = false) { $data = static::getCols('16384', $url); return (parent::noDataDefaultValue() == $data) ? $data : number_format($data['umrr'], 16); }
php
{ "resource": "" }
q26813
SEOstats.getUrl
train
public static function getUrl($url = false) { $url = false !== $url ? $url : self::$_url; return $url; }
php
{ "resource": "" }
q26814
Url.isRfc
train
public static function isRfc($url) { if(isset($url) && 1 < strlen($url)) { $host = self::parseHost($url); $scheme = strtolower(parse_url($url, PHP_URL_SCHEME)); if (false !== $host && ($scheme == 'http' || $scheme == 'https')) { $pattern = '([A-Za-z][A-...
php
{ "resource": "" }
q26815
Services_JSON.utf162utf8
train
function utf162utf8($utf16) { // oh please oh please oh please oh please oh please if(function_exists('mb_convert_encoding')) { return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); } $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); switch(true) { c...
php
{ "resource": "" }
q26816
Json.decode
train
public static function decode($str, $assoc = false) { if (!function_exists('json_decode')) { $j = self::getJsonService(); return $j->decode($str); } else { return $assoc ? json_decode($str, true) : json_decode($str); } }
php
{ "resource": "" }
q26817
Google.getPageRank
train
public static function getPageRank($url = false) { // Composer autoloads classes out of the SEOstats namespace. // The custom autolader, however, does not. So we need to include it first. if(!class_exists('\GTB_PageRank')) { require_once realpath(__DIR__ . '/3rdparty/GTB_PageRank...
php
{ "resource": "" }
q26818
Google.getSearchResultsTotal
train
public static function getSearchResultsTotal($url = false) { $url = parent::getUrl($url); $url = sprintf(Config\Services::GOOGLE_APISEARCH_URL, 1, $url); $ret = static::_getPage($url); $obj = Helper\Json::decode($ret); return !isset($obj->responseData->cursor->estimatedResu...
php
{ "resource": "" }
q26819
Sistrix.getVisibilityIndex
train
public static function getVisibilityIndex($url = false) { $url = parent::getUrl($url); $domain = Helper\Url::parseHost($url); $dataUrl = sprintf(Config\Services::SISTRIX_VI_URL, urlencode($domain)); $html = static::_getPage($dataUrl); @preg_match_all('#<h3>(.*?)<\/h3>#s...
php
{ "resource": "" }
q26820
Sistrix.getVisibilityIndexByApi
train
public static function getVisibilityIndexByApi($url = false, $db = false) { self::guardApiKey(); self::guardApiCredits(); $url = parent::getUrl($url); $domain = static::getDomainFromUrl($url); $database = static::getValidDatabase($db); $dataUrl = sprintf(Config\Serv...
php
{ "resource": "" }
q26821
HttpRequest.getHttpCode
train
public static function getHttpCode($url) { $ua = self::getUserAgent(); $curlopt_proxy = self::getProxy(); $curlopt_proxyuserpwd = self::getProxyUserPwd(); $ch = curl_init($url); curl_setopt_array($ch, array( CURLOPT_USERAGENT => $ua, CURLOPT_RET...
php
{ "resource": "" }
q26822
Alexa.getDailyRank
train
public static function getDailyRank($url = false) { self::setRankingKeys($url); if (0 == self::$_rankKeys['1d']) { return parent::noDataDefaultValue(); } $xpath = self::_getXPath($url); $nodes = @$xpath->query("//*[@id='rank']/table/tr[" . self::$_rankKeys['1d'] ...
php
{ "resource": "" }
q26823
Alexa.getGlobalRank
train
public static function getGlobalRank($url = false) { /* self::setRankingKeys($url); if (0 == self::$_rankKeys['3m']) { return parent::noDataDefaultValue(); } */ $xpath = self::_getXPath($url); $xpathQueryList = array( "//*[@id='traffi...
php
{ "resource": "" }
q26824
Alexa.setRankingKeys
train
public static function setRankingKeys($url = false) { $xpath = self::_getXPath($url); $nodes = @$xpath->query("//*[@id='rank']/table/tr"); if (5 == $nodes->length) { self::$_rankKeys = array( '1d' => 2, '7d' => 3, '1m' => 4, ...
php
{ "resource": "" }
q26825
GaussianMixture.priors
train
public function priors() : array { $priors = []; if (is_array($this->priors)) { $total = logsumexp($this->priors); foreach ($this->priors as $class => $probability) { $priors[$class] = exp($probability - $total); } } return $prio...
php
{ "resource": "" }
q26826
GaussianMixture.initialize
train
protected function initialize(Dataset $dataset) : array { $centroids = $this->seeder->seed($dataset, $this->k); $kernel = new Euclidean(); $clusters = array_fill(0, $this->k, []); foreach ($dataset as $sample) { $bestDistance = INF; $bestCluster = -1; ...
php
{ "resource": "" }
q26827
PReLU.compute
train
protected function compute(Matrix $z) : Matrix { if (!$this->alpha) { throw new RuntimeException('Layer is not initialized.'); } $alphas = $this->alpha->w(); $computed = []; foreach ($z as $i => $row) { $alpha = $alphas[$i]; $activation...
php
{ "resource": "" }
q26828
PReLU.differentiate
train
protected function differentiate(Matrix $z) : Matrix { if (!$this->alpha) { throw new RuntimeException('Layer has not been initlaized.'); } $alphas = $this->alpha->w(); $gradient = []; foreach ($z as $i => $row) { $alpha = $alphas[$i]; ...
php
{ "resource": "" }
q26829
RandIndex.comb
train
public static function comb(int $n, int $k = 2) : int { return $k === 0 ? 1 : (int) (($n * self::comb($n - 1, $k - 1)) / $k); }
php
{ "resource": "" }
q26830
Params.ints
train
public static function ints(int $min, int $max, int $n = 10) : array { if (($max - $min) < 0) { throw new InvalidArgumentException('Maximum cannot be' . ' less than minimum.'); } if ($n < 1) { throw new InvalidArgumentException('Cannot generate less' ...
php
{ "resource": "" }
q26831
Params.floats
train
public static function floats(float $min, float $max, int $n = 10) : array { if (($max - $min) < 0.) { throw new InvalidArgumentException('Maximum cannot be' . ' less than minimum.'); } if ($n < 1) { throw new InvalidArgumentException('Cannot generate...
php
{ "resource": "" }
q26832
Params.grid
train
public static function grid(float $min, float $max, int $n = 10) : array { if ($min > $max) { throw new InvalidArgumentException('Max cannot be less' . ' then min.'); } if ($n < 2) { throw new InvalidArgumentException('Cannot generate less' ...
php
{ "resource": "" }
q26833
Params.args
train
public static function args($object) : array { if (!is_object($object)) { throw new InvalidArgumentException('Argument must be' . ' an object ' . gettype($object) . ' found.'); } $reflector = new ReflectionClass($object); $constructor = $reflector->getCo...
php
{ "resource": "" }
q26834
Params.stringify
train
public static function stringify(array $constructor, string $equator = '=', string $separator = ' ') : string { $strings = []; foreach ($constructor as $arg => $param) { if (is_object($param)) { $param = self::shortName($param); } if (is_array($p...
php
{ "resource": "" }
q26835
CommitteeMachine.train
train
public function train(Dataset $dataset) : void { if ($this->type === self::CLASSIFIER or $this->type === self::REGRESSOR) { if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This estimator requires a' . ' labeled training set.'); ...
php
{ "resource": "" }
q26836
CommitteeMachine.decideClass
train
public function decideClass(array $votes) { $scores = array_fill_keys($this->classes, 0.); foreach ($votes as $i => $vote) { $scores[$vote] += $this->influences[$i]; } return argmax($scores); }
php
{ "resource": "" }
q26837
CommitteeMachine.decideAnomaly
train
public function decideAnomaly(array $votes) : int { $scores = array_fill(0, 2, 0.); foreach ($votes as $i => $vote) { $scores[$vote] += $this->influences[$i]; } return argmax($scores); }
php
{ "resource": "" }
q26838
CommitteeMachine._train
train
public function _train(Learner $estimator, Dataset $dataset) : Learner { $estimator->train($dataset); return $estimator; }
php
{ "resource": "" }
q26839
Deferred.result
train
public function result() : Matrix { if (!$this->result) { $this->result = call_user_func($this->computation); } return $this->result; }
php
{ "resource": "" }
q26840
GaussianNB.train
train
public function train(Dataset $dataset) : void { if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This Estimator requires a' . ' Labeled training set.'); } DatasetIsCompatibleWithEstimator::check($dataset, $this); $classes = $datas...
php
{ "resource": "" }
q26841
GaussianNB.partial
train
public function partial(Dataset $dataset) : void { if (empty($this->weights) or empty($this->means) or empty($this->variances)) { $this->train($dataset); return; } if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This Estimator req...
php
{ "resource": "" }
q26842
BatchNorm.back
train
public function back(Deferred $prevGradient, Optimizer $optimizer) : Deferred { if (!$this->beta or !$this->gamma) { throw new RuntimeException('Layer has not been initilaized.'); } if (!$this->stdInv or !$this->xHat) { throw new RuntimeException('Must perform forwar...
php
{ "resource": "" }
q26843
ClassificationTree.terminate
train
protected function terminate(Labeled $dataset) : BinaryNode { $n = $dataset->numRows(); $labels = $dataset->labels(); $counts = array_count_values($labels); $outcome = argmax($counts); $probabilities = []; foreach ($counts as $class => $count) { $prob...
php
{ "resource": "" }
q26844
ClassificationTree.splitImpurity
train
protected function splitImpurity(array $groups) : float { $n = array_sum(array_map('count', $groups)); $impurity = 0.; foreach ($groups as $dataset) { $k = $dataset->numRows(); if ($k < 2) { continue 1; } $counts = array_cou...
php
{ "resource": "" }
q26845
DataFrame.columnType
train
public function columnType(int $index) : int { if (empty($this->samples)) { throw new RuntimeException('Cannot determine data type' . ' of an empty data frame.'); } $sample = reset($this->samples); if (!isset($sample[$index])) { throw new Inv...
php
{ "resource": "" }
q26846
DataFrame.columns
train
public function columns() : array { if ($this->numRows() > 1) { return array_map(null, ...$this->samples); } $n = $this->numColumns(); $columns = []; for ($i = 0; $i < $n; $i++) { $columns[] = array_column($this->samples, $i); } ret...
php
{ "resource": "" }
q26847
DataFrame.columnsByType
train
public function columnsByType(int $type) : array { $n = $this->numColumns(); $columns = []; for ($i = 0; $i < $n; $i++) { if ($this->columnType($i) === $type) { $columns[$i] = $this->column($i); } } return $columns; }
php
{ "resource": "" }
q26848
LogisticRegression.partial
train
public function partial(Dataset $dataset) : void { if (!$this->network) { $this->train($dataset); return; } if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This estimator requires a' . ' labeled training set.'); ...
php
{ "resource": "" }
q26849
GradientBoost.compatibility
train
public function compatibility() : array { $compatibility = array_intersect($this->base->compatibility(), $this->booster->compatibility()); return array_values($compatibility); }
php
{ "resource": "" }
q26850
GradientBoost.predict
train
public function predict(Dataset $dataset) : array { if (empty($this->ensemble)) { throw new RuntimeException('Estimator has not been trained.'); } DatasetIsCompatibleWithEstimator::check($dataset, $this); $predictions = $this->base->predict($dataset); foreach (...
php
{ "resource": "" }
q26851
TSNE.pairwiseDistances
train
protected function pairwiseDistances(Matrix $samples) : Matrix { $distances = []; foreach ($samples as $a) { $temp = []; foreach ($samples as $b) { $temp[] = $this->kernel->compute($a, $b); } $distances[] = $temp; } ...
php
{ "resource": "" }
q26852
TSNE.highAffinities
train
protected function highAffinities(Matrix $distances) : Matrix { $zeros = array_fill(0, count($distances), 0); $p = []; foreach ($distances as $i => $row) { $affinities = $zeros; $minBeta = -INF; $maxBeta = INF; $beta = 1.; for ($...
php
{ "resource": "" }
q26853
TSNE.gradient
train
protected function gradient(Matrix $p, Matrix $y, Matrix $distances) : Matrix { $q = $distances->square() ->divide($this->degrees) ->add(1.) ->pow((1. + $this->degrees) / -2.); $qSigma = $q->sum()->multiply(2.); $q = $q->divide($qSigma) ->cli...
php
{ "resource": "" }
q26854
BootstrapAggregator.train
train
public function train(Dataset $dataset) : void { if ($this->type() === self::CLASSIFIER or $this->type() === self::REGRESSOR) { if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This estimator requires a' . ' labeled training set.'); ...
php
{ "resource": "" }
q26855
Isolator.split
train
public static function split(Dataset $dataset) : self { $column = rand(0, $dataset->numColumns() - 1); $sample = $dataset[rand(0, count($dataset) - 1)]; $value = $sample[$column]; $groups = $dataset->partition($column, $value); return new self($column, $value, $groups); ...
php
{ "resource": "" }
q26856
MeanShift.estimateRadius
train
public static function estimateRadius(Dataset $dataset, float $percentile = 30., ?Distance $kernel = null) : float { if ($percentile < 0. or $percentile > 100.) { throw new InvalidArgumentException('Percentile must be between' . " 0 and 100, $percentile given."); } ...
php
{ "resource": "" }
q26857
MeanShift.assign
train
protected function assign(array $sample) : int { $bestDistance = INF; $bestCluster = -1; foreach ($this->centroids as $cluster => $centroid) { $distance = $this->kernel->compute($sample, $centroid); if ($distance < $bestDistance) { $bestDistance = $d...
php
{ "resource": "" }
q26858
MeanShift.membership
train
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 $dista...
php
{ "resource": "" }
q26859
LODA.logLikelihood
train
protected function logLikelihood(Matrix $z) : array { $likelihoods = array_fill(0, $z->n(), 0.); foreach ($z as $i => $values) { [$edges, $counts, $densities] = $this->histograms[$i]; foreach ($values as $j => $value) { foreach ($edges as $k => $edge...
php
{ "resource": "" }
q26860
GaussianRandomProjector.minDimensions
train
public static function minDimensions(int $n, float $maxDistortion = 0.1) : int { return (int) round(4. * log($n) / ($maxDistortion ** 2 / 2. - $maxDistortion ** 3 / 3.)); }
php
{ "resource": "" }
q26861
Unlabeled.tail
train
public function tail(int $n = 10) : self { return self::quick(array_slice($this->samples, -$n)); }
php
{ "resource": "" }
q26862
Unlabeled.append
train
public function append(Dataset $dataset) : Dataset { return self::quick(array_merge($this->samples, $dataset->samples())); }
php
{ "resource": "" }
q26863
Unlabeled.batch
train
public function batch(int $n = 50) : array { $batches = []; $samples = $this->samples; foreach (array_chunk($this->samples, $n) as $batch) { $batches[] = self::quick($batch); } return $batches; }
php
{ "resource": "" }
q26864
ExtraTreeRegressor.split
train
protected function split(Labeled $dataset) : Decision { $bestImpurity = INF; $bestColumn = $bestValue = null; $bestGroups = []; $max = $dataset->numRows() - 1; shuffle($this->columns); foreach (array_slice($this->columns, 0, $this->maxFeatures) as $column) { ...
php
{ "resource": "" }
q26865
GridSearch.combineGrid
train
public static function combineGrid(array $grid) : array { $combinations = [[]]; foreach ($grid as $i => $params) { $append = []; foreach ($combinations as $product) { foreach ($params as $param) { $product[$i] = $param; ...
php
{ "resource": "" }
q26866
GridSearch.train
train
public function train(Dataset $dataset) : void { if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This Estimator requires a' . ' Labeled training set.'); } DatasetIsCompatibleWithEstimator::check($dataset, $this); if ($this->logger...
php
{ "resource": "" }
q26867
GridSearch.score
train
public function score(Learner $estimator, Labeled $dataset) : float { return $this->validator->test($estimator, $dataset, $this->metric); }
php
{ "resource": "" }
q26868
Labeled.stack
train
public static function stack(array $datasets) : self { $samples = $labels = []; foreach ($datasets as $dataset) { if (!$dataset instanceof self) { throw new InvalidArgumentException('Dataset must be' . ' an instance of Labeled, ' . get_class($dataset)...
php
{ "resource": "" }
q26869
Labeled.zip
train
public function zip() : array { $rows = $this->samples; foreach ($rows as $i => &$row) { $row[] = $this->labels[$i]; } return $rows; }
php
{ "resource": "" }
q26870
Labeled.label
train
public function label(int $index) { if (!isset($this->labels[$index])) { throw new InvalidArgumentException("Row at offset $index" . ' does not exist.'); } return $this->labels[$index]; }
php
{ "resource": "" }
q26871
Labeled.labelType
train
public function labelType() : ?int { if (!isset($this->labels[0])) { return null; } return DataType::determine($this->labels[0]); }
php
{ "resource": "" }
q26872
Labeled.transformLabels
train
public function transformLabels(callable $fn) : void { $labels = array_map($fn, $this->labels); foreach ($labels as $label) { if (!is_string($label) and !is_numeric($label)) { throw new RuntimeException('Label must be a string or' . ' numeric type, ' ...
php
{ "resource": "" }
q26873
Labeled.leave
train
public function leave(int $n = 1) : self { if ($n < 0) { throw new InvalidArgumentException('Cannot leave less than 0 samples.'); } return $this->splice($n, $this->numRows()); }
php
{ "resource": "" }
q26874
Labeled.randomize
train
public function randomize() : self { $order = range(0, $this->numRows() - 1); shuffle($order); array_multisort($order, $this->samples, $this->labels); return $this; }
php
{ "resource": "" }
q26875
Labeled.filterByColumn
train
public function filterByColumn(int $index, callable $fn) : self { $samples = $labels = []; foreach ($this->samples as $i => $sample) { if ($fn($sample[$index])) { $samples[] = $sample; $labels[] = $this->labels[$i]; } } return...
php
{ "resource": "" }
q26876
Labeled.filterByLabel
train
public function filterByLabel(callable $fn) : self { $samples = $labels = []; foreach ($this->labels as $i => $label) { if ($fn($label)) { $samples[] = $this->samples[$i]; $labels[] = $label; } } return self::quick($samples, $...
php
{ "resource": "" }
q26877
Labeled.sortByColumn
train
public function sortByColumn(int $index, bool $descending = false) { $order = $this->column($index); array_multisort( $order, $this->samples, $this->labels, $descending ? SORT_DESC : SORT_ASC ); return $this; }
php
{ "resource": "" }
q26878
Labeled.sortByLabel
train
public function sortByLabel(bool $descending = false) : Dataset { array_multisort( $this->labels, $this->samples, $descending ? SORT_DESC : SORT_ASC ); return $this; }
php
{ "resource": "" }
q26879
Labeled.stratify
train
public function stratify() : array { $strata = []; foreach ($this->_stratify() as $label => $stratum) { $labels = array_fill(0, count($stratum), $label); $strata[$label] = self::quick($stratum, $labels); } return $strata; }
php
{ "resource": "" }
q26880
Labeled.split
train
public function split(float $ratio = 0.5) : array { if ($ratio <= 0 or $ratio >= 1) { throw new InvalidArgumentException('Split ratio must be strictly' . " between 0 and 1, $ratio given."); } $n = (int) ($ratio * $this->numRows()); $leftSamples = array_slice...
php
{ "resource": "" }
q26881
Labeled.stratifiedFold
train
public function stratifiedFold(int $k = 10) : array { if ($k < 2) { throw new InvalidArgumentException('Cannot create less than' . " 2 folds, $k given."); } $folds = []; for ($i = 0; $i < $k; $i++) { $samples = $labels = []; fore...
php
{ "resource": "" }
q26882
Labeled._stratify
train
protected function _stratify() : array { $strata = []; foreach ($this->labels as $index => $label) { $strata[$label][] = $this->samples[$index]; } return $strata; }
php
{ "resource": "" }
q26883
Labeled.batch
train
public function batch(int $n = 50) : array { $sChunks = array_chunk($this->samples, $n); $lChunks = array_chunk($this->labels, $n); $batches = []; foreach ($sChunks as $i => $samples) { $batches[] = self::quick($samples, $lChunks[$i]); } return $batches...
php
{ "resource": "" }
q26884
Labeled.randomWeightedSubsetWithReplacement
train
public function randomWeightedSubsetWithReplacement(int $n, array $weights) : self { if ($n < 1) { throw new InvalidArgumentException('Cannot generate a' . " subset of less than 1 sample, $n given."); } if (count($weights) !== count($this->samples)) { ...
php
{ "resource": "" }
q26885
FuzzyCMeans.membership
train
protected function membership(array $sample) : array { $membership = $deltas = []; foreach ($this->centroids as $centroid) { $deltas[] = $this->kernel->compute($sample, $centroid); } foreach ($this->centroids as $cluster => $centroid) { $alpha = $this->kerne...
php
{ "resource": "" }
q26886
Hypersphere.split
train
public static function split(Dataset $dataset, Distance $kernel) : self { $samples = $dataset->samples(); $center = Matrix::quick($samples) ->transpose() ->mean() ->asArray(); $distances = []; foreach ($samples as $sample) { ...
php
{ "resource": "" }
q26887
DummyClassifier.train
train
public function train(Dataset $dataset) : void { if (!$dataset instanceof Labeled) { throw new InvalidArgumentException('This estimator requires a' . ' labeled training set.'); } $this->strategy->fit($dataset->labels()); $this->trained = true; }
php
{ "resource": "" }
q26888
DummyClassifier.predict
train
public function predict(Dataset $dataset) : array { if (!$this->trained) { throw new RuntimeException('The learner has not' . ' been trained.'); } $n = $dataset->numRows(); $predictions = []; for ($i = 0; $i < $n; $i++) { $pr...
php
{ "resource": "" }
q26889
Pipeline.trained
train
public function trained() : bool { return ($this->estimator instanceof Learner and $this->estimator->trained() and $this->fitted) or $this->fitted; }
php
{ "resource": "" }
q26890
Pipeline.train
train
public function train(Dataset $dataset) : void { $this->fit($dataset); if ($this->estimator instanceof Learner) { $this->estimator->train($dataset); } $this->fitted = true; }
php
{ "resource": "" }
q26891
Pipeline.partial
train
public function partial(Dataset $dataset) : void { if ($this->elastic) { $this->update($dataset); } if ($this->estimator instanceof Online) { $this->estimator->partial($dataset); } }
php
{ "resource": "" }
q26892
Pipeline.predict
train
public function predict(Dataset $dataset) : array { $this->preprocess($dataset); return $this->estimator->predict($dataset); }
php
{ "resource": "" }
q26893
Pipeline.fit
train
protected function fit(Dataset $dataset) : void { foreach ($this->transformers as $transformer) { if ($transformer instanceof Stateful) { $transformer->fit($dataset); if ($this->logger) { $this->logger->info('Fitted ' ....
php
{ "resource": "" }
q26894
Pipeline.update
train
protected function update(Dataset $dataset) : void { foreach ($this->transformers as $transformer) { if ($transformer instanceof Elastic) { $transformer->update($dataset); if ($this->logger) { $this->logger->info('Updated ' ...
php
{ "resource": "" }
q26895
Pipeline.preprocess
train
protected function preprocess(Dataset $dataset) : void { foreach ($this->transformers as $transformer) { $dataset->apply($transformer); } }
php
{ "resource": "" }
q26896
BinaryNode.children
train
public function children() : Generator { if ($this->left) { yield $this->left; } if ($this->right) { yield $this->right; } }
php
{ "resource": "" }
q26897
BinaryNode.height
train
public function height() : int { return 1 + max( $this->left ? $this->left->height() : 0, $this->right ? $this->right->height() : 0 ); }
php
{ "resource": "" }
q26898
BinaryNode.balance
train
public function balance() : int { return ($this->right ? $this->right->height() : 0) - ($this->left ? $this->left->height() : 0); }
php
{ "resource": "" }
q26899
BinaryNode.attachLeft
train
public function attachLeft(BinaryNode $node) : void { $node->setParent($this); $this->left = $node; }
php
{ "resource": "" }