public function cluster(TrainingSet $documents, FeatureFactoryInterface $ff)
    {
        // what a complete waste of memory here ...
        // the same data exists in $documents, $docs and
        // the only useful parts are in $this->strategy
        $docs = $this->getDocumentArray($documents, $ff);
        $this->strategy->initializeStrategy($this->dist,$docs);
        unset($docs); // perhaps save some memory

        // start with all the documents being in their
        // own cluster we 'll merge later
        $clusters = range(0,count($documents)-1);
        $c = count($clusters);
        while ($c>1) {
            // ask the strategy which to merge. The strategy
            // will assume that we will indeed merge the returned clusters
            list($i,$j) = $this->strategy->getNextMerge();
            $clusters[$i] = array($clusters[$i],$clusters[$j]);
            unset($clusters[$j]);
            $c--;
        }
        $clusters = array($clusters[$i]);

        // return the dendrogram
        return array($clusters);
    }
public function cluster(TrainingSet $documents, FeatureFactoryInterface $ff)
    {
        // what a complete waste of memory here ...
        // the same data exists in $documents, $docs and
        // the only useful parts are in $this->strategy
        $docs = $this->getDocumentArray($documents, $ff);
        $this->strategy->initializeStrategy($this->dist,$docs);
        unset($docs); // perhaps save some memory

        // start with all the documents being in their
        // own cluster we 'll merge later
        $clusters = range(0,count($documents)-1);
        $c = count($clusters);
        while ($c>1) {
            // ask the strategy which to merge. The strategy
            // will assume that we will indeed merge the returned clusters
            list($i,$j) = $this->strategy->getNextMerge();
            $clusters[$i] = array($clusters[$i],$clusters[$j]);
            unset($clusters[$j]);
            $c--;
        }
        $clusters = array($clusters[$i]);

        // return the dendrogram
        return array($clusters);
    }
public function cluster ( TrainingSet $ documents , FeatureFactoryInterface $ ff ) { // what a complete waste of memory here ... // the same data exists in $documents, $docs and // the only useful parts are in $this->strategy $ docs = $ this -> getDocumentArray ( $ documents , $ ff ) ; $ this -> strategy -> initializeStrategy ( $ this -> dist , $ docs ) ; unset ( $ docs ) ; // perhaps save some memory // start with all the documents being in their // own cluster we 'll merge later $ clusters = range ( 0 , count ( $ documents ) - 1 ) ; $ c = count ( $ clusters ) ; while ( $ c > 1 ) { // ask the strategy which to merge. The strategy // will assume that we will indeed merge the returned clusters list ( $ i , $ j ) = $ this -> strategy -> getNextMerge ( ) ; $ clusters [ $ i ] = array ( $ clusters [ $ i ] , $ clusters [ $ j ] ) ; unset ( $ clusters [ $ j ] ) ; $ c -- ; } $ clusters = array ( $ clusters [ $ i ] ) ; // return the dendrogram return array ( $ clusters ) ; }
Iteratively merge documents together to create an hierarchy of clusters.
While hierarchical clustering only returns one element, it still wraps it
in an array to be consistent with the rest of the clustering methods.

@return array An array containing one element which is the resulting dendrogram
Iteratively merge documents together to create an hierarchy of clusters . While hierarchical clustering only returns one element it still wraps it in an array to be consistent with the rest of the clustering methods .