// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rsi
callq 0x5577a
movq (%r14), %rdi
callq 0xfc81
movq %rbx, %rdi
callq 0x11d5c
movq (%r14), %rdi
callq 0x108c8
movq (%r14), %rdi
movq %rax, 0x30(%rsp)
movq %rax, %rsi
callq 0x10bb9
movq %rax, %r14
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
imull %esi, %esi
callq 0x380d3
movq %rax, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x380d3
movq %rax, 0x18(%rsp)
movq %rdx, %r12
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x380d3
movq %rax, 0x10(%rsp)
movq %rdx, %rbp
xorl %r13d, %r13d
movq %r14, %r15
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jge 0x17f9f
movq (%rsp), %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x10068
movl 0x1c0(%rbx), %ecx
xorl %esi, %esi
testl %ecx, %ecx
cmovlel %esi, %ecx
xorl %edi, %edi
cmpl %edi, %ecx
je 0x17f8b
cmpl 0x1407128(%rbx), %edi
je 0x17f87
movslq %esi, %rsi
movq (%rdx,%rsi,8), %r8
movsd (%r8,%rsi,8), %xmm0
movq (%rbp,%rsi,8), %r8
movsd %xmm0, (%r8,%r13,8)
movq (%r15), %r8
movsd (%r8,%rsi,8), %xmm0
movq (%r12,%rsi,8), %r8
movsd %xmm0, (%r8,%r13,8)
incl %esi
incl %edi
jmp 0x17f4e
movq 0x10(%r15), %r15
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3929f
incq %r13
jmp 0x17f27
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movl 0x1c0(%rbx), %esi
testl %esi, %esi
cmovlel %ecx, %esi
xorpd %xmm4, %xmm4
pushq $0x1
popq %rdi
xorl %r8d, %r8d
cmpl %esi, %r8d
je 0x18044
cmpl 0x1407128(%rbx), %r8d
je 0x1803c
movslq %ecx, %r9
xorpd %xmm0, %xmm0
xorl %r10d, %r10d
movq %rdi, %r11
cmpq %rdx, %r10
je 0x18032
movq %r11, %r15
cmpl %r15d, %eax
jle 0x1802a
movq (%r12,%r9,8), %r13
movsd (%r13,%r10,8), %xmm1
subsd (%r13,%r15,8), %xmm1
mulsd %xmm1, %xmm1
movq (%rbp,%r9,8), %r13
movsd (%r13,%r10,8), %xmm2
movsd (%r13,%r15,8), %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
incq %r15
jmp 0x17fe3
incq %r10
incq %r11
jmp 0x17fdb
maxsd %xmm4, %xmm0
incl %ecx
movapd %xmm0, %xmm4
incl %r8d
jmp 0x17fc0
movq %rbx, %rdi
movsd %xmm4, 0x8(%rsp)
callq 0x11d5c
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3929f
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x3929f
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x3929f
movq %r14, %rdi
callq 0x34ff7
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq (%rsp), %rdi
callq 0x2c010
movl 0x10(%rbx), %ecx
leal -0x1(%rcx), %eax
imull %ecx, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
cvtsi2sd %eax, %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq