4 public class OoOJavaExample {
6 public static void main( String[] args ) {
7 OoOJavaExample ex = new OoOJavaExample( 1234, 100, 0.05f, 15 );
11 private HashSet roots;
12 //private HashMap bin2set;
14 public OoOJavaExample( int seed, int numTrees, float probNull, int maxTreeDepth ) {
15 Random random = new Random( seed );
17 roots = new HashSet();
18 for( int i = 0; i < numTrees; ++i ) {
19 roots.add( makeNewTree( random, probNull, maxTreeDepth ) );
22 //bin2set = new HashMap();
25 private TreeNode makeNewTree( Random random, float probNull, int maxTreeDepth ) {
27 TreeNode root = new TreeNode( random.nextFloat() );
29 TreeNode left = buildSubTree( random, probNull, maxTreeDepth, 0 );
32 TreeNode right = buildSubTree( random, probNull, maxTreeDepth, 0 );
39 private TreeNode buildSubTree( Random random, float probNull, int maxTreeDepth, int depth ) {
41 TreeNode node = new TreeNode( random.nextFloat() );
42 if( depth > maxTreeDepth || random.nextFloat() < probNull ) {
47 TreeNode left = buildSubTree( random, probNull, maxTreeDepth, depth + 1 );
50 TreeNode right = buildSubTree( random, probNull, maxTreeDepth, depth + 1 );
57 public void runExample() {
58 Iterator itr = roots.iterator();
62 while( itr.hasNext() ) {
63 TreeNode root = (TreeNode) itr.next();
66 int weightBin = (int) root.computeTreeWeight();
71 HashSet set = (HashSet)bin2set.get( weightBin );
74 bin2set.put( weightBin, set );
81 System.out.println( "Num weight bins: "+zzz ); //bin2set.size() );