// File: aleperno[P]Datos/HashingPerceptron.cpp
// Function: HashingPerceptron::HashingPerceptron(char*, int, float, unsigned int, float)
HashingPerceptron::HashingPerceptron(char* path, int token_size, float learning_rate, unsigned int hash_size, float init) {

	ifstream myfile;
	myfile.open(path);

	Parser* parser = new Parser();

	//NO USO MAPPER
	//this->mapper = NULL;
	//El largo de la frase debe estar aca
	this->phrase_lenght = token_size;
	//Largo del hash
	this->hash_size = hash_size;
	clock_t inicio = clock();
	if(myfile.is_open())
	{
		printf("Began to represent reviews as vectors using hashing trick\n");

		string linea;
		while( getline(myfile,linea) )
		{
			vector<string> tokenized_columns = parser->tokenizeColumns(linea);
			string movie_id = tokenized_columns[0];
			//this->strToInt(tokenized_columns[1]);
			int sentiment = (tokenized_columns[1] == "0") ? 0:1;
			string review = tokenized_columns[2];

			vector<string> tokenized_words = parser->tokenizeReviews(review);
			//this->show_vec_str(tokenized_words);
			pair<int,vector<unsigned int>> par_aux;
			vector<unsigned int> vec_pos = this->getVector(tokenized_words);
			par_aux = make_pair(sentiment,vec_pos);
			this->test_vec.push_back(par_aux);
			//movie_id -> sentiment, [words]
			this->aux_map_2[movie_id] = par_aux;

		}
	}
	clock_t final = clock();
	double secs = double(final - inicio) / CLOCKS_PER_SEC;
	float min = floor(secs/60);
	float sec = secs - min*60;
	printf("Took %0.0f:%.3f\n",min,sec);
	delete parser;
	this->learning_rate = learning_rate;
	this->threshold = 0.5;

	this->weights = vector<float>(this->hash_size,init);
	cout << "Weights were initialized with " << this->weights[0] << endl;
	this->Initialize();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movss %xmm0, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
movq %rdi, %rax
movq %rax, -0x3f0(%rbp)
callq 0xf4f0
movq -0x3d8(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x3e8(%rbp)
callq 0xf510
movq -0x3d8(%rbp), %rdi
addq $0x58, %rdi
movq %rdi, -0x3e0(%rbp)
callq 0xf530
movq -0x3d8(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0x3d0(%rbp)
callq 0xf550
leaq -0x228(%rbp), %rdi
callq 0x4370
jmp 0xdb23
movq -0x10(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x41b0
jmp 0xdb3a
movl $0x60, %edi
callq 0x42e0
movq %rax, -0x3f8(%rbp)
jmp 0xdb4d
movq -0x3f8(%rbp), %rdi
callq 0x5450
jmp 0xdb5b
movq -0x3f0(%rbp), %rax
movq -0x3f8(%rbp), %rcx
movq %rcx, -0x240(%rbp)
movl -0x14(%rbp), %ecx
movl %ecx, 0x30(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x34(%rax)
callq 0x41c0
movq %rax, -0x248(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x44c0
movb %al, -0x3f9(%rbp)
jmp 0xdb9c
movb -0x3f9(%rbp), %al
testb $0x1, %al
jne 0xdbab
jmp 0xe00a
leaq 0x9602(%rip), %rdi      # 0x171b4
xorl %eax, %eax
callq 0x4060
jmp 0xdbbb
leaq -0x268(%rbp), %rdi
callq 0x4440
leaq -0x228(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x40a0
movq %rax, -0x408(%rbp)
jmp 0xdbe3
movq -0x408(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x43c0
movb %al, -0x409(%rbp)
jmp 0xdc01
movb -0x409(%rbp), %al
testb $0x1, %al
jne 0xdc10
jmp 0xdfeb
movq -0x240(%rbp), %rax
movq %rax, -0x418(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x4130
jmp 0xdc33
movq -0x418(%rbp), %rsi
leaq -0x280(%rbp), %rdi
leaq -0x2a0(%rbp), %rdx
callq 0x5660
jmp 0xdc4f
leaq -0x2a0(%rbp), %rdi
callq 0x41a0
xorl %eax, %eax
movl %eax, %esi
leaq -0x280(%rbp), %rdi
callq 0x4e10
movq %rax, %rsi
leaq -0x2c0(%rbp), %rdi
callq 0x4130
jmp 0xdc7c
leaq -0x280(%rbp), %rdi
movl $0x1, %esi
callq 0x4e10
movq %rax, %rdi
leaq 0x9558(%rip), %rsi      # 0x171ef
callq 0xd640
movb %al, -0x419(%rbp)
jmp 0xdca4
movb -0x419(%rbp), %al
notb %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x2c4(%rbp)
leaq -0x280(%rbp), %rdi
movl $0x2, %esi
callq 0x4e10
movq %rax, %rsi
leaq -0x2e8(%rbp), %rdi
callq 0x4130
jmp 0xdcda
movq -0x240(%rbp), %rax
movq %rax, -0x428(%rbp)
leaq -0x320(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x4130
jmp 0xdcfd
movq -0x428(%rbp), %rsi
leaq -0x300(%rbp), %rdi
leaq -0x320(%rbp), %rdx
callq 0x5890
jmp 0xdd19
leaq -0x320(%rbp), %rdi
callq 0x41a0
leaq -0x340(%rbp), %rdi
callq 0xf570
jmp 0xdd33
leaq -0x370(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0xf5b0
jmp 0xdd48
movq -0x3f0(%rbp), %rsi
leaq -0x358(%rbp), %rdi
leaq -0x370(%rbp), %rdx
callq 0xe250
jmp 0xdd64
leaq -0x370(%rbp), %rdi
callq 0x69d0
leaq -0x390(%rbp), %rdi
leaq -0x2c4(%rbp), %rsi
leaq -0x358(%rbp), %rdx
callq 0xf6a0
jmp 0xdd8c
leaq -0x340(%rbp), %rdi
movq %rdi, -0x430(%rbp)
leaq -0x390(%rbp), %rsi
movq %rsi, -0x438(%rbp)
callq 0xf6e0
movq -0x438(%rbp), %rdi
callq 0xf720
movq -0x3f0(%rbp), %rdi
movq -0x430(%rbp), %rsi
addq $0x88, %rdi
callq 0xf740
jmp 0xddd5
movq -0x3f0(%rbp), %rdi
addq $0x58, %rdi
leaq -0x2c0(%rbp), %rsi
callq 0xf7b0
movq %rax, -0x440(%rbp)
jmp 0xddf5
movq -0x440(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xf890
jmp 0xde0a
leaq -0x358(%rbp), %rdi
callq 0xf8d0
leaq -0x340(%rbp), %rdi
callq 0xf720
leaq -0x300(%rbp), %rdi
callq 0x69d0
leaq -0x2e8(%rbp), %rdi
callq 0x41a0
leaq -0x2c0(%rbp), %rdi
callq 0x41a0
leaq -0x280(%rbp), %rdi
callq 0x69d0
jmp 0xdbc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xe214
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xe208
movq -0x3f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
callq 0x42b0
jmp 0xe208
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdff9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x41a0
jmp 0xdff9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdfdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdfd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdfc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x41a0
jmp 0xdfc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdfb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0xdfad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x370(%rbp), %rdi
callq 0x69d0
jmp 0xdfad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x358(%rbp), %rdi
callq 0xf8d0
leaq -0x340(%rbp), %rdi
callq 0xf720
leaq -0x300(%rbp), %rdi
callq 0x69d0
leaq -0x2e8(%rbp), %rdi
callq 0x41a0
leaq -0x2c0(%rbp), %rdi
callq 0x41a0
leaq -0x280(%rbp), %rdi
callq 0x69d0
jmp 0xdff9
leaq -0x268(%rbp), %rdi
callq 0x41a0
jmp 0xe00a
leaq -0x268(%rbp), %rdi
callq 0x41a0
jmp 0xe208
callq 0x41c0
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rax
movq -0x248(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x915c(%rip), %xmm1     # 0x17190
divsd %xmm1, %xmm0
movsd %xmm0, -0x3a0(%rbp)
movsd -0x3a0(%rbp), %xmm0
movsd 0x9148(%rip), %xmm1     # 0x17198
divsd %xmm1, %xmm0
callq 0x4500
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3a4(%rbp)
movsd -0x3a0(%rbp), %xmm0
movss -0x3a4(%rbp), %xmm1
movss 0x9133(%rip), %xmm2     # 0x171b0
mulss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3a8(%rbp)
movss -0x3a4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x3a8(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x913d(%rip), %rdi      # 0x171f1
movb $0x2, %al
callq 0x4060
jmp 0xe0bd
movq -0x240(%rbp), %rax
movq %rax, -0x448(%rbp)
cmpq $0x0, %rax
je 0xe0de
movq -0x448(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x3f0(%rbp), %rax
movss -0x18(%rbp), %xmm0
movss %xmm0, 0x50(%rax)
movl $0x3f000000, 0x54(%rax) # imm = 0x3F000000
movl 0x34(%rax), %eax
movq %rax, -0x458(%rbp)
leaq -0x3c1(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0xf930
movq -0x458(%rbp), %rsi
movq -0x450(%rbp), %rcx
leaq -0x3c0(%rbp), %rdi
leaq -0x20(%rbp), %rdx
callq 0xf950
jmp 0xe133
movq -0x3f0(%rbp), %rdi
addq $0x38, %rdi
leaq -0x3c0(%rbp), %rsi
movq %rsi, -0x468(%rbp)
callq 0xf9d0
movq -0x468(%rbp), %rdi
callq 0xfa00
leaq -0x3c1(%rbp), %rdi
callq 0xfa60
movq 0x14e68(%rip), %rdi     # 0x22fd8
leaq 0x908b(%rip), %rsi      # 0x17202
callq 0x42d0
movq %rax, -0x460(%rbp)
jmp 0xe185
movq -0x3f0(%rbp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4ed0
movq -0x460(%rbp), %rdi
movss (%rax), %xmm0
callq 0x4220
movq %rax, -0x470(%rbp)
jmp 0xe1b2
movq -0x470(%rbp), %rdi
movq 0x14e08(%rip), %rsi     # 0x22fc8
callq 0x4310
jmp 0xe1c7
movq -0x3f0(%rbp), %rdi
callq 0xe4e0
jmp 0xe1d5
leaq -0x228(%rbp), %rdi
callq 0x40e0
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x3c1(%rbp), %rdi
callq 0xfa60
leaq -0x228(%rbp), %rdi
callq 0x40e0
movq -0x3d0(%rbp), %rdi
callq 0xfa80
movq -0x3e0(%rbp), %rdi
callq 0xfae0
movq -0x3e8(%rbp), %rdi
callq 0xfa00
movq -0x3d8(%rbp), %rdi
callq 0xfb00
movq -0x230(%rbp), %rdi
callq 0x4550