run method

List<List<int>> run(
  1. List<List<double>> dataset
)

Run clustering process, add configs in constructor

Implementation

List<List<int>> run(List<List<double>> dataset) {
  if (dataset == null) {
    throw new Exception("Dataset must not be null");
  }

  //save dataset to class' variable
  this.dataset = dataset;

  //initial variables
  _cluster = [];
  _currentLabel = -1;
  _label = List.generate(dataset.length, (_) => -1);

  for (int i = 0; i < dataset.length; i++) {
    //skip labeled points
    if (_label![i] != -1) continue;

    //neighbor indexes
    List<int> neighbors = _rangeQuery(dataset[i]);

    if (neighbors.length < minPoints) {
      _noise.add(i);
    } else {
      //add new cluster
      List<int> newCluster = [];
      _currentLabel = _currentLabel! + 1;
      _cluster.add(newCluster);
      _expandCluster(i, neighbors, newCluster);
    }
  }

  return _cluster;
}