// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/omnivariaterule.c
// Function: generalization_error_of_ruleset_with_deleted_rules
double generalization_error_of_ruleset_with_deleted_rules(Ruleset set, Instanceptr data, int* deleted, int positive, int modelselectionmethod)
{
 /*!Last Changed 20.02.2005*/
 Instanceptr test = data;
 Decisionruleptr tmp;
 int complexity = 0, i, *poscounts, *negcounts, posuncovered = 0, neguncovered = 0, classno, iscovered, covered;
 double loglikelihood, result;
 tmp = set.start;
 i = 0;
 while (tmp)
  {
   if ((!deleted[i]) && tmp->classno == positive)
     complexity += complexity_of_rule(tmp);
   tmp = tmp->next;
   i++;
  }
 poscounts = safecalloc(i, sizeof(int), "generalization_error_of_ruleset_with_deleted_rules", 14); 
 negcounts = safecalloc(i, sizeof(int), "generalization_error_of_ruleset_with_deleted_rules", 15); 
 while (test)
  {
   classno = give_classno(test);
   tmp = set.start;
   i = 0;
   iscovered = 0;
   while (tmp)
    {
     if (!(deleted[i]) && rule_cover_instance(test, *tmp))
      {
       iscovered = 1;
       if (tmp->classno == classno)
         poscounts[i]++;
       else
         negcounts[i]++;
       break;
      }
     i++;
     tmp = tmp->next;
    }
   if (!iscovered)
    {
     if (classno == positive)
       posuncovered++;
     else
       neguncovered++;
    }
   test = test->next;
  }
 loglikelihood = 0;
 covered = 0;
 for (i = 0; i < set.rulecount; i++)
   if (!(deleted[i]))
    {
     covered += poscounts[i];
     loglikelihood += log_likelihood_for_rule_induction(poscounts[i], negcounts[i]);
    }
 loglikelihood += log_likelihood_for_rule_induction(posuncovered, neguncovered);
 covered += posuncovered;
 switch (modelselectionmethod)
  {
   case MODEL_SELECTION_AIC:result = aic_loglikelihood(loglikelihood, complexity);
                            break;
   case MODEL_SELECTION_BIC:result = bic_loglikelihood(loglikelihood, complexity, covered);
                            break;
  }
 safe_free(poscounts);
 safe_free(negcounts);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, 0x6c(%rsp)
movl %edx, 0x38(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq 0xc0(%rsp), %r12
xorl %ebp, %ebp
testq %r12, %r12
je 0x50f3a
xorl %r13d, %r13d
movq %r12, %r15
cmpl $0x0, (%r14,%r13,4)
jne 0x50f1f
movl 0x38(%rsp), %eax
cmpl %eax, (%r15)
jne 0x50f1f
movq %r15, %rdi
callq 0x7ab90
addl %eax, %ebp
incq %r13
movq 0x30(%r15), %r15
testq %r15, %r15
jne 0x50f05
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x58(%rsp)
movl %r13d, %ebp
jmp 0x50f44
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x59999(%rip), %r15     # 0xaa8e4
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movl $0xe, %ecx
callq 0x3a1fc
movq %rax, 0x78(%rsp)
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movl $0xf, %ecx
callq 0x3a1fc
movq %rax, 0x60(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, %eax
movq %rax, 0x50(%rsp)
movl $0x0, %eax
movq %rax, 0x48(%rsp)
testq %rbx, %rbx
je 0x51059
movq $0x0, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movq %rbx, %rdi
callq 0x2f33a
movl %eax, %r15d
testq %r12, %r12
je 0x51013
xorl %r13d, %r13d
movq %r12, %rbp
cmpl $0x0, (%r14,%r13)
jne 0x51006
movq 0x30(%rbp), %rax
movq %rax, 0x30(%rsp)
movupd (%rbp), %xmm0
movupd 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x7b9ee
testl %eax, %eax
jne 0x51036
movq 0x30(%rbp), %rbp
addq $0x4, %r13
testq %rbp, %rbp
jne 0x50fcc
cmpl 0x38(%rsp), %r15d
jne 0x51028
movq 0x50(%rsp), %rax
incl %eax
movq %rax, 0x50(%rsp)
jmp 0x5104c
movq 0x48(%rsp), %rax
incl %eax
movq %rax, 0x48(%rsp)
jmp 0x5104c
cmpl %r15d, (%rbp)
jne 0x51043
movq 0x78(%rsp), %rax
jmp 0x51048
movq 0x60(%rsp), %rax
incl (%rax,%r13)
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x50fb6
leaq 0xc0(%rsp), %rax
movslq 0x10(%rax), %rbx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
xorpd %xmm1, %xmm1
testq %rbx, %rbx
movq 0x78(%rsp), %r13
jle 0x51102
xorl %r15d, %r15d
movl $0x0, 0x44(%rsp)
cmpl $0x0, (%r14,%r15,4)
jne 0x510fa
movl (%r13,%r15,4), %r12d
movq 0x60(%rsp), %rax
movl (%rax,%r15,4), %ecx
leal (%rcx,%r12), %eax
imull %r12d, %ecx
imull %eax, %ecx
testl %ecx, %ecx
je 0x510e8
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x38(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x39bdc
movsd 0x38(%rsp), %xmm1
mulsd 0x80(%rsp), %xmm0
jmp 0x510ec
xorpd %xmm0, %xmm0
addl 0x44(%rsp), %r12d
addsd %xmm0, %xmm1
movl %r12d, 0x44(%rsp)
incq %r15
cmpq %r15, %rbx
jne 0x5108c
movq 0x50(%rsp), %rbx
movq 0x48(%rsp), %rcx
leal (%rcx,%rbx), %eax
imull %ebx, %ecx
imull %eax, %ecx
testl %ecx, %ecx
je 0x5114e
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd %xmm1, 0x38(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x39bdc
movsd 0x38(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
addsd 0x70(%rsp), %xmm1
movl 0x6c(%rsp), %eax
cmpl $0x2, %eax
je 0x51173
cmpl $0x1, %eax
jne 0x5118e
movapd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x47871
jmp 0x51188
movl 0x44(%rsp), %edi
addl %ebx, %edi
movapd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x47cd7
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
callq 0x3a180
movq 0x60(%rsp), %rdi
callq 0x3a180
movsd 0x38(%rsp), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq