guineu.modules.dataanalysis.clustering.hierarchical.HierarClusterer.java Source code

Java tutorial

Introduction

Here is the source code for guineu.modules.dataanalysis.clustering.hierarchical.HierarClusterer.java

Source

/*
 * Copyright 2007-2013 VTT Biotechnology
 * This file is part of Guineu.
 *
 * Guineu is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * Guineu is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Guineu; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */
/**
 * @author Taken from MZmine2
 * http://mzmine.sourceforge.net/
 */

package guineu.modules.dataanalysis.clustering.hierarchical;

import guineu.modules.dataanalysis.clustering.ClusteringAlgorithm;
import guineu.modules.dataanalysis.clustering.VisualizationType;
import guineu.parameters.ParameterSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import weka.clusterers.Clusterer;
import weka.clusterers.HierarchicalClusterer;
import weka.core.Instances;

public class HierarClusterer implements ClusteringAlgorithm {

    private ParameterSet parameters;

    public HierarClusterer() {
        parameters = new HierarClustererParameters();
    }

    public String toString() {
        return "Hierarchical Clusterer";
    }

    public ParameterSet getParameterSet() {
        return parameters;
    }

    public List<Integer> getClusterGroups(Instances dataset) {
        return null;
    }

    public String getHierarchicalCluster(Instances dataset) {
        Clusterer clusterer = new HierarchicalClusterer();
        String[] options = new String[5];
        LinkType link = parameters.getParameter(HierarClustererParameters.linkType).getValue();
        DistanceType distanceType = parameters.getParameter(HierarClustererParameters.distanceType).getValue();
        options[0] = "-L";
        options[1] = link.name();
        options[2] = "-A";
        switch (distanceType) {
        case EUCLIDIAN:
            options[3] = "weka.core.EuclideanDistance";
            break;
        case CHEBYSHEV:
            options[3] = "weka.core.ChebyshevDistance";
            break;
        case MANHATTAN:
            options[3] = "weka.core.ManhattanDistance";
            break;
        case MINKOWSKI:
            options[3] = "weka.core.MinkowskiDistance";
            break;
        }

        options[4] = "-P";
        try {
            ((HierarchicalClusterer) clusterer).setOptions(options);
            clusterer.buildClusterer(dataset);
            return ((HierarchicalClusterer) clusterer).graph();
        } catch (Exception ex) {
            Logger.getLogger(HierarClusterer.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public VisualizationType getVisualizationType() {
        return null;
    }

    public int getNumberOfGroups() {
        return 1;
    }

}