// File: 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:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movl %edx, 0x1c4(%rsp)
movq %rcx, 0x1b8(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl $0x3c23d70a, 0x1b4(%rsp) # imm = 0x3C23D70A
movl $0x0, 0x1b0(%rsp)
movl $0xc47a0000, 0x1ac(%rsp) # imm = 0xC47A0000
movl $0x0, 0x1a8(%rsp)
movslq 0x1c4(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl $0x0, 0x18c(%rsp)
leaq 0x18b(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x3dc0
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rcx
leaq 0x190(%rsp), %rdi
leaq 0x18c(%rsp), %rdx
callq 0x3dd0
jmp 0x2e69
leaq 0x18b(%rsp), %rdi
callq 0x3e50
movq 0xa8(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
movl 0x1c4(%rsp), %edx
movq 0x1b8(%rsp), %rcx
callq 0x3e60
jmp 0x2e9c
callq 0x2150
movq %rax, 0x170(%rsp)
movss 0x1ac(%rsp), %xmm0
movss 0x1b0(%rsp), %xmm1
subss %xmm1, %xmm0
callq 0x44c0
movss %xmm0, 0xa4(%rsp)
jmp 0x2ecf
movss 0xa4(%rsp), %xmm0
ucomiss 0x1b4(%rsp), %xmm0
jbe 0x3886
movq 0xa8(%rsp), %rsi
movl 0x1a8(%rsp), %eax
incl %eax
movl %eax, 0x1a8(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x44e0
jmp 0x2f0d
movq 0xa8(%rsp), %rsi
addq $0x18, %rsi
leaq 0x140(%rsp), %rdi
callq 0x44e0
jmp 0x2f28
movq 0xa8(%rsp), %rsi
addq $0x30, %rsi
leaq 0x128(%rsp), %rdi
callq 0x45e0
jmp 0x2f43
movl $0x0, 0x124(%rsp)
movq 0xa8(%rsp), %rcx
movl 0x124(%rsp), %eax
cmpl 0x64(%rcx), %eax
jge 0x3051
movl $0x0, 0x120(%rsp)
movl 0x120(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x3039
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
movslq 0x124(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0x120(%rsp), %rsi
callq 0x4700
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x2f71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
leaq 0x18b(%rsp), %rdi
callq 0x3e50
jmp 0x3a62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
jmp 0x3a55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
jmp 0x3874
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
jmp 0x3867
jmp 0x303b
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x2f4e
movl $0x0, 0x11c(%rsp)
movq 0xa8(%rsp), %rcx
movl 0x11c(%rsp), %eax
cmpl 0x60(%rcx), %eax
jge 0x30e2
movl $0x0, 0x118(%rsp)
movl 0x118(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x30ca
movq 0xa8(%rsp), %rdi
movslq 0x11c(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0x118(%rsp), %rsi
callq 0x4700
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
jmp 0x307b
jmp 0x30cc
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x305c
movl $0x0, 0x114(%rsp)
movl 0x114(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x3130
movq 0xa8(%rsp), %rdi
addq $0x30, %rdi
movslq 0x114(%rsp), %rsi
callq 0x4700
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x30ed
movl $0x0, 0x110(%rsp)
movq 0xa8(%rsp), %rcx
movl 0x110(%rsp), %eax
cmpl 0x64(%rcx), %eax
jge 0x3523
movl $0x0, 0x10c(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0x10c(%rsp), %rax
movq %rax, 0x98(%rsp)
addq $0x48, %rdi
movslq 0x110(%rsp), %rsi
callq 0x4720
movq %rax, %rdi
callq 0x4740
movq %rax, %rcx
movq 0x98(%rsp), %rax
cmpq %rcx, %rax
jae 0x350b
movq 0xa8(%rsp), %rdi
addq $0x48, %rdi
movslq 0x110(%rsp), %rsi
callq 0x4720
movq %rax, %rdi
movslq 0x10c(%rsp), %rsi
callq 0x4760
movq (%rax), %rax
movq %rax, 0x104(%rsp)
movl 0x104(%rsp), %eax
movl %eax, 0x100(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0xfc(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xf8(%rsp)
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x331b
movslq 0x100(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0x46e0
movq %rax, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x4700
movss (%rax), %xmm0
movss %xmm0, 0x8c(%rsp)
movslq 0x110(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x46e0
movq %rax, %rdi
movslq 0xf4(%rsp), %rsi
callq 0x4700
movss 0x8c(%rsp), %xmm0
mulss (%rax), %xmm0
movss %xmm0, 0x90(%rsp)
movslq 0xf4(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x4700
movss 0x90(%rsp), %xmm0
mulss (%rax), %xmm0
movss %xmm0, 0xf0(%rsp)
movss 0xf0(%rsp), %xmm0
movss %xmm0, 0x94(%rsp)
movslq 0xf4(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4700
movss 0x94(%rsp), %xmm0
movss %xmm0, (%rax)
movss 0xf0(%rsp), %xmm0
addss 0xf8(%rsp), %xmm0
movss %xmm0, 0xf8(%rsp)
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x320a
movl $0x0, 0xec(%rsp)
movl 0xec(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x3385
movss 0xf8(%rsp), %xmm0
movss %xmm0, 0x88(%rsp)
movslq 0xec(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4700
movss 0x88(%rsp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x3326
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x34f3
cvtsi2ssl 0xfc(%rsp), %xmm0
movss %xmm0, 0x70(%rsp)
movslq 0xe8(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4700
movss 0x70(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
mulss (%rax), %xmm0
movss %xmm0, 0x74(%rsp)
movslq 0x100(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe8(%rsp), %rsi
callq 0x4700
movss 0x74(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
cvtsi2ssl 0xfc(%rsp), %xmm0
movss %xmm0, 0x78(%rsp)
movslq 0xe8(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4700
movss 0x78(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
mulss (%rax), %xmm0
movss %xmm0, 0x7c(%rsp)
addq $0x18, %rdi
movslq 0x110(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe8(%rsp), %rsi
callq 0x4700
movss 0x7c(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
cvtsi2ssl 0xfc(%rsp), %xmm0
movss %xmm0, 0x80(%rsp)
movslq 0xe8(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x4700
movss 0x80(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
mulss (%rax), %xmm0
movss %xmm0, 0x84(%rsp)
addq $0x30, %rdi
movslq 0xe8(%rsp), %rsi
callq 0x4700
movss 0x84(%rsp), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rax)
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x3390
jmp 0x34f5
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x315e
jmp 0x350d
movl 0x110(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x110(%rsp)
jmp 0x313b
xorps %xmm0, %xmm0
movss %xmm0, 0xe4(%rsp)
movl $0x0, 0xe0(%rsp)
movl 0xe0(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x377d
xorps %xmm0, %xmm0
movss %xmm0, 0xdc(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xd8(%rsp)
movl $0x0, 0xd4(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xd4(%rsp), %eax
cmpl 0x60(%rcx), %eax
jge 0x35d3
movq 0xa8(%rsp), %rdi
movslq 0xd4(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x4700
movss (%rax), %xmm0
addss 0xdc(%rsp), %xmm0
movss %xmm0, 0xdc(%rsp)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x3571
movl $0x0, 0xd0(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xd0(%rsp), %eax
cmpl 0x60(%rcx), %eax
jge 0x364b
movq 0xa8(%rsp), %rdi
movss 0xdc(%rsp), %xmm0
movss %xmm0, 0x6c(%rsp)
movslq 0xd0(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x4700
movss 0x6c(%rsp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x35de
movl $0x0, 0xcc(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xcc(%rsp), %eax
cmpl 0x64(%rcx), %eax
jge 0x36bc
movq 0xa8(%rsp), %rdi
addq $0x18, %rdi
movslq 0xcc(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x4700
movss (%rax), %xmm0
addss 0xd8(%rsp), %xmm0
movss %xmm0, 0xd8(%rsp)
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x3656
movl $0x0, 0xc8(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xc8(%rsp), %eax
cmpl 0x64(%rcx), %eax
jge 0x3738
movq 0xa8(%rsp), %rdi
movss 0xd8(%rsp), %xmm0
movss %xmm0, 0x68(%rsp)
addq $0x18, %rdi
movslq 0xc8(%rsp), %rsi
callq 0x46e0
movq %rax, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x4700
movss 0x68(%rsp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x36c7
movq 0xa8(%rsp), %rdi
addq $0x30, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x4700
movss (%rax), %xmm0
addss 0xe4(%rsp), %xmm0
movss %xmm0, 0xe4(%rsp)
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0x353a
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x1c4(%rsp), %eax
jge 0x37e4
movq 0xa8(%rsp), %rdi
cvtsi2ssl 0xd0(%rdi), %xmm0
movss %xmm0, 0x64(%rsp)
addq $0x30, %rdi
movslq 0xc4(%rsp), %rsi
callq 0x4700
movss 0x64(%rsp), %xmm1
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x3788
movq 0xa8(%rsp), %rdi
movss 0x1ac(%rsp), %xmm0
movss %xmm0, 0x1b0(%rsp)
callq 0x4780
movss %xmm0, 0x60(%rsp)
jmp 0x380b
movss 0x60(%rsp), %xmm0
movss %xmm0, 0x1ac(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x4930
leaq 0x140(%rsp), %rdi
callq 0x4990
leaq 0x158(%rsp), %rdi
callq 0x4990
jmp 0x2ea9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x4930
leaq 0x140(%rsp), %rdi
callq 0x4990
leaq 0x158(%rsp), %rdi
callq 0x4990
jmp 0x3a55
movq 0x12743(%rip), %rdi     # 0x15fd0
leaq 0xb7e8(%rip), %rsi      # 0xf07c
callq 0x21d0
movq %rax, 0x58(%rsp)
jmp 0x38a0
movq 0x58(%rsp), %rdi
movq 0x12714(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x38b3
movq 0x12716(%rip), %rdi     # 0x15fd0
leaq 0xb7cc(%rip), %rsi      # 0xf08d
callq 0x21d0
movq %rax, 0x50(%rsp)
jmp 0x38cd
movq 0x50(%rsp), %rdi
movss 0x1ac(%rsp), %xmm0
callq 0x2170
movq %rax, 0x48(%rsp)
jmp 0x38e7
movq 0x48(%rsp), %rdi
movq 0x126cd(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x38fa
movq 0x126cf(%rip), %rdi     # 0x15fd0
leaq 0xb793(%rip), %rsi      # 0xf09b
callq 0x21d0
movq %rax, 0x40(%rsp)
jmp 0x3914
movq 0x40(%rsp), %rdi
movss 0x1b4(%rsp), %xmm0
callq 0x2170
movq %rax, 0x38(%rsp)
jmp 0x392e
movq 0x38(%rsp), %rdi
leaq 0xb768(%rip), %rsi      # 0xf0a2
callq 0x21d0
movq %rax, 0x30(%rsp)
jmp 0x3946
movq 0x30(%rsp), %rdi
movl 0x1a8(%rsp), %esi
callq 0x22d0
movq %rax, 0x28(%rsp)
jmp 0x395e
movq 0x28(%rsp), %rdi
movq 0x12656(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x3971
movq 0x12658(%rip), %rdi     # 0x15fd0
leaq 0xb738(%rip), %rsi      # 0xf0b7
callq 0x21d0
movq %rax, 0x20(%rsp)
jmp 0x398b
callq 0x2150
movq 0x20(%rsp), %rdi
movq 0x170(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0xb65b(%rip), %xmm1     # 0xf008
mulsd %xmm1, %xmm0
callq 0x2300
movq %rax, 0x18(%rsp)
jmp 0x39bd
movq 0x18(%rsp), %rdi
leaq 0xb682(%rip), %rsi      # 0xf04b
callq 0x21d0
movq %rax, 0x10(%rsp)
jmp 0x39d5
movq 0x10(%rsp), %rdi
movq 0x125df(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x39e8
movq 0x125e1(%rip), %rdi     # 0x15fd0
leaq 0xb6cd(%rip), %rsi      # 0xf0c3
callq 0x21d0
movq %rax, 0x8(%rsp)
jmp 0x3a02
movq 0x8(%rsp), %rdi
movl 0x1c4(%rsp), %esi
callq 0x22d0
movq %rax, (%rsp)
jmp 0x3a19
movq (%rsp), %rdi
movq 0x1259c(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x3a2b
movq 0x1259e(%rip), %rdi     # 0x15fd0
movq 0x12587(%rip), %rsi     # 0x15fc0
callq 0x2210
jmp 0x3a40
leaq 0x190(%rsp), %rdi
callq 0x4930
addq $0x1d8, %rsp            # imm = 0x1D8
retq
leaq 0x190(%rsp), %rdi
callq 0x4930
movq 0x180(%rsp), %rdi
callq 0x22e0
nop