// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %r14
callq 0x3140
movq %rax, 0xa8(%rsp)
movq 0x8(%r14), %rsi
leaq 0x128(%rsp), %rdi
callq 0x10648
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x12418
pushq $0x60
popq %rdi
callq 0x3200
movq %rax, %r15
movq %rax, %rdi
callq 0xe460
movq %r15, 0x50(%r14)
movq 0x20(%r14), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x6c64
leaq 0xb0(%rsp), %rsi
movq %r15, %rdi
callq 0x8884
leaq 0xb0(%rsp), %rdi
callq 0x6886
movq 0x50(%r14), %rsi
leaq 0x78(%rsp), %rdi
callq 0x1242a
leaq 0x80(%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0x78(%rsp), %rbp
leaq 0x30(%rsp), %r15
movq %rbp, %rdi
callq 0x12460
testb %al, %al
jne 0x781f
movl 0x14(%r14), %eax
cmpl 0x18(%r14), %eax
jge 0x781f
movq %rbp, %rdi
callq 0x1244e
movq %rax, %r13
leaq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x6c64
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x74e4
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x74f5
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
subq 0x48(%rsp), %rax
sarq $0x2, %rax
movslq 0x10(%r14), %rcx
cmpq %rcx, %rax
jb 0x7810
andq $0x0, 0xa0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movl 0x98(%r14), %edx
testl %edx, %edx
je 0x7563
leaq 0x150(%rsp), %r12
movq %r12, %rdi
movq 0x28(%rsp), %rsi
callq 0x88a6
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x68a8
movq %r12, %rdi
callq 0x6886
jmp 0x7578
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x634c
movl 0x60(%r14), %r9d
movl 0x58(%r14), %r8d
movl 0x5c(%r14), %eax
movl %eax, (%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x128(%rsp), %rsi
leaq 0x48(%rsp), %rdx
movq %rbx, %rcx
callq 0x1068e
movsd 0xf0(%rsp), %xmm0
ucomisd 0xc14b(%rip), %xmm0     # 0x13700
jbe 0x7803
movq 0x16a16(%rip), %rax     # 0x1dfd8
movq (%rax), %rsi
pushq $0x2e
popq %rdi
callq 0x3260
movq 0xc8(%rsp), %rsi
movsd 0xe8(%rsp), %xmm0
movl 0xe0(%rsp), %edx
movl 0x60(%r14), %ecx
movq %r13, %rdi
callq 0xe560
movq 0xc8(%rsp), %rsi
movq (%rsi), %rax
leaq 0x150(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq *0x20(%rax)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x50(%rsp), %rax
subq 0x48(%rsp), %rax
sarq $0x2, %rax
cmpq %rbp, %rax
jbe 0x765b
leaq 0x158(%rsp), %rdi
movl %ebp, %esi
callq 0xe8d2
ucomisd 0xe8(%rsp), %xmm0
movq %r15, %rdi
jb 0x7645
leaq 0x10(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq %rbx, %rsi
callq 0x8982
incq %rbp
addq $0x4, %rbx
jmp 0x7610
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0xf(%rsp), %r12
movq %r12, %rcx
callq 0x89a0
movq 0x70(%rsp), %rax
movapd 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rcx
movq %rcx, 0x70(%rsp)
movaps 0x60(%rsp), %xmm1
movapd %xmm0, 0x60(%rsp)
movaps %xmm1, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0x6886
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x89a0
movq 0x70(%rsp), %rax
movapd 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rcx
movq %rcx, 0x70(%rsp)
movaps 0x60(%rsp), %xmm1
movapd %xmm0, 0x60(%rsp)
movaps %xmm1, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x6886
pushq $0x60
popq %rdi
callq 0x3200
movq %rax, %rbp
movq %rax, %rdi
callq 0xe460
movq %rbp, %rdi
movq %r13, %rsi
callq 0xe5d4
movl 0x60(%r14), %eax
movl %eax, 0x5c(%rbp)
movl 0x54(%r13), %eax
incl %eax
movl %eax, 0x54(%rbp)
leaq 0x110(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6c64
movq %rbp, %rdi
leaq 0x110(%rsp), %rbx
movq %rbx, %rsi
callq 0x8884
movq %rbx, %rdi
callq 0x6886
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe5da
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0x1242a
pushq $0x60
popq %rdi
callq 0x3200
movq %rax, %rbp
movq %rax, %rdi
callq 0xe460
movq %rbp, %rdi
movq %r13, %rsi
callq 0xe5d4
movl 0x60(%r14), %eax
movl %eax, 0x5c(%rbp)
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x6c64
movq %rbp, %rdi
leaq 0xf8(%rsp), %rbx
movq %rbx, %rsi
callq 0x8884
movq %rbx, %rdi
callq 0x6886
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe5e0
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0x1242a
movl 0x54(%r13), %eax
incl %eax
movl %eax, 0x54(%rbp)
movl 0x54(%r13), %eax
incl %eax
cmpl %eax, 0x9c(%r14)
jae 0x77ed
movl %eax, 0x9c(%r14)
incl 0x14(%r14)
leaq 0x150(%rsp), %rdi
callq 0xfa56
leaq 0x78(%rsp), %rbp
leaq 0x90(%rsp), %rdi
callq 0x6886
leaq 0x48(%rsp), %rdi
callq 0x6886
jmp 0x749d
movq 0x167b2(%rip), %rax     # 0x1dfd8
movq (%rax), %rsi
pushq $0xa
popq %rdi
callq 0x3260
callq 0x3140
subq 0xa8(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x12424
leaq 0x30(%rsp), %rdi
callq 0x6886
leaq 0x10(%rsp), %rdi
callq 0x6886
leaq 0x128(%rsp), %rdi
callq 0x1068c
movsd 0x28(%rsp), %xmm0
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x792a
movq %rax, %rbx
pushq $0x60
popq %rsi
movq %r15, %rdi
callq 0x3210
jmp 0x792f
movq %rax, %rbx
jmp 0x7939
jmp 0x78f6
jmp 0x78ff
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x78d5
jmp 0x78dc
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x6886
jmp 0x790b
movq %rax, %rbx
pushq $0x60
popq %rsi
movq %rbp, %rdi
callq 0x3210
jmp 0x790b
jmp 0x7908
jmp 0x7908
jmp 0x78f6
jmp 0x78f6
jmp 0x78f6
movq %rax, %rbx
jmp 0x7918
jmp 0x78ff
jmp 0x78ff
movq %rax, %rbx
jmp 0x792f
jmp 0x7908
jmp 0x7908
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0xfa56
leaq 0x90(%rsp), %rdi
callq 0x6886
leaq 0x48(%rsp), %rdi
callq 0x6886
leaq 0x78(%rsp), %rdi
callq 0x12424
leaq 0x30(%rsp), %rdi
callq 0x6886
leaq 0x10(%rsp), %rdi
callq 0x6886
leaq 0x128(%rsp), %rdi
callq 0x1068c
movq %rbx, %rdi
callq 0x3330