source: trunk/greenstone3-extensions/vishnu/src/vishnu/testvis/dendro/Cluster.java@ 8189

Last change on this file since 8189 was 8189, checked in by kjdon, 20 years ago

first version of Imperial College's Visualiser code

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1package vishnu.testvis.dendro;
2
3import java.util.*;
4
5public 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 public Vector docVect;
12 public Vector docObjVect;
13 public int[] wordFreq;
14
15 public double _children_sim;
16
17 // probably the size of the cluster
18 public int _items;
19
20 public int _split;
21
22
23
24 // [] -> centroid for each vector element ?
25 public double[] _centroid=null;
26
27 public Vector _iter_items = null;
28 public int _iter_items_num = 0;
29
30 public int _x = 0;
31 public int _y = 0;
32 public double[] getCentroid(){return _centroid;}
33
34 public Cluster(int id, Cluster parent, Cluster child_1, Cluster child_2, double children_sim, int items)
35 {
36 _id = id;
37 _children_sim = children_sim;
38 _items = items;
39 _split = 0;
40 _parent = parent;
41 _iter_items = new Vector(0);
42
43 // probably to get a balanced tree
44 if (child_1 != null && child_2 != null)
45 {
46 if (child_2._items > child_1._items)
47 {
48 _child_1 = child_1;
49 _child_2 = child_2;
50 }
51 else
52 {
53 _child_1 = child_2;
54 _child_2 = child_1;
55 }
56 }
57 else // if either or both are null
58 {
59 _child_1 = child_1;
60 _child_2 = child_2;
61 }
62 }
63
64 public void setDocVect(Vector docs)
65 {
66 docVect = docs;
67 }
68
69 public void setDocObjVect(Vector docObj)
70 {
71 docObjVect = docObj;
72 }
73
74 public Vector getDocObjVect()
75 {
76 return docObjVect;
77 }
78
79 public Vector getDocVect()
80 {
81 return docVect;
82 }
83
84 public void setWordFreq(int[] freqs)
85 {
86 wordFreq = freqs;
87 }
88
89 public int[] getWordFreq()
90 {
91 return wordFreq;
92 }
93
94 // a nice recursive function to determine the depth of the hierarchy
95 public int depth()
96 {
97 if (_id != -1)
98 return 0;
99 else
100 return Math.max(1 + _child_1.depth(), 1 + _child_2.depth());
101 }
102
103 void addChildrenToOutputVector(int []coding, Vector output)
104 {
105 if (_id != -1)
106 {
107 Integer ii = new Integer(coding[_id]);
108 output.addElement(ii);
109
110 }
111 else
112 {
113 _child_1.addChildrenToOutputVector(coding,output);
114 _child_2.addChildrenToOutputVector(coding,output);
115 }
116 }
117
118}
119
120
Note: See TracBrowser for help on using the repository browser.