https://github.com/tdebatty/php-clustering
Clustering algorithms for PHP
https://github.com/tdebatty/php-clustering
Last synced: 3 months ago
JSON representation
Clustering algorithms for PHP
- Host: GitHub
- URL: https://github.com/tdebatty/php-clustering
- Owner: tdebatty
- Created: 2013-07-30T09:52:26.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-12-31T10:49:25.000Z (about 11 years ago)
- Last Synced: 2025-03-26T02:51:07.217Z (10 months ago)
- Language: PHP
- Size: 146 KB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
php-clustering
==============
Clustering algorithms for PHP
Usage
-----
```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);
```