// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rdi, 0x28(%rsp)
leaq 0xc1d1f(%rip), %r13     # 0xcd870
movq (%r13), %rax
movl 0x10(%rax), %edi
movl 0x1c0(%rax), %esi
movsd 0x8a262(%rip), %xmm0    # 0x95dc8
callq 0x4dde8
movq %rax, 0x8(%rsp)
movq (%r13), %rax
movl 0x10(%rax), %edx
movl 0x1c0(%rax), %ecx
leaq 0x8a459(%rip), %r14     # 0x95fdd
pushq $0x8
popq %rdi
pushq $0x7
popq %r9
movq %rdi, %rsi
movq %r14, %r8
callq 0x351c3
movq %rax, %r12
movq %r13, %r15
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
pushq $0x6
popq %rdx
movq %r14, %rsi
callq 0x34f59
movq %rax, %r13
movsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r10d, %r10d
xorl %ecx, %ecx
movq %rbx, 0x30(%rsp)
movq (%r15), %rax
movl 0x10(%rax), %esi
cmpl (%rbx), %ecx
jge 0xbdac
movl %ecx, 0x24(%rsp)
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
xorl %edx, %edx
cmpq %rcx, %rdx
je 0xbc15
movl 0x1c0(%rax), %edi
testl %edi, %edi
cmovlel %r10d, %edi
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0xbc10
movq (%r12,%rdx,8), %r9
andq $0x0, (%r9,%r8,8)
incq %r8
jmp 0xbbfd
incq %rdx
jmp 0xbbe9
movq 0x28(%rsp), %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0xbd36
xorl %ebx, %ebx
movslq 0x10(%rax), %rsi
cmpq %rsi, %rbx
jge 0xbc92
movq 0x8(%rsp), %rcx
movq (%rcx,%rbx,8), %rcx
movsd (%rcx), %xmm0
xorl %esi, %esi
movsd %xmm0, (%r13,%rbx,8)
movslq 0x1c0(%rax), %rcx
decq %rcx
cmpq %rcx, %rsi
jge 0xbc8d
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rax
leaq 0x1(%rsi), %r14
movsd 0x8(%rax,%rsi,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbp, %rdi
callq 0x2aea2
mulsd 0x18(%rsp), %xmm0
addsd (%r13,%rbx,8), %xmm0
movq (%r15), %rax
movq %r14, %rsi
jmp 0xbc41
incq %rbx
jmp 0xbc29
movq %r13, %rdi
callq 0x4dd7c
movq (%r15), %rax
xorl %ebx, %ebx
movslq 0x10(%rax), %rsi
cmpq %rsi, %rbx
jge 0xbd2d
movq %rbp, %rdi
callq 0x2b47e
movl %eax, %eax
movsd 0x89862(%rip), %xmm1    # 0x95520
cmpq %rax, %rbx
je 0xbcc7
xorpd %xmm1, %xmm1
subsd (%r13,%rbx,8), %xmm1
movq (%r12,%rbx,8), %rax
movsd (%rax), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
xorl %r14d, %r14d
movsd %xmm1, 0x18(%rsp)
movq (%r15), %rax
movslq 0x1c0(%rax), %rcx
decq %rcx
cmpq %rcx, %r14
jge 0xbd25
movq %rbp, %rdi
movl %r14d, %esi
callq 0x2aea2
movsd 0x18(%rsp), %xmm1
movq (%r12,%rbx,8), %rax
mulsd %xmm1, %xmm0
addsd 0x8(%rax,%r14,8), %xmm0
movsd %xmm0, 0x8(%rax,%r14,8)
incq %r14
jmp 0xbce7
incq %rbx
jmp 0xbc9f
addq $0x10, %rbp
jmp 0xbc1a
testl %esi, %esi
movl $0x0, %r10d
cmovlel %r10d, %esi
xorl %ecx, %ecx
movq 0x30(%rsp), %rbx
cmpq %rsi, %rcx
je 0xbd90
movl 0x1c0(%rax), %edx
testl %edx, %edx
cmovlel %r10d, %edx
xorl %edi, %edi
cmpq %rdi, %rdx
je 0xbd8b
movq (%r12,%rcx,8), %r8
movq 0x8(%rsp), %r9
movq (%r9,%rcx,8), %r9
movsd (%r8,%rdi,8), %xmm0
mulsd 0x10(%rsp), %xmm0
addsd (%r9,%rdi,8), %xmm0
movsd %xmm0, (%r9,%rdi,8)
incq %rdi
jmp 0xbd5c
incq %rcx
jmp 0xbd49
movsd 0x10(%rsp), %xmm0
mulsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x24(%rsp), %ecx
incl %ecx
jmp 0xbbcb
movq %r12, %rdi
callq 0x34fc3
movq %r13, %rdi
callq 0x34ff7
movq 0x8(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq