webd/聚类

此软件包最新版本(dev-master)没有可用的许可证信息。

聚类算法

dev-master 2014-12-31 10:49 UTC

This package is auto-updated.

Last update: 2024-09-19 22:39:40 UTC


README

PHP的聚类算法

用法

use \webd\clustering\KMeans;
use \webd\clustering\GMeans;
use \webd\clustering\RnPoint;

// These examples use points in Rn, but some algorithms (like KMeans)
// support points in non-euclidean spaces
$points = array(
    new RnPoint(array(1, 1)),
    new RnPoint(array(2, 2)),
    new RnPoint(array(2, 3))
);

// Simple KMeans
$kmeans = new KMeans;
$kmeans->k = 2;
$kmeans->n = 10;
$kmeans->points = $points;
$kmeans->run();

var_dump($kmeans->centers);

// GMeans (no need to specify the number of clusters)
$nd = new \webd\stats\NormalDistribution();

// Create points around (1, 1) and (9, 9)
$points = array();
for ($i = 0; $i < 100; $i++) {
    $points[] = new RnPoint($nd->sample()+1, $nd->sample()+1);
    $points[] = new RnPoint($nd->sample()+9, $nd->sample()+9);
}

$gmeans = new GMeans();
$gmeans->points = $points;
$gmeans->run();
var_dump($gmeans->found_centers);