// File: lipiji[P]PG_DEEP/deep.cpp
// Function: LR::train(double*, int*, double)
void LR::train(double *x, int *y, double gamma)
{
    double *h_theta_x = new double[n_labels];
    double *dy = new double[n_labels];

    for(int i=0; i<n_labels; i++) 
    {
        h_theta_x[i] = 0;
        for(int j=0; j<n_features; j++) 
        {
            h_theta_x[i] += W[i][j] * x[j];
        }
        h_theta_x[i] += b[i];
    }
    softmax(h_theta_x);

    for(int i=0; i<n_labels; i++) 
    {
        dy[i] = (y[i]==1 ? 1:0) - h_theta_x[i];

        for(int j=0; j<n_features; j++) 
        {
            W[i][j] -= gamma * (-1*dy[i] * x[j] + lamda * W[i][j]);
        }

        b[i] += gamma * dy[i];
    }
    delete[] h_theta_x;
    delete[] dy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x28(%rbp)
movslq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x48(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x6a20
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x69ef
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6998
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6971
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6ba0
movl $0x0, -0x3c(%rbp)
movq -0x48(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x6b63
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x6b25
movq -0x48(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movq -0x30(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movsd 0x460e(%rip), %xmm2     # 0xb0b8
mulsd (%rcx,%rdx,8), %xmm2
movq -0x10(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm3
movsd 0x10(%rax), %xmm1
movq 0x18(%rax), %rcx
movslq -0x3c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x40(%rbp), %rdx
mulsd (%rcx,%rdx,8), %xmm1
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x6a81
movq -0x48(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movq -0x30(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm2
movq 0x20(%rax), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6a34
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x6b7a
movq -0x50(%rbp), %rdi
callq 0x22e0
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x6b91
movq -0x58(%rbp), %rdi
callq 0x22e0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)