// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/dataset.c
// Function: fisher_discriminant_ratio
double fisher_discriminant_ratio(Datasetptr d)
{
 /* multiclass is handled by one vs one */
 Instanceptr tempinst, traindata, c_means;
 int *c_counts;
 matrix class_mean, class_cov, class_var, fisher_class_feature;
 int i, j, k, f;
 double result = 0, classsum, maxratio; 
 read_from_train_file(d, &traindata);
 realize(traindata);
 exchange_classdefno(d);
 c_counts = find_class_counts(traindata);
 c_means = find_class_means(traindata, c_counts);
 fisher_class_feature = matrix_alloc(d->multifeaturecount - 1, d->classno * d->classno);
 class_mean = matrix_alloc(d->multifeaturecount - 1, d->classno);
 class_var = matrix_alloc(d->multifeaturecount - 1, d->classno);
 tempinst = c_means;
 for (j = 0; j < d->classno; j++)
  {
   class_cov = class_covariance(traindata, j, tempinst);  /*OLCAY DEGISTIRDIM*/
   for (i = 0, f = 0; i < d->multifeaturecount; i++)
    {
     if (i != d->classdefno)
      {
       class_var.values[f][j] = class_cov.values[f][f];
       class_mean.values[f][j] = tempinst->values[f].floatvalue;
       f++;
      }
    }
   tempinst = tempinst->next;
   matrix_free(class_cov);
  }
 maxratio = 0;
 for (i = 0, f = 0;i < d->multifeaturecount; i++)
  {
   if (i != d->classdefno)
    {
     classsum = 0;
     for (j = 0; j < d->classno; j++)
      {
       for (k = j + 1; k < d->classno; k++)
        {
         classsum += (class_mean.values[f][j] - class_mean.values[f][k]) * (class_mean.values[f][j] - class_mean.values[f][k]) / ((class_var.values[f][j] * class_var.values[f][j]) + (class_var.values[f][k] * class_var.values[f][k]));
        }
      }
     if (classsum > maxratio)
      {
       maxratio = classsum;
      }
     f++;
    }
  }
 exchange_classdefno(d);
 matrix_free(fisher_class_feature);
 matrix_free(class_mean);
 matrix_free(class_var);
 safe_free(c_means);
 safe_free(c_counts);
 deallocate(traindata);
 traindata = NULL;
 result = maxratio / (d->classno * (d->classno - 1) / 2);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x5c7af
movq (%r14), %rdi
callq 0x10964
leaq 0x1407128(%rbx), %rdi
leaq 0x1407138(%rbx), %rsi
movq %rdi, (%rsp)
movq %rsi, 0x48(%rsp)
callq 0x395a3
movq (%r14), %rdi
callq 0x115e1
movq (%r14), %rdi
movq %rax, 0x50(%rsp)
movq %rax, %rsi
callq 0x11918
movq %rax, 0x10(%rsp)
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
imull %esi, %esi
callq 0x3c6e5
movq %rax, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x3c6e5
movq %rax, 0x30(%rsp)
movq %rdx, %rbp
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x3c6e5
movq %rax, 0x28(%rsp)
movq %rdx, %r15
movl 0x10(%rbx), %eax
testl %eax, %eax
jle 0x19734
xorl %r14d, %r14d
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x10d5a
movl 0x1c0(%rbx), %ecx
testl %ecx, %ecx
jle 0x19719
movq (%rsp), %rsi
movl (%rsi), %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl %edi, %esi
je 0x19713
movslq %r8d, %r8
movq (%rdx,%r8,8), %r9
movsd (%r9,%r8,8), %xmm0
movq (%r15,%r8,8), %r9
movsd %xmm0, (%r9,%r14,8)
movq (%r13), %r9
movsd (%r9,%r8,8), %xmm0
movq (%rbp,%r8,8), %r9
movsd %xmm0, (%r9,%r14,8)
incl %r8d
incl %edi
cmpl %edi, %ecx
jne 0x196e0
movq 0x10(%r13), %r13
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3dbad
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x196bb
movq %rbx, 0x20(%rsp)
movl 0x1c0(%rbx), %ecx
testl %ecx, %ecx
jle 0x197f4
movq (%rsp), %rdx
movl (%rdx), %ebx
movslq %eax, %rsi
movl %esi, %edi
xorpd %xmm5, %xmm5
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpl %ebx, %r8d
je 0x197e6
testl %eax, %eax
jle 0x197d7
movslq %r9d, %r10
xorpd %xmm0, %xmm0
movl $0x1, %edx
xorl %r14d, %r14d
movq %r14, %r11
incq %r14
cmpq %rsi, %r14
jge 0x197cd
movq (%rbp,%r10,8), %r13
movsd (%r13,%r11,8), %xmm1
movq (%r15,%r10,8), %r12
movsd (%r12,%r11,8), %xmm2
mulsd %xmm2, %xmm2
movq %rdx, %r11
movapd %xmm1, %xmm3
subsd (%r13,%r11,8), %xmm3
mulsd %xmm3, %xmm3
movsd (%r12,%r11,8), %xmm4
mulsd %xmm4, %xmm4
addsd %xmm2, %xmm4
divsd %xmm4, %xmm3
addsd %xmm3, %xmm0
incq %r11
cmpq %r11, %rdi
jne 0x197a0
incq %rdx
cmpq %rdi, %r14
jne 0x19778
jmp 0x197db
xorpd %xmm0, %xmm0
maxsd %xmm5, %xmm0
incl %r9d
movapd %xmm0, %xmm5
incl %r8d
cmpl %ecx, %r8d
jne 0x1975c
jmp 0x197f8
xorpd %xmm5, %xmm5
movsd %xmm5, 0x18(%rsp)
movq (%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x395a3
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3dbad
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x3dbad
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x3dbad
movq 0x10(%rsp), %rdi
callq 0x39194
movq 0x50(%rsp), %rdi
callq 0x39194
movq 0x8(%rsp), %rdi
callq 0x2f616
movq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
leal -0x1(%rax), %ecx
imull %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq