// File: /workspace/github_cpp_makefile_star2_O1/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 0x6a2e(%rip), %rbx      # 0xdfd8
leaq 0x2c41(%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 0x2d23(%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
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x38(%r15), %rax
movq %rax, -0x50(%rbp)
movl $0x1, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
movl %r12d, -0x48(%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, -0x40(%rbp)
cmpq %rax, %r12
je 0x7760
movl %r13d, -0x44(%rbp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movl (%r12), %eax
movl %eax, -0x70(%rbp)
leaq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x8bc2
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
callq 0x8286
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rax
subq %rdi, %rax
je 0x76cf
sarq $0x2, %rax
movq 0x38(%r15), %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 0x76bb
jmp 0x76d3
xorpd %xmm0, %xmm0
testq %rdi, %rdi
je 0x76e7
movss %xmm0, -0x38(%rbp)
callq 0x3210
movss -0x38(%rbp), %xmm0
xorl %eax, %eax
ucomiss 0x54(%r15), %xmm0
seta %al
movl -0x70(%rbp), %edx
subl %eax, %edx
je 0x7738
incl %ebx
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
cmpq %rcx, %rax
leaq -0x68(%rbp), %r14
je 0x773c
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
movq 0x38(%r15), %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 0x7716
jmp 0x773c
leaq -0x68(%rbp), %r14
incl %r13d
addq $0x20, %r12
cmpq -0x40(%rbp), %r12
jne 0x7677
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x44(%rbp), %r13d
jmp 0x776b
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %ebx, %ebx
callq 0x3180
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd -0x78(%rbp), %xmm0
divsd 0x29fb(%rip), %xmm0     # 0xa180
movsd %xmm0, -0x40(%rbp)
divsd 0x29f6(%rip), %xmm0     # 0xa188
callq 0x33b0
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulss 0x29f6(%rip), %xmm0     # 0xa1a0
cvtss2sd %xmm0, %xmm0
addsd -0x40(%rbp), %xmm0
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %ebx, %xmm3
divsd -0x38(%rbp), %xmm3
movsd 0x29c2(%rip), %xmm0     # 0xa190
subsd %xmm3, %xmm0
cvtss2sd %xmm2, %xmm2
leaq 0x2a3b(%rip), %rdi      # 0xa218
movl -0x48(%rbp), %r12d
movl %r12d, %esi
movl %ebx, %edx
movb $0x3, %al
callq 0x3060
movq 0x67c4(%rip), %rax      # 0xdfb8
movq (%rax), %rdi
callq 0x32a0
cmpl %r13d, %ebx
setle %al
cmpl $-0x1, %r13d
sete %cl
orb %al, %cl
movl %ebx, %r14d
movq 0x67c3(%rip), %rbx      # 0xdfd8
je 0x7842
movl -0x2c(%rbp), %ecx
incl %ecx
cmpl %r13d, %r14d
movl $0x0, %eax
cmovnel %eax, %ecx
movl %ecx, -0x2c(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x8306
movl %r14d, %eax
movl %r14d, %r13d
jmp 0x7845
movl %r14d, %eax
cmpl $0x96, %r12d
jne 0x7891
movl $0x17, %edx
movq %rbx, %rdi
leaq 0x29d5(%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 0x78d6
testl %eax, %eax
je 0x78d6
cmpl $0x5, -0x2c(%rbp)
jne 0x78f4
movl $0x2a, %edx
movq %rbx, %rdi
leaq 0x29a0(%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 0x78e6
callq 0x3210
testb %bl, %bl
leaq -0x68(%rbp), %r14
jne 0x7637
jmp 0x78fb
incl %r12d
movb $0x1, %bl
jmp 0x78d8
movq 0x66d6(%rip), %rbx      # 0xdfd8
leaq 0x296c(%rip), %rsi      # 0xa275
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x3290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x66a4(%rip), %rdi      # 0xdfd8
callq 0x3040
movq %rax, %rdi
callq 0x3190
movq 0x6690(%rip), %rdi      # 0xdfd8
leaq 0x2942(%rip), %rsi      # 0xa291
movl $0x12, %edx
callq 0x3290
movq 0x6678(%rip), %rdi      # 0xdfd8
movl %r13d, %esi
callq 0x33d0
movq %rax, %rbx
movq (%rax), %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 -0x90(%rbp), %rsi
movq -0x50(%rbp), %rdi
callq 0x8306
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x79b3
callq 0x3210
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x79df
jmp 0x79ce
jmp 0x79ce
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x79df
callq 0x3210
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x79f0
callq 0x3210
movq %rbx, %rdi
callq 0x33e0