// File: /workspace/github_cpp_makefile_star2_O2/thunlp[P]KB2E/TransE/Train_TransE.cpp
// Function: Train::bfgs()
void bfgs()
    {
        res=0;
        int nbatches=100;
        int nepoch = 1000;
        int batchsize = fb_h.size()/nbatches;
            for (int epoch=0; epoch<nepoch; epoch++)
            {

            	res=0;
             	for (int batch = 0; batch<nbatches; batch++)
             	{
             		relation_tmp=relation_vec;
            		entity_tmp = entity_vec;
             		for (int k=0; k<batchsize; k++)
             		{
						int i=rand_max(fb_h.size());
						int j=rand_max(entity_num);
						double pr = 1000*right_num[fb_r[i]]/(right_num[fb_r[i]]+left_num[fb_r[i]]);
						if (method ==0)
                            pr = 500;
						if (rand()%1000<pr)
						{
							while (ok[make_pair(fb_h[i],fb_r[i])].count(j)>0)
								j=rand_max(entity_num);
							train_kb(fb_h[i],fb_l[i],fb_r[i],fb_h[i],j,fb_r[i]);
						}
						else
						{
							while (ok[make_pair(j,fb_r[i])].count(fb_l[i])>0)
								j=rand_max(entity_num);
							train_kb(fb_h[i],fb_l[i],fb_r[i],j,fb_l[i],fb_r[i]);
						}
                		norm(relation_tmp[fb_r[i]]);
                		norm(entity_tmp[fb_h[i]]);
                		norm(entity_tmp[fb_l[i]]);
                		norm(entity_tmp[j]);
             		}
		            relation_vec = relation_tmp;
		            entity_vec = entity_tmp;
             	}
                cout<<"epoch:"<<epoch<<' '<<res<<endl;
                FILE* f2 = fopen(("relation2vec."+version).c_str(),"w");
                FILE* f3 = fopen(("entity2vec."+version).c_str(),"w");
                for (int i=0; i<relation_num; i++)
                {
                    for (int ii=0; ii<n; ii++)
                        fprintf(f2,"%.6lf\t",relation_vec[i][ii]);
                    fprintf(f2,"\n");
                }
                for (int i=0; i<entity_num; i++)
                {
                    for (int ii=0; ii<n; ii++)
                        fprintf(f3,"%.6lf\t",entity_vec[i][ii]);
                    fprintf(f3,"\n");
                }
                fclose(f2);
                fclose(f3);
            }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
andq $0x0, 0x38(%rdi)
movq 0x70(%rdi), %rax
subq 0x68(%rdi), %rax
sarq $0x2, %rax
xorl %esi, %esi
pushq $0x64
popq %rcx
xorl %edx, %edx
divq %rcx
leaq 0xc8(%rdi), %rcx
movq %rcx, 0x30(%rsp)
leaq 0xf8(%rdi), %rcx
movq %rcx, 0x50(%rsp)
leaq 0xe0(%rdi), %rcx
movq %rcx, 0x28(%rsp)
leaq 0x110(%rdi), %rcx
movq %rcx, 0x48(%rsp)
testl %eax, %eax
cmovlel %esi, %eax
movq %rax, 0x58(%rsp)
leaq 0x68(%rsp), %r13
leaq 0x14(%rsp), %r14
cmpl $0x3e8, %esi            # imm = 0x3E8
je 0x43dd
movq %rsi, 0x40(%rsp)
andq $0x0, 0x38(%rbx)
xorl %eax, %eax
cmpl $0x64, %eax
je 0x4263
movl %eax, 0x3c(%rsp)
movq 0x50(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x47ec
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x47ec
xorl %eax, %eax
cmpl 0x58(%rsp), %eax
je 0x423a
movl %eax, 0x20(%rsp)
movq 0x70(%rbx), %rsi
subq 0x68(%rbx), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x48ca
movl %eax, %r15d
movl 0x36f3d(%rip), %esi     # 0x3af44
movq %rbx, %rdi
callq 0x48ca
movl %eax, 0x14(%rsp)
movslq %r15d, %r15
leaq (,%r15,4), %rbp
movq 0x98(%rbx), %rsi
addq %rbp, %rsi
leaq 0x37069(%rip), %r12     # 0x3b098
movq %r12, %rdi
callq 0x327e
movsd (%rax), %xmm0
mulsd 0x1ffd(%rip), %xmm0     # 0x6040
movsd %xmm0, 0x18(%rsp)
movq 0x98(%rbx), %rsi
addq %rbp, %rsi
movq %r12, %rdi
callq 0x327e
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x98(%rbx), %rsi
addq %rbp, %rsi
leaq 0x36ff2(%rip), %rdi     # 0x3b068
callq 0x327e
cmpl $0x0, 0x34(%rbx)
movsd 0x1fc1(%rip), %xmm0     # 0x6048
je 0x409d
movsd 0x60(%rsp), %xmm1
addsd (%rax), %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x2070
cltd
movl $0x3e8, %ecx            # imm = 0x3E8
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x410e
movq 0x68(%rbx), %rax
movq 0x98(%rbx), %rcx
movl (%rax,%r15,4), %eax
movl (%rcx,%r15,4), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x68(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3990
movq %rax, %rdi
movq %r14, %rsi
callq 0x490e
testq %rax, %rax
je 0x4161
movl 0x36e44(%rip), %esi     # 0x3af44
movq %rbx, %rdi
callq 0x48ca
movl %eax, 0x14(%rsp)
jmp 0x40c0
movl 0x14(%rsp), %eax
movq 0x98(%rbx), %rcx
movl (%rcx,%r15,4), %ecx
shlq $0x20, %rcx
movl %eax, %eax
orq %rcx, %rax
movq %rax, 0x68(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3990
movq 0x80(%rbx), %rsi
addq %rbp, %rsi
movq %rax, %rdi
callq 0x490e
testq %rax, %rax
je 0x418f
movl 0x36df1(%rip), %esi     # 0x3af44
movq %rbx, %rdi
callq 0x48ca
movl %eax, 0x14(%rsp)
jmp 0x4112
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%r15,4), %esi
movl (%rcx,%r15,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%r15,4), %ecx
movl 0x14(%rsp), %r9d
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %esi, %r8d
jmp 0x41bb
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%r15,4), %esi
movl (%rcx,%r15,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%r15,4), %ecx
movl 0x14(%rsp), %r8d
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %edx, %r9d
callq 0x4928
movq 0x98(%rbx), %rax
movslq (%rax,%r15,4), %rax
imulq $0x18, %rax, %rsi
addq 0xf8(%rbx), %rsi
movq %rbx, %rdi
callq 0x3ee0
movq 0x68(%rbx), %rax
movslq (%rax,%r15,4), %rax
imulq $0x18, %rax, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x3ee0
movq 0x80(%rbx), %rax
movslq (%rax,%r15,4), %rax
imulq $0x18, %rax, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x3ee0
movslq 0x14(%rsp), %rax
imulq $0x18, %rax, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x3ee0
movl 0x20(%rsp), %eax
incl %eax
jmp 0x3fdc
movq 0x30(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x47ec
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x47ec
movl 0x3c(%rsp), %eax
incl %eax
jmp 0x3faf
movq 0x5d6e(%rip), %rdi      # 0x9fd8
leaq 0x1f19(%rip), %rsi      # 0x618a
callq 0x2190
movq %rax, %rdi
movq 0x40(%rsp), %rsi
callq 0x22c0
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x21e0
movsd 0x38(%rbx), %xmm0
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x20c0
movq %r13, %rdi
leaq 0x1ee4(%rip), %rsi      # 0x6191
leaq 0x5f24(%rip), %r15      # 0xa1d8
movq %r15, %rdx
callq 0x49cb
movq 0x68(%rsp), %rdi
leaq 0x1ed7(%rip), %r12      # 0x619f
movq %r12, %rsi
callq 0x21f0
movq %rax, 0x20(%rsp)
movq %r13, %rdi
callq 0x2338
movq %r13, %rdi
leaq 0x1eba(%rip), %rsi      # 0x61a1
movq %r15, %rdx
callq 0x49cb
movq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x21f0
movq %rax, %r12
movq %r13, %rdi
callq 0x2338
xorl %ecx, %ecx
movslq 0x36c30(%rip), %rax     # 0x3af40
cmpq %rax, %rcx
jge 0x4369
movq %rcx, 0x18(%rsp)
imulq $0x18, %rcx, %r15
xorl %ebp, %ebp
movslq 0x30(%rbx), %rax
cmpq %rax, %rbp
jge 0x4352
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rax
movsd (%rax,%rbp,8), %xmm0
movq 0x20(%rsp), %rdi
leaq 0x1e67(%rip), %rsi      # 0x61ad
movb $0x1, %al
callq 0x2240
incq %rbp
jmp 0x4320
pushq $0xa
popq %rdi
movq 0x20(%rsp), %rsi
callq 0x2210
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x4309
xorl %ebp, %ebp
movslq 0x36bd2(%rip), %rax     # 0x3af44
cmpq %rax, %rbp
jge 0x43bf
xorl %r15d, %r15d
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jge 0x43af
movq 0x28(%rsp), %rax
movq (%rax), %rax
imulq $0x18, %rbp, %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%r15,8), %xmm0
movq %r12, %rdi
leaq 0x1e0a(%rip), %rsi      # 0x61ad
movb $0x1, %al
callq 0x2240
incq %r15
jmp 0x437a
pushq $0xa
popq %rdi
movq %r12, %rsi
callq 0x2210
incq %rbp
jmp 0x436b
movq 0x20(%rsp), %rdi
callq 0x21a0
movq %r12, %rdi
callq 0x21a0
movq 0x40(%rsp), %rsi
incl %esi
jmp 0x3f97
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop