// File: /workspace/github_cpp_makefile_star2_O3/aleperno[P]Datos/HashingPerceptron.cpp
// Function: HashingPerceptron::Initialize()
void HashingPerceptron::Initialize()
{

	cout << "Began to balance perceptron's weights" << endl;
	printf("\nIterations \t Errors \t Average \t Time \n");
	int iter_count = 1;
	int rev_counter = 0;
	clock_t inicio = clock();
	int min_error = -1;
	int min_count = 0;
	vector<float> aux_weights;
	while (true)
	{
		int error_count = 0;
		rev_counter = 0;
		pair<int,vector<unsigned int>> elem;
		BOOST_FOREACH(elem,this->test_vec)
		{
			rev_counter++;
			float aux = dot_product(elem.second);
			bool result = aux > this->threshold;
			//int error = elem.second.first - result;
			int error = elem.first - result;
			if (error != 0)
			{
				int pos;
				error_count++;
				BOOST_FOREACH(pos, elem.second)
				{
					this->weights[pos] += learning_rate * error;
				}
			}
		}
		//Imprimo los resultados parciales del balanceo
		double final = clock();
		double secs = double(final - inicio) / CLOCKS_PER_SEC;
		float min = floor(secs/60);
		float sec = secs - min*60;
		printf("%d\t\t%d\t\t%0.5f\t\t%.0f:%.3f\n",iter_count,error_count, 1.0 - (double)error_count/rev_counter,min,sec);
		fflush(stdout);
		//Veo si el error es el minimo, guardo el hiperplano
		if (error_count <= min_error || min_error == -1)
		{
			if (error_count == min_error)
				min_count++;
			else
				min_count = 0;
			min_error = error_count;
			aux_weights = this->weights;
		}
		//Controlo el corte
		if (iter_count == ITERATION_LIMIT)
		{
			cout << "Reached Iteration Limit" << endl;
			break;
		}
		if (error_count == 0) break;
		if (min_count == 5)
		{
			cout << "Reached Iteration Limit with minimum error" << endl;
			break;
		}
		iter_count++;
	}
	cout << "Finished perceptron balance" << endl;
	//Guardo el hiperplano de minimo error
	cout << "Minimum error was " << min_error << endl;
	this->weights = aux_weights;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r15
movq 0x6a60(%rip), %rbx      # 0xdfd8
leaq 0x2c73(%rip), %rsi      # 0xa1f2
movl $0x25, %edx
movq %rbx, %rdi
callq 0x3290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
leaq 0x2d55(%rip), %rdi      # 0xa30f
callq 0x3350
callq 0x3180
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rcx
movaps %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
leaq -0x68(%rbp), %r14
leaq 0x38(%r15), %rcx
movq %rcx, -0x38(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x1, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
movl %r12d, -0x50(%rbp)
movl $0x0, -0x70(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movq 0x88(%r15), %r12
movq 0x90(%r15), %rax
movq %rax, -0x48(%rbp)
cmpq %rax, %r12
je 0x7737
movl %r13d, -0x4c(%rbp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movl (%r12), %eax
movl %eax, -0x70(%rbp)
leaq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x8b8a
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
callq 0x826c
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rcx
movq %rcx, %rax
subq %rdi, %rax
je 0x76a3
sarq $0x2, %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movl (%rdi,%rdx,4), %esi
addss (%rcx,%rsi,4), %xmm0
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0x768f
jmp 0x76ac
xorpd %xmm0, %xmm0
testq %rcx, %rcx
je 0x76bb
movss %xmm0, -0x40(%rbp)
callq 0x3210
movss -0x40(%rbp), %xmm0
xorl %eax, %eax
ucomiss 0x54(%r15), %xmm0
seta %al
movl -0x70(%rbp), %edx
subl %eax, %edx
je 0x770f
incl %ebx
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
cmpq %rcx, %rax
leaq -0x68(%rbp), %r14
je 0x7713
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
movq -0x38(%rbp), %rdx
movq (%rdx), %rdx
movslq (%rax), %rsi
movss 0x50(%r15), %xmm1
mulss %xmm0, %xmm1
addss (%rdx,%rsi,4), %xmm1
movss %xmm1, (%rdx,%rsi,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x76ed
jmp 0x7713
leaq -0x68(%rbp), %r14
incl %r13d
addq $0x20, %r12
cmpq -0x48(%rbp), %r12
jne 0x7645
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x4c(%rbp), %r13d
jmp 0x7742
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorl %ebx, %ebx
callq 0x3180
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd -0x78(%rbp), %xmm0
divsd 0x2a24(%rip), %xmm0     # 0xa180
movsd %xmm0, -0x48(%rbp)
divsd 0x2a1f(%rip), %xmm0     # 0xa188
callq 0x33b0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulss 0x2a1f(%rip), %xmm0     # 0xa1a0
cvtss2sd %xmm0, %xmm0
addsd -0x48(%rbp), %xmm0
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %ebx, %xmm3
divsd -0x40(%rbp), %xmm3
movsd 0x29eb(%rip), %xmm0     # 0xa190
subsd %xmm3, %xmm0
cvtss2sd %xmm2, %xmm2
leaq 0x2a64(%rip), %rdi      # 0xa218
movl -0x50(%rbp), %r12d
movl %r12d, %esi
movl %ebx, %edx
movb $0x3, %al
callq 0x3060
movq 0x67ed(%rip), %rax      # 0xdfb8
movq (%rax), %rdi
callq 0x32a0
cmpl %r13d, %ebx
setg %al
cmpl $-0x1, %r13d
setne %cl
testb %al, %cl
movl %ebx, %r14d
movq 0x67ec(%rip), %rbx      # 0xdfd8
jne 0x7819
movl -0x2c(%rbp), %ecx
incl %ecx
cmpl %r13d, %r14d
movl $0x0, %eax
cmovnel %eax, %ecx
movl %ecx, -0x2c(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x82ec
movl %r14d, %eax
movl %r14d, %r13d
jmp 0x781c
movl %r14d, %eax
cmpl $0x96, %r12d
jne 0x7868
movl $0x17, %edx
movq %rbx, %rdi
leaq 0x29fe(%rip), %rsi      # 0xa232
callq 0x3290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
movl $0x96, %r12d
jmp 0x78ad
testl %eax, %eax
je 0x78ad
cmpl $0x5, -0x2c(%rbp)
jne 0x78cb
movl $0x2a, %edx
movq %rbx, %rdi
leaq 0x29c9(%rip), %rsi      # 0xa24a
callq 0x3290
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
xorl %ebx, %ebx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x78bd
callq 0x3210
testb %bl, %bl
leaq -0x68(%rbp), %r14
jne 0x7605
jmp 0x78d2
incl %r12d
movb $0x1, %bl
jmp 0x78af
movq 0x66ff(%rip), %r14      # 0xdfd8
leaq 0x2995(%rip), %rsi      # 0xa275
movl $0x1b, %edx
movq %r14, %rdi
callq 0x3290
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x66cd(%rip), %rdi      # 0xdfd8
callq 0x3040
movq %rax, %rdi
callq 0x3190
movq 0x66b9(%rip), %rdi      # 0xdfd8
leaq 0x296b(%rip), %rsi      # 0xa291
movl $0x12, %edx
callq 0x3290
movq 0x66a1(%rip), %rdi      # 0xdfd8
movl %r13d, %esi
callq 0x33d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
leaq -0x90(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x82ec
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x798a
callq 0x3210
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x79b6
jmp 0x79a5
jmp 0x79a5
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x79b6
callq 0x3210
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x79c7
callq 0x3210
movq %rbx, %rdi
callq 0x33e0
nop