// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/classification.c
// Function: train_logistic
void* train_logistic(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
 /*!Last Changed 17.04.2005*/
 double** w, **deltaw, *y, diff, eta;
 Instanceptr tmp;
 int i, j, k, cno;
 Logistic_parameterptr param;
 param = (Logistic_parameterptr) parameters;
 w = two_dimensional_initialize(current_dataset->classno, current_dataset->multifeaturecount, 0.01);
 deltaw = (double**) safemalloc_2d(sizeof(double *), sizeof(double), current_dataset->classno, current_dataset->multifeaturecount, "logistic", 7);
 y = safemalloc(current_dataset->classno * sizeof(double), "logistic", 6);
 eta = param->learning_rate;
 for (k = 0; k < param->perceptron_run; k++)
  {
   for (i = 0; i < current_dataset->classno; i++)
     for (j = 0; j < current_dataset->multifeaturecount; j++)
       deltaw[i][j] = 0.0;
   tmp = *trdata;
   while (tmp)
    {
     for (i = 0; i < current_dataset->classno; i++)
      {
       y[i] = w[i][0];
       for (j = 0; j < current_dataset->multifeaturecount - 1; j++)
         y[i] += w[i][j + 1] * real_feature(tmp, j);
      }
     softmax(y, current_dataset->classno);
     for (i = 0; i < current_dataset->classno; i++)
      {
       cno = give_classno(tmp);
       if (cno == i)
         diff = 1.0 - y[i];
       else
         diff = 0.0 - y[i];
       deltaw[i][0] += diff;
       for (j = 0; j < current_dataset->multifeaturecount - 1; j++)
         deltaw[i][j + 1] += diff * real_feature(tmp, j);
      }
     tmp = tmp->next;
    }
   for (i = 0; i < current_dataset->classno; i++)
     for (j = 0; j < current_dataset->multifeaturecount; j++)
       w[i][j] += eta * deltaw[i][j];
   eta *= param->etadecrease;
  }
 free_2d((void**)deltaw, current_dataset->classno);
 safe_free(y);
 return w;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rdi, 0x20(%rsp)
leaq 0xc66e5(%rip), %rbx     # 0xd2870
movq (%rbx), %rax
movl 0x10(%rax), %edi
movl 0x1c0(%rax), %esi
movsd 0x96c21(%rip), %xmm0    # 0xa2dc0
callq 0x545f4
movq %rax, 0x10(%rsp)
movq (%rbx), %rax
movl 0x10(%rax), %edx
movl 0x1c0(%rax), %ecx
leaq 0x96e19(%rip), %r15     # 0xa2fd5
movl $0x8, %edi
movl $0x8, %esi
movq %r15, %r8
movl $0x7, %r9d
callq 0x393b5
movq %rax, %r12
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
movq %r15, %rsi
movl $0x6, %edx
callq 0x390f5
movq %rax, %r13
movq %r14, 0x18(%rsp)
cmpl $0x0, (%r14)
jle 0xc41a
movq 0x18(%rsp), %rax
movsd 0x8(%rax), %xmm1
xorl %r10d, %r10d
movq %r10, 0x28(%rsp)
movsd %xmm1, 0x30(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %r14
testq %r14, %r14
jle 0xc257
movl 0x1c0(%rax), %r15d
movq %r15, %rax
shlq $0x3, %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
testl %r15d, %r15d
jle 0xc24f
movq (%r12,%rbp,8), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x4050
incq %rbp
cmpq %rbp, %r14
jne 0xc23a
movq 0x20(%rsp), %rax
movq (%rax), %rbp
testq %rbp, %rbp
je 0xc3ab
movq (%rbx), %rax
movl 0x10(%rax), %esi
testl %esi, %esi
movq 0x10(%rsp), %rcx
jle 0xc2f0
xorl %r14d, %r14d
movq (%rcx,%r14,8), %rax
movsd (%rax), %xmm0
movsd %xmm0, (%r13,%r14,8)
movq (%rbx), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0xc2e1
xorl %esi, %esi
movq (%rcx,%r14,8), %rax
leaq 0x1(%rsi), %r15
movsd 0x8(%rax,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
callq 0x2e4b6
mulsd 0x8(%rsp), %xmm0
addsd (%r13,%r14,8), %xmm0
movsd %xmm0, (%r13,%r14,8)
movq (%rbx), %rax
movslq 0x1c0(%rax), %rax
decq %rax
movq %r15, %rsi
cmpq %rax, %r15
movq 0x10(%rsp), %rcx
jl 0xc297
incq %r14
movq (%rbx), %rax
movslq 0x10(%rax), %rsi
cmpq %rsi, %r14
jl 0xc27a
movq %r13, %rdi
callq 0x5458c
movq (%rbx), %rax
cmpl $0x0, 0x10(%rax)
jle 0xc3a2
xorl %r14d, %r14d
movq %rbp, %rdi
callq 0x2eaca
movl %eax, %eax
movsd 0x96206(%rip), %xmm1    # 0xa2520
cmpq %rax, %r14
je 0xc323
xorpd %xmm1, %xmm1
subsd (%r13,%r14,8), %xmm1
movq (%r12,%r14,8), %rax
movsd (%rax), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq (%rbx), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0xc38f
xorl %r15d, %r15d
movsd %xmm1, 0x8(%rsp)
movq %rbp, %rdi
movl %r15d, %esi
callq 0x2e4b6
movsd 0x8(%rsp), %xmm1
movq (%r12,%r14,8), %rax
mulsd %xmm1, %xmm0
addsd 0x8(%rax,%r15,8), %xmm0
movsd %xmm0, 0x8(%rax,%r15,8)
leaq 0x1(%r15), %rax
movq (%rbx), %rcx
movslq 0x1c0(%rcx), %rcx
decq %rcx
movq %rax, %r15
cmpq %rcx, %rax
jl 0xc34f
incq %r14
movq (%rbx), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r14
jl 0xc308
movq 0x10(%rbp), %rbp
jmp 0xc25f
movq (%rbx), %rcx
movslq 0x10(%rcx), %rax
testq %rax, %rax
movq 0x10(%rsp), %r9
movsd 0x30(%rsp), %xmm1
movq 0x28(%rsp), %r10
jle 0xc404
movl 0x1c0(%rcx), %ecx
xorl %edx, %edx
testl %ecx, %ecx
jle 0xc3fc
movq (%r12,%rdx,8), %rsi
movq (%r9,%rdx,8), %rdi
xorl %r8d, %r8d
movsd (%rsi,%r8,8), %xmm0
mulsd %xmm1, %xmm0
addsd (%rdi,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rcx
jne 0xc3de
incq %rdx
cmpq %rax, %rdx
jne 0xc3cf
movq 0x18(%rsp), %rax
mulsd 0x10(%rax), %xmm1
incl %r10d
cmpl (%rax), %r10d
jl 0xc20e
movq (%rbx), %rax
movl 0x10(%rax), %esi
movq %r12, %rdi
callq 0x3915f
movq %r13, %rdi
callq 0x39194
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq