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