// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movsd %xmm0, 0x8(%rsp)
movl %edx, %ebp
movl %esi, 0x20(%rsp)
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x2fa14
movl %eax, 0x4(%rsp)
leaq 0x8724e(%rip), %rax     # 0xd2870
movq (%rax), %rax
movl 0x1c0(%rax), %r15d
xorl %eax, %eax
leaq 0x10(%rsp), %r12
movq %rax, (%r12)
leaq 0x30(%rsp), %r13
movq %rax, (%r13)
xorl %eax, %eax
callq 0x7aa9e
movq %rax, %r14
movl %ebp, (%rax)
movl $0x1, 0x40(%rax)
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl 0x20(%rsp), %ecx
callq 0x30465
leaq 0x20(%r14), %rdx
movq %r14, %rcx
addq $0x30, %rcx
movq (%r12), %rdi
movq (%r13), %rsi
cmpl 0x4(%rsp), %r15d
jle 0x4b699
leaq 0x1c(%rsp), %r9
movl %ebp, %r8d
movsd 0x8(%rsp), %xmm0
callq 0x4c341
jmp 0x4b6ac
leaq 0x1c(%rsp), %r9
movl %ebp, %r8d
movsd 0x8(%rsp), %xmm0
callq 0x4be42
testl %eax, %eax
je 0x4b796
movl 0x1c(%rsp), %eax
movl %eax, 0x3c(%r14)
movq 0x10(%rsp), %rdi
callq 0x2fa14
movl %eax, %r15d
movq 0x30(%rsp), %rdi
callq 0x2fa14
movl %eax, %r12d
leal (%r12,%r15), %ebx
movl %r15d, %edi
movl %ebx, %esi
callq 0x7adaf
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x4b30f
movl %eax, %ebp
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4b30f
movl %eax, %r13d
movl %eax, 0x4(%rsp)
addl %ebp, %r13d
setne %al
cmpl %ebx, %r13d
setne %cl
testb %al, %cl
jne 0x4b731
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rsi
callq 0x3dbad
movl %ebp, %edi
movl %r13d, %esi
callq 0x7adaf
cvtsi2sd %ebp, %xmm1
movsd 0x8(%rsp), %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
subl %ebp, %r15d
addl %r15d, %r12d
subl 0x4(%rsp), %r12d
movl %r15d, %edi
movl %r12d, %esi
callq 0x7adaf
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x8(%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 0x4b7aa
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rsi
callq 0x3dbad
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rdi
movq %rax, (%rdi)
movq 0x30(%rsp), %rsi
callq 0x2fd59
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq