// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rdi, %rbx
movq $0x0, 0x38(%rdi)
movq 0x70(%rdi), %rax
subq 0x68(%rdi), %rax
sarq $0x2, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rcx # imm = 0x28F5C28F5C28F5C3
mulq %rcx
shrq $0x2, %rdx
movq %rdx, 0x68(%rsp)
leaq 0xc8(%rdi), %r14
leaq 0xf8(%rdi), %r15
leaq 0xe0(%rdi), %r12
leaq 0x110(%rdi), %rbp
movq $0x0, 0x18(%rsp)
leaq 0x28(%rsp), %r13
movq %r14, 0x60(%rsp)
movq %r15, 0x58(%rsp)
movq %r12, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
movq $0x0, 0x38(%rbx)
xorl %eax, %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4c3c
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4c3c
cmpl $0x0, 0x68(%rsp)
jle 0x4676
xorl %r14d, %r14d
movl %r14d, 0x10(%rsp)
movq 0x70(%rbx), %rsi
subq 0x68(%rbx), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x4db4
movl %eax, %ebp
movl 0x36b4e(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db4
movl %eax, %r12d
movslq %ebp, %rbp
leaq (,%rbp,4), %r14
movq 0x98(%rbx), %rsi
addq %r14, %rsi
leaq 0x36c7b(%rip), %r15     # 0x3b088
movq %r15, %rdi
callq 0x36a0
movsd (%rax), %xmm0
mulsd 0x2c27(%rip), %xmm0     # 0x7048
movsd %xmm0, 0x8(%rsp)
movq 0x98(%rbx), %rsi
addq %r14, %rsi
movq %r15, %rdi
callq 0x36a0
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0x98(%rbx), %rsi
addq %r14, %rsi
leaq 0x36c04(%rip), %rdi     # 0x3b058
callq 0x36a0
cmpl $0x0, 0x34(%rbx)
movsd 0x2beb(%rip), %xmm0     # 0x7050
je 0x447b
movsd 0x70(%rsp), %xmm1
addsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x2080
cltq
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
imull $0x3e8, %ecx, %ecx      # imm = 0x3E8
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x453e
movl 0x10(%rsp), %r14d
movq 0x68(%rbx), %rax
movq 0x98(%rbx), %rcx
movl (%rax,%rbp,4), %eax
movl (%rcx,%rbp,4), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x28(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d86
movq 0x10(%rax), %rdx
addq $0x8, %rax
movq %rax, %rcx
testq %rdx, %rdx
je 0x4513
movq %rax, %rcx
xorl %esi, %esi
cmpl %r12d, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x44fb
movq %rax, %rdx
cmpq %rax, %rcx
je 0x4526
cmpl 0x20(%rcx), %r12d
cmovlq %rax, %rcx
movq %rcx, %rdx
cmpq %rax, %rdx
je 0x458c
movl 0x36a03(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db4
movl %eax, %r12d
jmp 0x44c0
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %eax
shlq $0x20, %rax
movl %r12d, %ecx
orq %rax, %rcx
movq %rcx, 0x28(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d86
movq 0x80(%rbx), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x4df8
testq %rax, %rax
je 0x45ba
movl 0x369b5(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db4
movl %eax, %r12d
jmp 0x453e
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%rbp,4), %esi
movl (%rcx,%rbp,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %esi, %r8d
movl %r12d, %r9d
callq 0x4e42
jmp 0x45eb
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%rbp,4), %esi
movl (%rcx,%rbp,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %r12d, %r8d
movl %edx, %r9d
callq 0x4e42
movl 0x10(%rsp), %r14d
movq 0x98(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0xf8(%rbx), %rsi
movq %rbx, %rdi
callq 0x428a
movq 0x68(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x428a
movq 0x80(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x428a
movslq %r12d, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x428a
incl %r14d
cmpl 0x68(%rsp), %r14d
jne 0x43c5
movq 0x60(%rsp), %r14
movq %r14, %rdi
movq 0x58(%rsp), %r15
movq %r15, %rsi
callq 0x4c3c
movq 0x50(%rsp), %r12
movq %r12, %rdi
movq 0x48(%rsp), %rbp
movq %rbp, %rsi
callq 0x4c3c
movl 0x24(%rsp), %eax
incl %eax
cmpl $0x64, %eax
jne 0x439d
movl $0x6, %edx
movq 0x591d(%rip), %r14      # 0x9fd8
movq %r14, %rdi
leaq 0x2ac5(%rip), %rsi      # 0x718a
callq 0x21f0
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x22d0
movb $0x20, 0x28(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21f0
movsd 0x38(%rbx), %xmm0
movq %rax, %rdi
callq 0x22a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r13, %rdi
leaq 0x2a64(%rip), %rsi      # 0x7191
leaq 0x5a94(%rip), %rdx      # 0xa1c8
callq 0x4ee5
movq 0x28(%rsp), %rdi
leaq 0x2a5a(%rip), %rsi      # 0x719f
callq 0x2200
movq %rax, %r14
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4769
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %r14, 0x10(%rsp)
movq %r13, %rdi
leaq 0x2a29(%rip), %rsi      # 0x71a1
leaq 0x5a49(%rip), %rdx      # 0xa1c8
callq 0x4ee5
movq 0x28(%rsp), %rdi
leaq 0x2a0f(%rip), %rsi      # 0x719f
callq 0x2200
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x47b6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21d0
cmpl $0x0, 0x36773(%rip)     # 0x3af30
jle 0x4821
xorl %r14d, %r14d
cmpl $0x0, 0x30(%rbx)
leaq 0x29e0(%rip), %r12      # 0x71ad
movq 0x10(%rsp), %rbp
jle 0x4805
xorl %r15d, %r15d
movq 0xc8(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2240
incq %r15
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jl 0x47d7
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2220
incq %r14
movslq 0x36714(%rip), %rax     # 0x3af30
cmpq %rax, %r14
jl 0x47c2
cmpl $0x0, 0x3670c(%rip)     # 0x3af34
movq 0x8(%rsp), %rbp
jle 0x488c
xorl %r14d, %r14d
cmpl $0x0, 0x30(%rbx)
leaq 0x2970(%rip), %r12      # 0x71ad
jle 0x4870
xorl %r15d, %r15d
movq 0xe0(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2240
incq %r15
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jl 0x4842
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2220
incq %r14
movslq 0x366ad(%rip), %rax     # 0x3af34
cmpq %rax, %r14
jl 0x4832
movq 0x10(%rsp), %rdi
callq 0x21b0
movq %rbp, %rdi
callq 0x21b0
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
cmpl $0x3e8, %eax            # imm = 0x3E8
movq 0x60(%rsp), %r14
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %r12
movq 0x48(%rsp), %rbp
jne 0x4393
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq