// File: /workspace/github_cpp_makefile_star2_O3/0asa[P]TTree-source/ClassicNodeTree.cpp
// Function: ClassicNodeTree::learn()
double ClassicNodeTree::learn() {
	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();
		lsleft.clear();		lsright.clear();
		if (set.size() >= nmin) {
			// for each group construct a tree and keep the best
			std::vector<unsigned int> kgroupcand;
			if (k == 0) {
				kgroupcand = groupcand;
			} else {
				kgroupcand = Sampler::random(groupcand,k);
			}
			//Sampler::print(kgroupcand);
			//ScoreInfo si = s.getBestGroupSNPScore(set,kgroupcand,internalComp,treeType,kint);
			//ScoreInfo si = s.getBestGroupStumpScore(set,kgroupcand,internalComp,treeType);

			ScoreInfo si = s.getBestGroupScore(set,kgroupcand,internalComp,treeType,kint);
			if (si.score > 0) {
				fprintf(stderr,".");
				n->setTest(si.weak,si.threshold, si.group,treeType);
				
				//fprintf(stderr,"Group:%d\tScore:%1.4f\t(*%d)\n", si.group,si.score, set.size()); 
				// mise a jour ls-left-right 
				Result r = si.weak->test(&set);
				for (int i = 0 ; i < set.size(); ++i) {
					if (r.prob.getProb(i)>=si.threshold)
						lsleft.push_back(set[i]);
					else
						lsright.push_back(set[i]);
				}
				// SHRINK TO FIT TRICK :
				std::vector<unsigned int>(lsleft.begin(),lsleft.end()).swap(lsleft);
				std::vector<unsigned int>(lsright.begin(),lsright.end()).swap(lsright);
				Node *left = new Node();	left->setParent(n); left->setTreeType(treeType);
				left->setDepth(n->getDepth()+1); // 27-07-2012
				left->setLS(lsleft);	n->setLeft(left);	stack.push(left);
				Node *right = new Node();	right->setParent(n); right->setTreeType(treeType);
				right->setLS(lsright);	n->setRight(right);	stack.push(right);
				right->setDepth(n->getDepth()+1); // 27-07-2012
				if (maxdepth < n->getDepth()+1) { maxdepth = n->getDepth()+1; } 
				complexity++;

			}
		}
	}	
	fprintf(stderr,"\n");
	return (clock() - clock_start);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %r14
callq 0x3130
movq %rax, 0xc0(%rsp)
movq 0x8(%r14), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x1354c
xorl %eax, %eax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x1554c
movl $0x60, %edi
callq 0x3200
movq %rax, %r15
movq %rax, %rdi
callq 0x11008
movq %r15, 0x50(%r14)
movq 0x20(%r14), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x7b86
leaq 0xf8(%rsp), %rsi
movq %r15, %rdi
callq 0x73dc
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x2, %rax
movl 0x58(%r15), %ecx
cmpq %rcx, %rax
jbe 0x828b
movl %eax, 0x58(%r15)
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x82a8
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x50(%r14), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x15574
leaq 0x80(%r14), %rax
movq %rax, 0x50(%rsp)
leaq 0x148(%rsp), %r12
leaq 0x30(%rsp), %r15
leaq 0xa8(%rsp), %rdi
callq 0x155be
testb %al, %al
jne 0x87a4
movl 0x14(%r14), %eax
cmpl 0x18(%r14), %eax
jge 0x87a4
leaq 0xa8(%rsp), %rdi
callq 0x155ac
movq %rax, %rbp
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x7b86
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x8323
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x8334
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rax
subq %rdi, %rax
sarq $0x2, %rax
movslq 0x10(%r14), %rcx
cmpq %rcx, %rax
jb 0x8789
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
movl 0x98(%r14), %edx
testl %edx, %edx
je 0x840b
leaq 0x140(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x9cca
movq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movapd 0x140(%rsp), %xmm0
movapd %xmm0, 0x90(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x140(%rsp)
movq $0x0, 0x150(%rsp)
testq %rdi, %rdi
je 0x8401
subq %rdi, %rsi
callq 0x3210
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x8401
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0x90(%rsp), %rbx
jmp 0x8420
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
callq 0x73dc
movl 0x60(%r14), %r9d
movl 0x58(%r14), %r8d
movl 0x5c(%r14), %eax
movl %eax, (%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movq %rbx, %rcx
callq 0x13592
movsd 0x138(%rsp), %xmm0
ucomisd 0xe2a3(%rip), %xmm0     # 0x16700
jbe 0x8767
movq 0x17b6e(%rip), %rax     # 0x1ffd8
movq (%rax), %rsi
movl $0x2e, %edi
callq 0x3270
movq 0x110(%rsp), %rsi
movsd 0x130(%rsp), %xmm0
movl 0x128(%rsp), %edx
movl 0x60(%r14), %ecx
movq %rbp, %rdi
callq 0x11130
movq 0x110(%rsp), %rsi
movq (%rsi), %rax
leaq 0x140(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq *0x20(%rax)
movq 0x60(%rsp), %rax
cmpq 0x58(%rsp), %rax
je 0x853b
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
movl %r13d, %esi
callq 0x11528
movq 0x58(%rsp), %rdx
addq %rbx, %rdx
ucomisd 0x130(%rsp), %xmm0
jae 0x8506
movq 0x38(%rsp), %rsi
movq %r15, %rdi
leaq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rsi
je 0x851c
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rax)
jmp 0x8521
movq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rsi
jne 0x84f9
callq 0x9f8a
movq 0x60(%rsp), %rax
subq 0x58(%rsp), %rax
incq %r13
sarq $0x2, %rax
addq $0x4, %rbx
cmpq %r13, %rax
ja 0x84c7
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9dc2
movq 0x80(%rsp), %rax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rsi
movq %rsi, 0x80(%rsp)
movapd 0x70(%rsp), %xmm0
movq %rdi, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
movapd %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
testq %rdi, %rdi
je 0x859b
subq %rdi, %rsi
callq 0x3210
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9dc2
movq 0x80(%rsp), %rax
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rsi
movq %rsi, 0x80(%rsp)
movapd 0x70(%rsp), %xmm0
movq %rdi, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
movapd %xmm0, 0x30(%rsp)
movq %rax, 0x40(%rsp)
testq %rdi, %rdi
je 0x85fb
subq %rdi, %rsi
callq 0x3210
movl $0x60, %edi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
callq 0x11008
movq %r13, %rdi
movq %rbp, %rsi
callq 0x111a8
movl 0x60(%r14), %eax
movl %eax, 0x5c(%r13)
movl 0x54(%rbp), %eax
incl %eax
movl %eax, 0x54(%r13)
leaq 0xe0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x7b86
movq %r13, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x73dc
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x2, %rax
movl 0x58(%r13), %ecx
cmpq %rcx, %rax
jbe 0x8667
movl %eax, 0x58(%r13)
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x8684
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %rbp, %rdi
movq %r13, %rsi
callq 0x111ae
leaq 0xa8(%rsp), %rdi
movq %r13, %rsi
callq 0x15574
movl $0x60, %edi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
callq 0x11008
movq %r13, %rdi
movq %rbp, %rsi
callq 0x111a8
movl 0x60(%r14), %eax
movl %eax, 0x5c(%r13)
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0x7b86
movq %r13, %rdi
leaq 0xc8(%rsp), %rsi
callq 0x73dc
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x2, %rax
movl 0x58(%r13), %ecx
cmpq %rcx, %rax
jbe 0x8700
movl %eax, 0x58(%r13)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x871d
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %rbp, %rdi
movq %r13, %rsi
callq 0x111b4
leaq 0xa8(%rsp), %rdi
movq %r13, %rsi
callq 0x15574
movl 0x54(%rbp), %eax
incl %eax
movl %eax, 0x54(%r13)
movl 0x54(%rbp), %eax
incl %eax
cmpl %eax, 0x9c(%r14)
jae 0x8756
movl %eax, 0x9c(%r14)
incl 0x14(%r14)
leaq 0x140(%rsp), %rdi
callq 0x12826
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8784
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x82d2
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
jmp 0x82d2
movq 0x1782d(%rip), %rax     # 0x1ffd8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x3270
callq 0x3130
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x1555c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x87e4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x87fb
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
subq 0xc0(%rsp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x13590
movsd 0x50(%rsp), %xmm0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x891e
movq 0x108(%rsp), %rsi
jmp 0x8916
movq %rax, %rbx
movl $0x60, %esi
movq %r15, %rdi
jmp 0x8919
movq %rax, %rbx
jmp 0x8942
jmp 0x88c8
jmp 0x88d1
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x88dd
movq 0xd8(%rsp), %rsi
jmp 0x88ab
jmp 0x88b0
jmp 0x88c8
jmp 0x88c8
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x88dd
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x88bb
movq %rax, %rbx
movl $0x60, %esi
movq %r13, %rdi
callq 0x3210
jmp 0x88dd
jmp 0x88da
jmp 0x88da
jmp 0x88c8
movq %rax, %rbx
jmp 0x88ea
jmp 0x88d1
jmp 0x88d1
movq %rax, %rbx
jmp 0x891e
jmp 0x88da
jmp 0x88da
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x12826
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8907
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x891e
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0xa8(%rsp), %rdi
callq 0x1555c
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8942
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8959
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0x1a0(%rsp), %rdi
callq 0x13590
movq %rbx, %rdi
callq 0x3320