Return the membership of a sample to each of the c centroids.

@param array $sample
@return array
336145
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->kernel->compute($sample, $centroid);

            $sigma = 0.;

            foreach ($deltas as $delta) {
                $sigma += ($alpha / ($delta ?: EPSILON)) ** $this->lambda;
            }

            $membership[$cluster] = 1. / ($sigma ?: EPSILON);
        }

        return $membership;
    }
895749
public function calculate_sample($sampleid, $sampleorigin, $notusedstarttime = false, $notusedendtime = false) {

        if ($sampleorigin === 'course_modules') {
            $cm = $this->retrieve('course_modules', $sampleid);
            $cminfo = \cm_info::create($cm);

            $socialbreadthindicator = $this->get_social_indicator($cminfo->modname);
            $potentiallevel = $socialbreadthindicator->get_social_breadth_level($cminfo);
            if ($potentiallevel > community_of_inquiry_activity::MAX_SOCIAL_LEVEL) {
                $this->level_not_accepted($potentiallevel);
            }

        } else {
            $course = $this->retrieve('course', $sampleid);
            $modinfo = get_fast_modinfo($course);

            $cms = $modinfo->get_cms();
            if (!$cms) {
                return self::get_min_value();
            }

            $potentiallevel = 0;
            foreach ($cms as $cm) {
                if (!$socialbreadthindicator = $this->get_social_indicator($cm->modname)) {
                    continue;
                }
                $level = $socialbreadthindicator->get_social_breadth_level($cm);
                if ($level > community_of_inquiry_activity::MAX_SOCIAL_LEVEL) {
                    $this->level_not_accepted($level);
                }
                if ($level > $potentiallevel) {
                    $potentiallevel = $level;
                }
            }
        }

        // Core activities social breadth only reaches level 2, until core activities social
        // breadth do not reach level 5 we limit it to what we currently support, which is level 2.
        if ($potentiallevel > 2) {
            $potentiallevel = 2;
        }

        // Supporting only social breadth level 1 and 2 the possible values are -1 or 1.
        $levelscore = round(self::get_max_value() - self::get_min_value(), 2);

        // We substract $levelscore because we want to start from the lower socre and there is no cognitive depth level 0.
        return self::get_min_value() + ($levelscore * $potentiallevel) - $levelscore;
    }
549409
public static function population(array $a, $sample = true)
    {
        if (empty($a)) {
            throw InvalidArgumentException::arrayCantBeEmpty();
        }

        $n = count($a);

        if ($sample && $n === 1) {
            throw InvalidArgumentException::arraySizeToSmall(2);
        }

        $mean = Mean::arithmetic($a);
        $carry = 0.0;
        foreach ($a as $val) {
            $d = $val - $mean;
            $carry += $d * $d;
        }

        if ($sample) {
            --$n;
        }

        return sqrt((float) ($carry / $n));
    }
507503
public function getSamplingNodes()
	{
		$nodes	= array();
		$start	= $this->interval->getStart();
		$distance	= $this->getNodeDistance();
		for( $i = 0; $i<$this->getNodes(); $i++ )
		{
			$x = $start + $i * $distance;
			$nodes[] = $x;
		}
		return $nodes;
	}
664700
protected function predictSampleBinary(array $sample)
    {
        if ($this->evaluate($sample[$this->column], $this->operator, $this->value)) {
            return $this->binaryLabels[0];
        }

        return $this->binaryLabels[1];
    }
647504
public function search(array $sample) : ?Neighborhood
    {
        $current = $this->root;

        while ($current) {
            if ($current instanceof Coordinate) {
                if ($sample[$current->column()] < $current->value()) {
                    $current = $current->left();
                } else {
                    $current = $current->right();
                }

                continue 1;
            }

            if ($current instanceof Neighborhood) {
                return $current;
            }
        }

        return null;
    }
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];
    }
457342
private function powerSet(array $sample): array
    {
        $results = [[]];
        foreach ($sample as $item) {
            foreach ($results as $combination) {
                $results[] = array_merge([$item], $combination);
            }
        }

        return $results;
    }
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);
    }
1137376
public function transform(array &$samples) : void
    {
        foreach ($samples as &$sample) {
            foreach ($sample as &$feature) {
                if (is_string($feature) and is_numeric($feature)) {
                    $feature = (int) $feature == $feature
                        ? (int) $feature
                        : (float) $feature;
                }
            }
        }
    }
994246
private function getBeyondMinimumIndexes(int $samplesCount)
    {
        $indexes = [];
        foreach ($this->frequencies as $token => $frequency) {
            if (($frequency / $samplesCount) < $this->minDF) {
                $indexes[] = $this->getTokenIndex($token);
            }
        }

        return $indexes;
    }
1085938
public function transform(array $sample): array
    {
        if (!$this->fit) {
            throw new InvalidOperationException('LDA has not been fitted with respect to original dataset, please run LDA::fit() first');
        }

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

        return $this->reduce($sample);
    }
58910
def _get_sample_select(samples, keep):
    """"""
    k = np.ones_like(samples, dtype=bool)
    if keep is not None:
        k = np.array([s in keep for s in samples], dtype=bool)
        if np.sum(k) == 0:
            logger.warning("No samples matched the keep list")
    return k
804151
def sample_given_context(self, c, c_dims):
        '''
        
        '''
        return self.sample()[list(set(range(self.ndims)) - set(c_dims))]
726865
private function items(): array
    {
        $items = [];

        foreach ($this->samples as $sample) {
            foreach ($sample as $item) {
                if (!in_array($item, $items, true)) {
                    $items[] = $item;
                }
            }
        }

        return array_map(function ($entry) {
            return [$entry];
        }, $items);
    }
25963
protected function predictSample(array $sample): array
    {
        $predicts = array_values(array_filter($this->getRules(), function ($rule) use ($sample) {
            return $this->equals($rule[self::ARRAY_KEY_ANTECEDENT], $sample);
        }));

        return array_map(function ($rule) {
            return $rule[self::ARRAY_KEY_CONSEQUENT];
        }, $predicts);
    }
118263
protected function inertia(array $samples) : float
    {
        $inertia = 0.;

        foreach ($samples as $sample) {
            foreach ($this->centroids as $centroid) {
                $inertia += $this->kernel->compute($sample, $centroid);
            }
        }

        return $inertia;
    }