// File: /workspace/github_cpp_makefile_star2_O1/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 0x135c8
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 0x155dc
movl $0x60, %edi
callq 0x3200
movq %rax, %r15
movq %rax, %rdi
callq 0x1103c
movq %r15, 0x50(%r14)
movq 0x20(%r14), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x7b1c
leaq 0xf8(%rsp), %rsi
movq %r15, %rdi
callq 0x7392
movq 0x8(%r15), %rax
subq (%r15), %rax
sarq $0x2, %rax
movl 0x58(%r15), %ecx
cmpq %rcx, %rax
jbe 0x821f
movl %eax, 0x58(%r15)
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x823c
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x50(%r14), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x15604
leaq 0x80(%r14), %rax
movq %rax, 0x50(%rsp)
leaq 0x148(%rsp), %r12
leaq 0x30(%rsp), %r15
leaq 0xa8(%rsp), %rdi
callq 0x1564e
testb %al, %al
jne 0x8735
movl 0x14(%r14), %eax
cmpl 0x18(%r14), %eax
jge 0x8735
leaq 0xa8(%rsp), %rdi
callq 0x1563c
movq %rax, %rbp
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x7b1c
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x82b7
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x82c8
movq %rax, 0x38(%rsp)
movq 0x60(%rsp), %rax
subq 0x58(%rsp), %rax
sarq $0x2, %rax
movslq 0x10(%r14), %rcx
cmpq %rcx, %rax
jb 0x8715
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
movl 0x98(%r14), %edx
testl %edx, %edx
je 0x839c
leaq 0x140(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x9ca2
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 0x8375
subq %rdi, %rsi
callq 0x3210
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x8392
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0x90(%rsp), %rbx
jmp 0x83b1
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
callq 0x7392
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 0x13620
movsd 0x138(%rsp), %xmm0
ucomisd 0xe312(%rip), %xmm0     # 0x16700
jbe 0x86f8
movq 0x17bdd(%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 0x11160
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 0x84cc
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
movl %r13d, %esi
callq 0x11558
movq 0x58(%rsp), %rdx
addq %rbx, %rdx
ucomisd 0x130(%rsp), %xmm0
jae 0x8497
movq 0x38(%rsp), %rsi
movq %r15, %rdi
leaq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rsi
je 0x84ad
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rax)
jmp 0x84b2
movq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rsi
jne 0x848a
callq 0x9f7a
movq 0x60(%rsp), %rax
subq 0x58(%rsp), %rax
incq %r13
sarq $0x2, %rax
addq $0x4, %rbx
cmpq %r13, %rax
ja 0x8458
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9da0
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 0x852c
subq %rdi, %rsi
callq 0x3210
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9da0
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 0x858c
subq %rdi, %rsi
callq 0x3210
movl $0x60, %edi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
callq 0x1103c
movq %r13, %rdi
movq %rbp, %rsi
callq 0x111d8
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 0x7b1c
movq %r13, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x7392
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x2, %rax
movl 0x58(%r13), %ecx
cmpq %rcx, %rax
jbe 0x85f8
movl %eax, 0x58(%r13)
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x8615
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %rbp, %rdi
movq %r13, %rsi
callq 0x111de
leaq 0xa8(%rsp), %rdi
movq %r13, %rsi
callq 0x15604
movl $0x60, %edi
callq 0x3200
movq %rax, %r13
movq %rax, %rdi
callq 0x1103c
movq %r13, %rdi
movq %rbp, %rsi
callq 0x111d8
movl 0x60(%r14), %eax
movl %eax, 0x5c(%r13)
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0x7b1c
movq %r13, %rdi
leaq 0xc8(%rsp), %rsi
callq 0x7392
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x2, %rax
movl 0x58(%r13), %ecx
cmpq %rcx, %rax
jbe 0x8691
movl %eax, 0x58(%r13)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x86ae
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %rbp, %rdi
movq %r13, %rsi
callq 0x111e4
leaq 0xa8(%rsp), %rdi
movq %r13, %rsi
callq 0x15604
movl 0x54(%rbp), %eax
incl %eax
movl %eax, 0x54(%r13)
movl 0x54(%rbp), %eax
incl %eax
cmpl %eax, 0x9c(%r14)
jae 0x86e7
movl %eax, 0x9c(%r14)
incl 0x14(%r14)
leaq 0x140(%rsp), %rdi
callq 0x1288e
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8715
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8266
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
jmp 0x8266
movq 0x1789c(%rip), %rax     # 0x1ffd8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x3270
callq 0x3130
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x155ec
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8775
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x878c
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 0x1361e
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 0x88af
movq 0x108(%rsp), %rsi
jmp 0x88a7
movq %rax, %rbx
movl $0x60, %esi
movq %r15, %rdi
jmp 0x88aa
movq %rax, %rbx
jmp 0x88bc
jmp 0x8859
jmp 0x8862
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x886e
movq 0xd8(%rsp), %rsi
jmp 0x883c
jmp 0x8841
jmp 0x8859
jmp 0x8859
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x886e
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x884c
movq %rax, %rbx
movl $0x60, %esi
movq %r13, %rdi
callq 0x3210
jmp 0x886e
jmp 0x886b
jmp 0x886b
jmp 0x8859
movq %rax, %rbx
jmp 0x887b
jmp 0x8862
jmp 0x8862
movq %rax, %rbx
jmp 0x88af
jmp 0x886b
jmp 0x886b
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x1288e
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x8898
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x88af
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0xa8(%rsp), %rdi
callq 0x155ec
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x88d3
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x88ea
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
leaq 0x1a0(%rsp), %rdi
callq 0x1361e
movq %rbx, %rdi
callq 0x3320
nop