1 | package weka.clusterers; |
---|
2 | |
---|
3 | |
---|
4 | import weka.clusterers.forMetisMQI.Graph; |
---|
5 | import weka.clusterers.forMetisMQI.GraphAlgorithms; |
---|
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 | |
---|
24 | Graph g = new Graph(data); |
---|
25 | GraphAlgorithms ga = new GraphAlgorithms(); |
---|
26 | ga.METIS(g); |
---|
27 | numberOfClusters = 1; |
---|
28 | } |
---|
29 | |
---|
30 | @Override |
---|
31 | public int clusterInstance(Instance instance) throws Exception { |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | @Override |
---|
36 | public double[] distributionForInstance(Instance instance) |
---|
37 | throws Exception { |
---|
38 | double[] d = new double[numberOfClusters()]; |
---|
39 | d[clusterInstance(instance)] = 1.0; |
---|
40 | return d; |
---|
41 | } |
---|
42 | |
---|
43 | @Override |
---|
44 | public Capabilities getCapabilities() { |
---|
45 | Capabilities result = super.getCapabilities(); |
---|
46 | result.enable(Capability.NUMERIC_ATTRIBUTES); |
---|
47 | result.enable(Capability.NO_CLASS); |
---|
48 | return result; |
---|
49 | } |
---|
50 | |
---|
51 | @Override |
---|
52 | public int numberOfClusters() throws Exception { |
---|
53 | return numberOfClusters; |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Main method for executing this clusterer. |
---|
58 | * |
---|
59 | * @param args |
---|
60 | * the options, use "-h" to display options |
---|
61 | */ |
---|
62 | public static void main(String[] args) { |
---|
63 | AbstractClusterer.runClusterer(new SimpleClusterer(), args); |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|