// File: 0asa[P]TTree-source/ClassicTree.cpp
// Function: ClassicTree::learnnbf()
double ClassicTree::learnnbf() { 
	clock_t clock_start = clock();
	Scorer s(db);
	std::vector<unsigned int> lsleft;
	std::vector<unsigned int> lsright;
	
	
	Stack stack;
	root = new Node();	root->setLS((*ls));	stack.push(root);
	while (!stack.empty() && complexity < maxcomplexity) {
		Node *n = stack.pop();
		std::vector<unsigned int> set = n->getLS();
		if (set.size() >= nmin) {
			std::vector<unsigned int> kcand;
			if (k > 0)
				kcand = Sampler::random((*cand),k);
			else
				kcand = (*cand); 
			ScoreInfo si = s.getBestScore(set,kcand);
			if (si.score > 0) {
				db->getLRSet(si,set,lsleft,lsright);
				n->setTest(si);
				Node *left  = new Node();	left->setParent(n); 
				left->setDepth(n->getDepth()+1); // 09-07-2012
				left->setLS(lsleft);	n->setLeft(left);	stack.push(left);
				Node *right = new Node();	right->setParent(n); 
				right->setDepth(n->getDepth()+1); // 09-07-2012
				right->setLS(lsright);	n->setRight(right);	stack.push(right);
				if (maxdepth < n->getDepth()+1) { maxdepth = n->getDepth()+1; }
				complexity++;
				// BEGIN-02-08-2012 : all nmin at once
				// need to attach vote at each node
				std::vector<double> vote(2,0.0);
				for (int i = 0 ; i < set.size() ; ++i)
					vote[db->getOutput(set[i])] += db->getWeight(set[i]);
				for (int i = 0 ; i < vote.size() ; ++i) 
					vote[i] /= set.size();
				n->setVote(vote);
				// END-02-08-2012
			}
		}
	}	
	createProbsInLeaf();
	return (clock() - clock_start);
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0xc8(%rsp)
callq 0x3180
movq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x258(%rsp)
movq 0x8(%rax), %rsi
leaq 0x230(%rsp), %rdi
callq 0x26d90
leaq 0x218(%rsp), %rdi
callq 0x67b0
leaq 0x200(%rsp), %rdi
callq 0x67b0
leaq 0x1e8(%rsp), %rdi
callq 0x2d660
jmp 0x13451
movl $0x60, %edi
callq 0x3270
movq %rax, 0xc0(%rsp)
jmp 0x13465
movq 0xc0(%rsp), %rdi
callq 0x21960
jmp 0x13474
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq %rcx, 0x50(%rax)
movq 0x20(%rax), %rsi
movq 0x50(%rax), %rax
movq %rax, 0xb8(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0xcbb0
jmp 0x134a7
movq 0xb8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x12260
jmp 0x134be
leaq 0x1c0(%rsp), %rdi
callq 0x6830
movq 0xc8(%rsp), %rax
movq 0x50(%rax), %rsi
leaq 0x1e8(%rsp), %rdi
callq 0x2d680
jmp 0x134e6
jmp 0x134e8
leaq 0x1e8(%rsp), %rdi
callq 0x2d720
movb %al, 0xb7(%rsp)
jmp 0x134fe
movb 0xb7(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xb6(%rsp)
jne 0x1352d
jmp 0x13515
movq 0xc8(%rsp), %rcx
movl 0x14(%rcx), %eax
cmpl 0x18(%rcx), %eax
setl %al
movb %al, 0xb6(%rsp)
movb 0xb6(%rsp), %al
testb $0x1, %al
jne 0x1353d
jmp 0x13d0b
leaq 0x1e8(%rsp), %rdi
callq 0x2d6d0
movq %rax, 0xa8(%rsp)
jmp 0x13554
movq 0xa8(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0xcba0
movq %rax, 0xa0(%rsp)
jmp 0x1357b
movq 0xa0(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0xcbb0
jmp 0x13592
leaq 0x1a0(%rsp), %rdi
callq 0x8bf0
movq 0xc8(%rsp), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jb 0x13cf9
leaq 0x188(%rsp), %rdi
callq 0x67b0
movq 0xc8(%rsp), %rax
cmpl $0x0, 0x58(%rax)
jbe 0x136b4
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rsi
movl 0x58(%rax), %edx
leaq 0x170(%rsp), %rdi
callq 0x122d0
jmp 0x135f1
leaq 0x188(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x6800
leaq 0x170(%rsp), %rdi
callq 0x6830
jmp 0x136d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
jmp 0x13d81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
jmp 0x13d74
movq 0xc0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x13d74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x6830
jmp 0x13d74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
jmp 0x13cdd
movq 0xc8(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x188(%rsp), %rdi
callq 0x90f0
jmp 0x136cf
jmp 0x136d1
leaq 0x140(%rsp), %rdi
leaq 0x230(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
leaq 0x188(%rsp), %rcx
callq 0x168e0
jmp 0x136f8
movsd 0x168(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x13cb4
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x1a0(%rsp), %rdx
leaq 0x218(%rsp), %rcx
leaq 0x200(%rsp), %r8
callq 0x19420
jmp 0x13741
movq 0x1b8(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x21b10
jmp 0x13758
movl $0x60, %edi
callq 0x3270
movq %rax, 0x98(%rsp)
jmp 0x1376c
movq 0x98(%rsp), %rdi
callq 0x21960
jmp 0x1377b
movq 0x98(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rdi
movq 0x1b8(%rsp), %rsi
callq 0x21c50
jmp 0x137a2
movq 0x138(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x12630
movl %eax, 0x94(%rsp)
jmp 0x137c8
movq 0x88(%rsp), %rdi
movl 0x94(%rsp), %esi
incl %esi
callq 0x12610
jmp 0x137e0
movq 0x138(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0xcbb0
jmp 0x13807
movq 0x80(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x12260
jmp 0x1381e
leaq 0x120(%rsp), %rdi
callq 0x6830
movq 0x1b8(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x21c70
jmp 0x13842
movq 0x138(%rsp), %rsi
leaq 0x1e8(%rsp), %rdi
callq 0x2d680
jmp 0x13859
movl $0x60, %edi
callq 0x3270
movq %rax, 0x78(%rsp)
jmp 0x1386a
movq 0x78(%rsp), %rdi
callq 0x21960
jmp 0x13876
movq 0x78(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
movq 0x1b8(%rsp), %rsi
callq 0x21c50
jmp 0x1389a
movq 0x118(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x12630
movl %eax, 0x74(%rsp)
jmp 0x138ba
movq 0x68(%rsp), %rdi
movl 0x74(%rsp), %esi
incl %esi
callq 0x12610
jmp 0x138cc
movq 0x118(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0xcbb0
jmp 0x138f0
movq 0x60(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x12260
jmp 0x13904
leaq 0x100(%rsp), %rdi
callq 0x6830
movq 0x1b8(%rsp), %rdi
movq 0x118(%rsp), %rsi
callq 0x21c90
jmp 0x13928
movq 0x118(%rsp), %rsi
leaq 0x1e8(%rsp), %rdi
callq 0x2d680
jmp 0x1393f
movq 0xc8(%rsp), %rax
movl 0x15c(%rax), %eax
movl %eax, 0x58(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x12630
movl %eax, 0x5c(%rsp)
jmp 0x13964
movl 0x58(%rsp), %eax
movl 0x5c(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x13a5c
movq 0x1b8(%rsp), %rdi
callq 0x12630
movl %eax, 0x54(%rsp)
jmp 0x1398a
movq 0xc8(%rsp), %rax
movl 0x54(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x15c(%rax)
jmp 0x13a5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
jmp 0x13cd0
movq 0x98(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x13cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x6830
jmp 0x13cd0
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x13cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x6830
jmp 0x13cd0
movq 0xc8(%rsp), %rax
movl 0x14(%rax), %ecx
incl %ecx
movl %ecx, 0x14(%rax)
movq $0x0, 0xe0(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xccb0
movq 0x48(%rsp), %rcx
leaq 0xe8(%rsp), %rdi
movl $0x2, %esi
leaq 0xe0(%rsp), %rdx
callq 0xccc0
jmp 0x13aab
leaq 0xdf(%rsp), %rdi
callq 0xcd40
movl $0x0, 0xd8(%rsp)
movslq 0xd8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x8bf0
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x13be7
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movslq 0xd8(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0xcd80
movq 0x30(%rsp), %rdi
movl (%rax), %esi
callq 0xcd50
movsd %xmm0, 0x38(%rsp)
jmp 0x13b28
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movslq 0xd8(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0xcd80
movq 0x20(%rsp), %rdi
movl (%rax), %esi
callq 0xcdc0
movw %ax, 0x2e(%rsp)
jmp 0x13b61
movw 0x2e(%rsp), %ax
movswq %ax, %rsi
leaq 0xe8(%rsp), %rdi
callq 0xcda0
movsd 0x38(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0x13ac3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0xdf(%rsp), %rdi
callq 0xcd40
jmp 0x13cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xcaa0
jmp 0x13cd0
movl $0x0, 0xd4(%rsp)
movslq 0xd4(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xab40
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x13c90
leaq 0x1a0(%rsp), %rdi
callq 0x8bf0
movq %rax, %xmm0
movaps 0x1cb1e(%rip), %xmm1    # 0x30750
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1cb22(%rip), %xmm1    # 0x30760
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0xd4(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0xcda0
movsd 0x10(%rsp), %xmm1
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x13bf2
movq 0x1b8(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x21dd0
jmp 0x13ca7
leaq 0xe8(%rsp), %rdi
callq 0xcaa0
leaq 0x140(%rsp), %rdi
callq 0x12640
leaq 0x188(%rsp), %rdi
callq 0x6830
jmp 0x13cf9
leaq 0x140(%rsp), %rdi
callq 0x12640
leaq 0x188(%rsp), %rdi
callq 0x6830
leaq 0x1a0(%rsp), %rdi
callq 0x6830
jmp 0x13d74
leaq 0x1a0(%rsp), %rdi
callq 0x6830
jmp 0x134e8
movq 0xc8(%rsp), %rdi
callq 0x13dc0
jmp 0x13d1a
callq 0x3180
subq 0x258(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x2d670
leaq 0x200(%rsp), %rdi
callq 0x6830
leaq 0x218(%rsp), %rdi
callq 0x6830
leaq 0x230(%rsp), %rdi
callq 0x26e10
movsd 0x8(%rsp), %xmm0
addq $0x268, %rsp            # imm = 0x268
retq
leaq 0x1e8(%rsp), %rdi
callq 0x2d670
leaq 0x200(%rsp), %rdi
callq 0x6830
leaq 0x218(%rsp), %rdi
callq 0x6830
leaq 0x230(%rsp), %rdi
callq 0x26e10
movq 0x1e0(%rsp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)