// File: /workspace/github_cpp_makefile_star2_O2/fei3189[P]PLSI/./plsi.hpp
// Function: PLSI::_train(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void _train(const vector<string> &docs, int z_k, const vector<string> &w_stop) {
        float eps = 0.01;
        float last = 0, current = -1000;
        int iter_num = 0;
        vector<float> p_zwd(z_k, 0);

        _preprocess(docs, z_k, w_stop);
        clock_t t = clock();
        while (fabs(current - last) > eps) {
            ++iter_num;
            vector<vector<float> > p_wz_current = p_wz;
            vector<vector<float> > p_dz_current = p_dz;
            vector<float> p_z_current = p_z;
            for (int i = 0; i < c_doc; ++i)
                for (int k = 0; k < z_k; ++k)
                    p_dz[i][k] = 0;
            for (int i = 0; i < c_word; ++i)
                for (int k = 0; k < z_k; ++k)
                    p_wz[i][k] = 0;
            for (int k = 0; k < z_k; ++k)
                p_z[k] = 0;
            for (int i = 0; i < c_doc; ++i) {
                for (int _j = 0; _j < n_wd[i].size(); ++_j) {
                    Index adj = n_wd[i][_j];
                    int j = adj.idx;
                    int v = adj.value;
                    float sum_zwd = 0;
                    for (int k = 0; k < z_k; ++k) {
                        float tmp = p_wz_current[j][k] * p_dz_current[i][k] * p_z_current[k];
                        p_zwd[k] = tmp;
                        sum_zwd += tmp;
                    }
                    for (int k = 0; k < z_k; ++k)
                        p_zwd[k] /= sum_zwd;
                    for (int k = 0; k < z_k; ++k) {
                        p_wz[j][k] += v * p_zwd[k];
                        p_dz[i][k] += v * p_zwd[k];
                        p_z[k] += v * p_zwd[k];
                    }
                }
            }

            float sum_z = 0;
            for (int k = 0; k < z_k; ++k) {
                float sum_w = 0, sum_d = 0;
                for (int i = 0; i < c_word; ++i)
                    sum_w += p_wz[i][k];
                for (int i = 0; i < c_word; ++i)
                    p_wz[i][k] /= sum_w;
                
                for (int i = 0; i < c_doc; ++i)
                    sum_d += p_dz[i][k];
                for (int i = 0; i < c_doc; ++i)
                    p_dz[i][k] /= sum_d;
                sum_z += p_z[k];
            }
            for (int k = 0; k < z_k; ++k)
                p_z[k] /= _all_words;

            last = current;
            current = _likelihood();
        }
        cout << "Train finished. " << endl;
        cout << "Likelihood = " << current << endl;
        cout << "eps = " << eps << ", iteration times = " << iter_num << endl;
        cout << "Time spent " << 1.0 * (clock() - t) / CLOCKS_PER_SEC << "s" << endl;
        cout << "Number of topics = " << z_k << endl;
        cout << endl;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movslq %edx, %r12
leaq 0x78(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movq %r12, %rsi
callq 0x2ea0
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movq %rbx, %rcx
callq 0x2ef6
callq 0x2120
movq %rax, 0x30(%rsp)
leaq 0x18(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x30(%r15), %rax
movq %rax, 0x18(%rsp)
testl %ebp, %ebp
movl $0x0, %ebx
cmovgl %ebp, %ebx
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
movss 0x364e(%rip), %xmm1     # 0x6004
movl $0x0, 0x4(%rsp)
movq %r15, 0x28(%rsp)
movss (%rsp), %xmm0
movss %xmm1, (%rsp)
subss %xmm0, %xmm1
andps 0x3648(%rip), %xmm1     # 0x6020
ucomiss 0x3629(%rip), %xmm1     # 0x6008
jbe 0x2d29
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x3212
leaq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3212
leaq 0x90(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x326c
incl 0x4(%rsp)
movl 0x64(%r15), %edi
testl %edi, %edi
movl $0x0, %eax
cmovlel %eax, %edi
xorl %ecx, %ecx
cmpq %rdi, %rcx
je 0x2a50
imulq $0x18, %rcx, %rax
movq 0x10(%rsp), %rdx
addq (%rdx), %rax
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x2a4b
movq (%rax), %rsi
andl $0x0, (%rsi,%rdx,4)
incq %rdx
jmp 0x2a3a
incq %rcx
jmp 0x2a27
movl 0x60(%r15), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, 0x20(%rsp)
xorl %edx, %edx
cmpq 0x20(%rsp), %rdx
je 0x2a8b
imulq $0x18, %rdx, %rax
addq (%r15), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x2a86
movq (%rax), %rsi
andl $0x0, (%rsi,%rcx,4)
incq %rcx
jmp 0x2a75
incq %rdx
jmp 0x2a65
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x2aa3
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x2a95
movq 0x48(%r15), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq %rdi, 0x40(%rsp)
cmpq %rdi, %rax
je 0x2c06
movq %rax, 0x8(%rsp)
imulq $0x18, %rax, %rdi
movq 0x38(%rsp), %rax
movq (%rax,%rdi), %r8
movq 0x8(%rax,%rdi), %r9
subq %r8, %r9
sarq $0x3, %r9
xorl %r10d, %r10d
cmpq %r9, %r10
je 0x2bef
movl %ebp, %r15d
movslq (%r8,%r10,8), %rax
movl 0x4(%r8,%r10,8), %r14d
imulq $0x18, %rax, %r11
movq 0x78(%rsp), %rbp
addq %r11, %rbp
movq 0x60(%rsp), %r12
addq %rdi, %r12
movq 0x90(%rsp), %r13
xorps %xmm0, %xmm0
movq 0x48(%rsp), %rcx
xorl %eax, %eax
cmpq %rax, %rbx
je 0x2b44
movq (%rbp), %rdx
movq (%r12), %rsi
movss (%rsi,%rax,4), %xmm1
mulss (%rdx,%rax,4), %xmm1
mulss (%r13,%rax,4), %xmm1
movss %xmm1, (%rcx,%rax,4)
addss %xmm1, %xmm0
incq %rax
jmp 0x2b18
movq 0x48(%rsp), %rax
movss 0x34bb(%rip), %xmm1     # 0x600c
divss %xmm0, %xmm1
xorl %ecx, %ecx
movq 0x28(%rsp), %rdx
cmpq %rcx, %rbx
je 0x2b74
movss (%rax,%rcx,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
incq %rcx
jmp 0x2b5c
cvtsi2ss %r14d, %xmm0
movq 0x48(%rsp), %r14
addq (%rdx), %r11
movq 0x18(%rdx), %rbp
addq %rdi, %rbp
movq 0x30(%rdx), %r13
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x2be4
movss (%r14,%r12,4), %xmm1
mulss %xmm0, %xmm1
movq (%r11), %rax
addss (%rax,%r12,4), %xmm1
movss %xmm1, (%rax,%r12,4)
movss (%r14,%r12,4), %xmm1
mulss %xmm0, %xmm1
movq (%rbp), %rax
addss (%rax,%r12,4), %xmm1
movss %xmm1, (%rax,%r12,4)
movss (%r14,%r12,4), %xmm1
mulss %xmm0, %xmm1
addss (%r13,%r12,4), %xmm1
movss %xmm1, (%r13,%r12,4)
incq %r12
jmp 0x2b8f
incq %r10
movl %r15d, %ebp
jmp 0x2add
movq 0x8(%rsp), %rax
incq %rax
movq 0x28(%rsp), %r15
movq 0x40(%rsp), %rdi
jmp 0x2ab3
imulq $0x18, 0x20(%rsp), %rcx
imulq $0x18, %rdi, %rax
xorl %edx, %edx
cmpq %rbx, %rdx
je 0x2cbc
movq (%r15), %rsi
xorps %xmm0, %xmm0
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x2c38
movq (%rsi,%rdi), %r8
addss (%r8,%rdx,4), %xmm0
addq $0x18, %rdi
jmp 0x2c23
movss 0x33cc(%rip), %xmm1     # 0x600c
divss %xmm0, %xmm1
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x2c65
movq (%rsi,%rdi), %r8
movss (%r8,%rdx,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, (%r8,%rdx,4)
addq $0x18, %rdi
jmp 0x2c46
movq 0x10(%rsp), %rsi
movq (%rsi), %rsi
xorps %xmm0, %xmm0
xorl %edi, %edi
cmpq %rdi, %rax
je 0x2c87
movq (%rsi,%rdi), %r8
addss (%r8,%rdx,4), %xmm0
addq $0x18, %rdi
jmp 0x2c72
movss 0x337d(%rip), %xmm1     # 0x600c
divss %xmm0, %xmm1
xorl %edi, %edi
cmpq %rdi, %rax
je 0x2cb4
movq (%rsi,%rdi), %r8
movss (%r8,%rdx,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, (%r8,%rdx,4)
addq $0x18, %rdi
jmp 0x2c95
incq %rdx
jmp 0x2c12
cvtsi2ssl 0xd0(%r15), %xmm1
movq 0x30(%r15), %rax
movss 0x333b(%rip), %xmm0     # 0x600c
divss %xmm1, %xmm0
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x2cef
movss (%rax,%rcx,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, (%rax,%rcx,4)
incq %rcx
jmp 0x2cd7
movq %r15, %rdi
callq 0x32ba
movss %xmm0, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x3416
leaq 0x60(%rsp), %rdi
callq 0x33c8
leaq 0x78(%rsp), %rdi
callq 0x33c8
movss 0x8(%rsp), %xmm1
jmp 0x29c3
movq 0x72a0(%rip), %rdi      # 0x9fd0
leaq 0x3371(%rip), %rsi      # 0x60a8
callq 0x21a0
movq %rax, %rdi
callq 0x20e0
movq 0x7285(%rip), %rdi      # 0x9fd0
leaq 0x3367(%rip), %rsi      # 0x60b9
callq 0x21a0
movq %rax, %rdi
movss (%rsp), %xmm0
callq 0x2140
movq %rax, %rdi
callq 0x20e0
movq 0x725d(%rip), %rdi      # 0x9fd0
leaq 0x334d(%rip), %rsi      # 0x60c7
callq 0x21a0
movsd 0x32b9(%rip), %xmm0     # 0x6040
movq %rax, %rdi
callq 0x2260
leaq 0x3338(%rip), %rsi      # 0x60ce
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0x22a0
movq %rax, %rdi
callq 0x20e0
movq 0x7217(%rip), %rdi      # 0x9fd0
leaq 0x3323(%rip), %rsi      # 0x60e3
callq 0x21a0
movq %rax, %rbx
callq 0x2120
subq 0x30(%rsp), %rax
cvtsi2sd %rax, %xmm0
mulsd 0x3269(%rip), %xmm0     # 0x6048
movq %rbx, %rdi
callq 0x2260
leaq 0x3289(%rip), %rsi      # 0x6077
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20e0
movq 0x71cb(%rip), %rdi      # 0x9fd0
leaq 0x32e3(%rip), %rsi      # 0x60ef
callq 0x21a0
movq %rax, %rdi
movl %ebp, %esi
callq 0x22a0
movq %rax, %rdi
callq 0x20e0
movq 0x71a6(%rip), %rdi      # 0x9fd0
callq 0x20e0
leaq 0x48(%rsp), %rdi
callq 0x3416
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e7f
jmp 0x2e7f
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x3416
jmp 0x2e64
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x33c8
jmp 0x2e73
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x33c8
jmp 0x2e82
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3416
movq %rbx, %rdi
callq 0x22b0