// File: 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:
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, 0x2f0(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0xc8(%rsp)
callq 0x3180
movq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x2e8(%rsp)
movq 0x8(%rax), %rsi
leaq 0x2c0(%rsp), %rdi
callq 0x26d90
leaq 0x2a8(%rsp), %rdi
callq 0x67b0
leaq 0x290(%rsp), %rdi
callq 0x67b0
leaq 0x278(%rsp), %rdi
callq 0x2d660
jmp 0xf701
movl $0x60, %edi
callq 0x3270
movq %rax, 0xc0(%rsp)
jmp 0xf715
movq 0xc0(%rsp), %rdi
callq 0x21960
jmp 0xf724
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 0x250(%rsp), %rdi
callq 0xcbb0
jmp 0xf757
movq 0xb8(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x12260
jmp 0xf76e
leaq 0x250(%rsp), %rdi
callq 0x6830
movq 0xc8(%rsp), %rax
movq 0x50(%rax), %rsi
leaq 0x278(%rsp), %rdi
callq 0x2d680
jmp 0xf796
jmp 0xf798
leaq 0x278(%rsp), %rdi
callq 0x2d720
movb %al, 0xb7(%rsp)
jmp 0xf7ae
movb 0xb7(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xb6(%rsp)
jne 0xf7dd
jmp 0xf7c5
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 0xf7ed
jmp 0x1006e
leaq 0x278(%rsp), %rdi
callq 0x2d6d0
movq %rax, 0xa8(%rsp)
jmp 0xf804
movq 0xa8(%rsp), %rax
movq %rax, 0x248(%rsp)
movq 0x248(%rsp), %rdi
callq 0xcba0
movq %rax, 0xa0(%rsp)
jmp 0xf82b
movq 0xa0(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0xcbb0
jmp 0xf842
leaq 0x2a8(%rsp), %rdi
callq 0x122b0
leaq 0x290(%rsp), %rdi
callq 0x122b0
leaq 0x230(%rsp), %rdi
callq 0x8bf0
movq 0xc8(%rsp), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jb 0x1005c
leaq 0x218(%rsp), %rdi
callq 0x67b0
movq 0xc8(%rsp), %rax
cmpl $0x0, 0x98(%rax)
jne 0xf95c
movq 0xc8(%rsp), %rsi
subq $-0x80, %rsi
leaq 0x218(%rsp), %rdi
callq 0x90f0
jmp 0xf8bb
jmp 0xf9a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x100ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x100e0
movq 0xc0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x100e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x6830
jmp 0x100e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x1003d
movq 0xc8(%rsp), %rax
movq %rax, %rsi
subq $-0x80, %rsi
movl 0x98(%rax), %edx
leaq 0x200(%rsp), %rdi
callq 0x122d0
jmp 0xf980
leaq 0x218(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x6800
leaq 0x200(%rsp), %rdi
callq 0x6830
movq 0xc8(%rsp), %rax
movl 0x60(%rax), %r9d
movl 0x58(%rax), %r8d
movl 0x5c(%rax), %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq 0x1d0(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0x230(%rsp), %rdx
leaq 0x218(%rsp), %rcx
callq 0x26e20
jmp 0xf9e1
movsd 0x1f8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x10014
movq 0x315da(%rip), %rax     # 0x40fd8
movq (%rax), %rdi
leaq 0x20fe7(%rip), %rsi     # 0x309ef
xorl %eax, %eax
callq 0x3360
movq 0xc8(%rsp), %rax
movq 0x248(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movsd 0x1f0(%rsp), %xmm0
movl 0x1e8(%rsp), %edx
movl 0x60(%rax), %ecx
callq 0x21b90
jmp 0xfa41
movq 0x1d0(%rsp), %rsi
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq 0x178(%rsp), %rdi
leaq 0x230(%rsp), %rdx
callq *%rax
jmp 0xfa64
movl $0x0, 0x174(%rsp)
movslq 0x174(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x8bf0
movq %rax, %rcx
movq 0x98(%rsp), %rax
cmpq %rcx, %rax
jae 0xfb6f
leaq 0x180(%rsp), %rdi
movl 0x174(%rsp), %esi
callq 0x224f0
movsd %xmm0, 0x90(%rsp)
jmp 0xfabf
movsd 0x90(%rsp), %xmm0
ucomisd 0x1f0(%rsp), %xmm0
jb 0xfb2e
movslq 0x174(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0xcd80
movq %rax, %rsi
leaq 0x2a8(%rsp), %rdi
callq 0x12490
jmp 0xfafa
jmp 0xfb57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x10030
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
jmp 0x10005
movslq 0x174(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0xcd80
movq %rax, %rsi
leaq 0x290(%rsp), %rdi
callq 0x12490
jmp 0xfb55
jmp 0xfb57
jmp 0xfb59
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0xfa6f
leaq 0x2a8(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x8aa0
movq 0x80(%rsp), %rdi
movq %rax, 0x150(%rsp)
callq 0x88f0
movq %rax, 0x148(%rsp)
leaq 0x147(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x79a0
movq 0x88(%rsp), %rcx
movq 0x150(%rsp), %rsi
movq 0x148(%rsp), %rdx
leaq 0x158(%rsp), %rdi
callq 0x12500
jmp 0xfbdd
leaq 0x158(%rsp), %rdi
movq %rdi, 0x68(%rsp)
leaq 0x2a8(%rsp), %rsi
callq 0x12590
movq 0x68(%rsp), %rdi
callq 0x6830
leaq 0x147(%rsp), %rdi
callq 0xbb90
leaq 0x290(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x8aa0
movq 0x70(%rsp), %rdi
movq %rax, 0x120(%rsp)
callq 0x88f0
movq %rax, 0x118(%rsp)
leaq 0x117(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x79a0
movq 0x78(%rsp), %rcx
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdx
leaq 0x128(%rsp), %rdi
callq 0x12500
jmp 0xfc70
leaq 0x128(%rsp), %rdi
movq %rdi, 0x58(%rsp)
leaq 0x290(%rsp), %rsi
callq 0x12590
movq 0x58(%rsp), %rdi
callq 0x6830
leaq 0x117(%rsp), %rdi
callq 0xbb90
movl $0x60, %edi
callq 0x3270
movq %rax, 0x60(%rsp)
jmp 0xfcb2
movq 0x60(%rsp), %rdi
callq 0x21960
jmp 0xfcbe
movq 0x60(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rdi
movq 0x248(%rsp), %rsi
callq 0x21c50
jmp 0xfce2
movq 0xc8(%rsp), %rax
movq 0x108(%rsp), %rdi
movl 0x60(%rax), %esi
callq 0x125f0
jmp 0xfcfc
movq 0x108(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x248(%rsp), %rdi
callq 0x12630
movl %eax, 0x54(%rsp)
jmp 0xfd1c
movq 0x48(%rsp), %rdi
movl 0x54(%rsp), %esi
incl %esi
callq 0x12610
jmp 0xfd2e
movq 0x108(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x2a8(%rsp), %rsi
callq 0xcbb0
jmp 0xfd52
movq 0x40(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x12260
jmp 0xfd66
leaq 0xf0(%rsp), %rdi
callq 0x6830
movq 0x248(%rsp), %rdi
movq 0x108(%rsp), %rsi
callq 0x21c70
jmp 0xfd8a
movq 0x108(%rsp), %rsi
leaq 0x278(%rsp), %rdi
callq 0x2d680
jmp 0xfda1
movl $0x60, %edi
callq 0x3270
movq %rax, 0x38(%rsp)
jmp 0xfdb2
movq 0x38(%rsp), %rdi
callq 0x21960
jmp 0xfdbe
movq 0x38(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
movq 0x248(%rsp), %rsi
callq 0x21c50
jmp 0xfde2
movq 0xc8(%rsp), %rax
movq 0xe8(%rsp), %rdi
movl 0x60(%rax), %esi
callq 0x125f0
jmp 0xfdfc
movq 0xe8(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0xcbb0
jmp 0xfe20
movq 0x30(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x12260
jmp 0xfe34
leaq 0xd0(%rsp), %rdi
callq 0x6830
movq 0x248(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0x21c90
jmp 0xfe58
movq 0xe8(%rsp), %rsi
leaq 0x278(%rsp), %rdi
callq 0x2d680
jmp 0xfe6f
movq 0xe8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x248(%rsp), %rdi
callq 0x12630
movl %eax, 0x2c(%rsp)
jmp 0xfe8f
movq 0x20(%rsp), %rdi
movl 0x2c(%rsp), %esi
incl %esi
callq 0x12610
jmp 0xfea1
movq 0xc8(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x248(%rsp), %rdi
callq 0x12630
movl %eax, 0x1c(%rsp)
jmp 0xfec6
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0xffe5
movq 0x248(%rsp), %rdi
callq 0x12630
movl %eax, 0x14(%rsp)
jmp 0xfeec
movq 0xc8(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x9c(%rax)
jmp 0xffe5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x147(%rsp), %rdi
callq 0xbb90
jmp 0x10005
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0x117(%rsp), %rdi
callq 0xbb90
jmp 0x10005
movq 0x60(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x10005
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x6830
jmp 0x10005
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
movl $0x60, %esi
callq 0x3280
jmp 0x10005
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x270(%rsp)
movl %eax, 0x26c(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x6830
jmp 0x10005
movq 0xc8(%rsp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
leaq 0x178(%rsp), %rdi
callq 0x24b00
jmp 0x10014
leaq 0x178(%rsp), %rdi
callq 0x24b00
jmp 0x10030
leaq 0x1d0(%rsp), %rdi
callq 0x12640
leaq 0x218(%rsp), %rdi
callq 0x6830
jmp 0x1005c
leaq 0x1d0(%rsp), %rdi
callq 0x12640
leaq 0x218(%rsp), %rdi
callq 0x6830
leaq 0x230(%rsp), %rdi
callq 0x6830
jmp 0x100e0
leaq 0x230(%rsp), %rdi
callq 0x6830
jmp 0xf798
movq 0x30f63(%rip), %rax     # 0x40fd8
movq (%rax), %rdi
leaq 0x20595(%rip), %rsi     # 0x30614
movb $0x0, %al
callq 0x3360
callq 0x3180
subq 0x2e8(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x2d670
leaq 0x290(%rsp), %rdi
callq 0x6830
leaq 0x2a8(%rsp), %rdi
callq 0x6830
leaq 0x2c0(%rsp), %rdi
callq 0x26e10
movsd 0x8(%rsp), %xmm0
addq $0x2f8, %rsp            # imm = 0x2F8
retq
leaq 0x278(%rsp), %rdi
callq 0x2d670
leaq 0x290(%rsp), %rdi
callq 0x6830
leaq 0x2a8(%rsp), %rdi
callq 0x6830
leaq 0x2c0(%rsp), %rdi
callq 0x26e10
movq 0x270(%rsp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)