// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/multivariaterule.c
// Function: find_best_multivariate_condition_lda
Decisionconditionptr find_best_multivariate_condition_lda(Instanceptr* growset, int positive, MULTIVARIATE_TYPE multivariate_type, double variance_explained)
{
 /*!Last Changed 21.09.2004 m number of features, n number of eigenvectors*/
 /*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 09.01.2004*/
 int positivecount, negativecount, posover, negover, newdim, size = data_size(*growset), d = current_dataset->multifeaturecount - 1;
 Instanceptr positives = NULL, negatives = NULL;
 double it, itdot, gainover, gainunder;
 Decisionconditionptr result;
 result = empty_condition();
 result->featureindex = multivariate_type;
 result->conditiontype = MULTIVARIATE_CONDITION;
 divide_instancelist_one_vs_rest(growset, &positives, &negatives, positive);
 if (d < size)
  {
   if (!best_multivariate_split_lda_with_pca(positives, negatives, &(result->w), &(result->w0), multivariate_type, &newdim, variance_explained))
    {
     result->featureindex = -1;
     matrix_free(result->w);
     *growset = positives;
     merge_instancelist(growset, negatives);
     return result;
    }
  }
 else
  {
   if (!best_multivariate_split_lda_with_svd(positives, negatives, &(result->w), &(result->w0), multivariate_type, &newdim, variance_explained))
    {
     result->featureindex = -1;
     matrix_free(result->w);
     *growset = positives;
     merge_instancelist(growset, negatives);
     return result;
    }
  }
 result->freeparam = newdim;
 positivecount = data_size(positives);
 negativecount = data_size(negatives);
 it = information(positivecount, positivecount + negativecount);
 posover = count_multivariate_condition_over_threshold(positives, result);
 negover = count_multivariate_condition_over_threshold(negatives, result);
 if ((posover + negover) == positivecount + negativecount || (posover + negover) == 0)
  {
   result->featureindex = -1;
   matrix_free(result->w);
  }
 itdot = information(posover, posover + negover);
 gainover = posover * (it - itdot);
 itdot = information(positivecount - posover, positivecount - posover + negativecount - negover);
 gainunder = (positivecount - posover) * (it - itdot);
 if (gainover > gainunder)
   result->comparison = '>';
 else
   result->comparison = '<';
 *growset = positives;
 merge_instancelist(growset, negatives);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x10(%rsp)
movl %edx, %ebx
movl %esi, 0x3c(%rsp)
movq %rdi, %rbp
movq (%rdi), %rdi
callq 0x2c3cc
movl %eax, 0x20(%rsp)
leaq 0x87f86(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x1c0(%rax), %r15d
leaq 0x30(%rsp), %r12
andq $0x0, (%r12)
leaq 0x28(%rsp), %r13
andq $0x0, (%r13)
xorl %eax, %eax
callq 0x71cd1
movq %rax, %r14
movl %ebx, 0xc(%rsp)
movl %ebx, (%rax)
movl $0x1, 0x40(%rax)
movq %rbp, 0x40(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl 0x3c(%rsp), %ecx
callq 0x2cd37
leaq 0x20(%r14), %rdx
movq %r14, %rcx
addq $0x30, %rcx
movq (%r12), %rdi
movq (%r13), %rsi
cmpl 0x20(%rsp), %r15d
jle 0x45967
leaq 0x1c(%rsp), %r9
movl 0xc(%rsp), %r8d
movsd 0x10(%rsp), %xmm0
callq 0x465c0
jmp 0x4597c
leaq 0x1c(%rsp), %r9
movl 0xc(%rsp), %r8d
movsd 0x10(%rsp), %xmm0
callq 0x460cb
testl %eax, %eax
je 0x45a60
movl 0x1c(%rsp), %eax
movl %eax, 0x3c(%r14)
movq 0x30(%rsp), %rdi
callq 0x2c3cc
movl %eax, %r15d
movq 0x28(%rsp), %rdi
callq 0x2c3cc
movl %eax, %r12d
leal (%r12,%r15), %ebx
movl %r15d, %edi
movl %ebx, %esi
callq 0x71fae
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x455ec
movl %eax, %ebp
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x455ec
movl %eax, %r13d
movl %eax, 0xc(%rsp)
addl %ebp, %r13d
setne %al
cmpl %ebx, %r13d
setne %cl
testb %al, %cl
jne 0x459fe
orl $-0x1, (%r14)
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rsi
callq 0x3929f
movl %ebp, %edi
movl %r13d, %esi
callq 0x71fae
cvtsi2sd %ebp, %xmm1
movsd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
subl %ebp, %r15d
addl %r15d, %r12d
subl 0xc(%rsp), %r12d
movl %r15d, %edi
movl %r12d, %esi
callq 0x71fae
cvtsi2sd %r15d, %xmm1
movsd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd 0x20(%rsp), %xmm0
ucomisd %xmm2, %xmm0
seta %al
addb %al, %al
orb $0x3c, %al
movb %al, 0x4(%r14)
jmp 0x45a71
orl $-0x1, (%r14)
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rsi
callq 0x3929f
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq 0x28(%rsp), %rsi
callq 0x2c6e4
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq