https://github.com/mljs/simple-clustering
Extracts the isolated sub-blocs of a binary matrix
https://github.com/mljs/simple-clustering
Last synced: 8 months ago
JSON representation
Extracts the isolated sub-blocs of a binary matrix
- Host: GitHub
- URL: https://github.com/mljs/simple-clustering
- Owner: mljs
- Created: 2016-08-08T13:37:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-10-09T12:49:53.000Z (about 5 years ago)
- Last Synced: 2025-04-11T06:05:47.721Z (8 months ago)
- Language: JavaScript
- Size: 75.2 KB
- Stars: 0
- Watchers: 7
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-clustering
Finds the isolated clusters from a similarity/connectivity matrix.
The input could be a matrix (array of arrays) or it could be a single array containing the values of the upper triangular of that matrix.
By default the function returns a clustering matrix: It is a binary row wise matrix, where each row has n components. The ones at row i and column j indicates that element j belong to cluster i.
## Installation
`$ npm install ml-simple-clustering`
## Usage
### As an ES module
```js
import { simpleClustering } from 'ml-simple-clustering';
const clusters = simpleClustering(dataMatrix, options);
```
### As a CommonJS module
```js
const { simpleClustering } = require('ml-simple-clustering');
const clusters = simpleClustering(dataMatrix, options);
```
## [API Documentation](https://mljs.github.io/simpleClustering/docs/globals.html)
In order to get a general idea of the problem you could also check the [Wikipedia article](https://en.wikipedia.org/wiki/Flood_fill).
## Examples
```js
const { simpleClustering } = require('ml-simple-clustering');
let matrix = [
[1, 2, 0, 0],
[1, 2, 0, 0],
[0, 0, 3, 4],
[0, 0, 5, 6],
];
let clusters = simpleClustering(matrix, {
threshold: 0,
out: 'values',
});
console.log(`clusters = ${clusters}`);
/**
clusters = [
[
[1, 2],
[1, 2],
],
[
[3, 4],
[5, 6],
],
]
*/
```
## License
[MIT](./LICENSE)