1 | package vishnu.cluster;
|
---|
2 |
|
---|
3 | import java.util.*;
|
---|
4 |
|
---|
5 | public class Cluster
|
---|
6 | {
|
---|
7 | public int _id;
|
---|
8 | public Cluster _parent = null;
|
---|
9 | public Cluster _child_1 = null;
|
---|
10 | public Cluster _child_2 = null;
|
---|
11 |
|
---|
12 | public double _children_sim;
|
---|
13 |
|
---|
14 | // probably the size of the cluster
|
---|
15 | public int _items;
|
---|
16 |
|
---|
17 | public int _split;
|
---|
18 |
|
---|
19 | // [] -> centroid for each vector element ?
|
---|
20 | public double[] _centroid=null;
|
---|
21 |
|
---|
22 | public Vector _iter_items = null;
|
---|
23 | public int _iter_items_num = 0;
|
---|
24 |
|
---|
25 | public int _x = 0;
|
---|
26 | public int _y = 0;
|
---|
27 | public double[] getCentroid(){return _centroid;}
|
---|
28 |
|
---|
29 | public Cluster(int id, Cluster parent, Cluster child_1, Cluster child_2, double children_sim, int items)
|
---|
30 | {
|
---|
31 | _id = id;
|
---|
32 | _children_sim = children_sim;
|
---|
33 | _items = items;
|
---|
34 | _split = 0;
|
---|
35 | _parent = parent;
|
---|
36 | _iter_items = new Vector(0);
|
---|
37 |
|
---|
38 | // probably to get a balanced tree
|
---|
39 | if (child_1 != null && child_2 != null)
|
---|
40 | {
|
---|
41 | if (child_2._items > child_1._items)
|
---|
42 | {
|
---|
43 | _child_1 = child_1;
|
---|
44 | _child_2 = child_2;
|
---|
45 | }
|
---|
46 | else
|
---|
47 | {
|
---|
48 | _child_1 = child_2;
|
---|
49 | _child_2 = child_1;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | else // if either or both are null
|
---|
53 | {
|
---|
54 | _child_1 = child_1;
|
---|
55 | _child_2 = child_2;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | // a nice recursive function to determine the depth of the hierarchy
|
---|
60 | public int depth()
|
---|
61 | {
|
---|
62 | if (_id != -1)
|
---|
63 | return 0;
|
---|
64 | else
|
---|
65 | return Math.max(1 + _child_1.depth(), 1 + _child_2.depth());
|
---|
66 | }
|
---|
67 |
|
---|
68 | void addChildrenToOutputVector(int []coding, Vector output)
|
---|
69 | {
|
---|
70 | if (_id != -1)
|
---|
71 | {
|
---|
72 | Integer ii = new Integer(coding[_id]);
|
---|
73 | output.addElement(ii);
|
---|
74 |
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | _child_1.addChildrenToOutputVector(coding,output);
|
---|
79 | _child_2.addChildrenToOutputVector(coding,output);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|