[6] | 1 | package weka.clusterers; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | import weka.clusterers.forMetisMQI.GraphAlgorithms; |
---|
[9] | 5 | import weka.clusterers.forMetisMQI.UndirectedGraph; |
---|
[6] | 6 | import weka.core.Capabilities; |
---|
| 7 | import weka.core.Instance; |
---|
| 8 | import weka.core.Instances; |
---|
| 9 | import weka.core.Capabilities.Capability; |
---|
| 10 | |
---|
| 11 | public class SimpleClusterer extends AbstractClusterer { |
---|
| 12 | |
---|
| 13 | private int numberOfClusters = 0; |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | private static final long serialVersionUID = 1L; |
---|
| 19 | |
---|
| 20 | @Override |
---|
| 21 | public void buildClusterer(Instances data) throws Exception { |
---|
| 22 | getCapabilities().testWithFail(data); |
---|
| 23 | |
---|
[9] | 24 | UndirectedGraph g = new UndirectedGraph(); |
---|
| 25 | g.loadFromInstance(data); |
---|
[6] | 26 | GraphAlgorithms ga = new GraphAlgorithms(); |
---|
[7] | 27 | ga.METIS(g); |
---|
[6] | 28 | numberOfClusters = 1; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | @Override |
---|
| 32 | public int clusterInstance(Instance instance) throws Exception { |
---|
| 33 | return 0; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | @Override |
---|
| 37 | public double[] distributionForInstance(Instance instance) |
---|
| 38 | throws Exception { |
---|
| 39 | double[] d = new double[numberOfClusters()]; |
---|
| 40 | d[clusterInstance(instance)] = 1.0; |
---|
| 41 | return d; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | @Override |
---|
| 45 | public Capabilities getCapabilities() { |
---|
| 46 | Capabilities result = super.getCapabilities(); |
---|
| 47 | result.enable(Capability.NUMERIC_ATTRIBUTES); |
---|
| 48 | result.enable(Capability.NO_CLASS); |
---|
| 49 | return result; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | @Override |
---|
| 53 | public int numberOfClusters() throws Exception { |
---|
| 54 | return numberOfClusters; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Main method for executing this clusterer. |
---|
| 59 | * |
---|
| 60 | * @param args |
---|
| 61 | * the options, use "-h" to display options |
---|
| 62 | */ |
---|
| 63 | public static void main(String[] args) { |
---|
| 64 | AbstractClusterer.runClusterer(new SimpleClusterer(), args); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | } |
---|