// File: /workspace/github_c_makefile_star2_O1/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), %r15
xorl %r12d, %r12d
testq %r15, %r15
je 0x4fa32
xorl %ebp, %ebp
cmpl $0x0, (%r14,%rbp,4)
jne 0x4fa16
movl 0x38(%rsp), %eax
cmpl %eax, (%r15)
jne 0x4fa16
movq %r15, %rdi
callq 0x79250
addl %eax, %r12d
incq %rbp
movq 0x30(%r15), %r15
testq %r15, %r15
jne 0x4f9fb
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x58(%rsp)
movl %ebp, %r12d
jmp 0x4fa3c
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x57e01(%rip), %r15     # 0xa7844
movl $0x4, %esi
movq %r12, %rdi
movq %r15, %rdx
movl $0xe, %ecx
callq 0x39210
movq %rax, 0x78(%rsp)
movl $0x4, %esi
movq %r12, %rdi
movq %r15, %rdx
movl $0xf, %ecx
callq 0x39210
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 0x4fb61
leaq 0xc0(%rsp), %rax
movq (%rax), %r13
movq $0x0, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movq %rbx, %rdi
callq 0x2eaca
movl %eax, %r15d
testq %r13, %r13
je 0x4fb1c
xorl %ebp, %ebp
movq %r13, %r12
cmpl $0x0, (%r14,%rbp)
jne 0x4fb0e
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movupd (%r12), %xmm0
movupd 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x7a0fc
testl %eax, %eax
jne 0x4fb3f
movq 0x30(%r12), %r12
addq $0x4, %rbp
testq %r12, %r12
jne 0x4face
cmpl 0x38(%rsp), %r15d
jne 0x4fb31
movq 0x50(%rsp), %rax
incl %eax
movq %rax, 0x50(%rsp)
jmp 0x4fb54
movq 0x48(%rsp), %rax
incl %eax
movq %rax, 0x48(%rsp)
jmp 0x4fb54
cmpl %r15d, (%r12)
jne 0x4fb4c
movq 0x78(%rsp), %rax
jmp 0x4fb51
movq 0x60(%rsp), %rax
incl (%rax,%rbp)
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x4fab9
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 0x4fc0a
xorl %r15d, %r15d
movl $0x0, 0x44(%rsp)
cmpl $0x0, (%r14,%r15,4)
jne 0x4fc02
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 0x4fbf0
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x38(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x38e99
movsd 0x38(%rsp), %xmm1
mulsd 0x80(%rsp), %xmm0
jmp 0x4fbf4
xorpd %xmm0, %xmm0
addl 0x44(%rsp), %r12d
addsd %xmm0, %xmm1
movl %r12d, 0x44(%rsp)
incq %r15
cmpq %r15, %rbx
jne 0x4fb94
movq 0x50(%rsp), %rbx
movq 0x48(%rsp), %rcx
leal (%rcx,%rbx), %eax
imull %ebx, %ecx
imull %eax, %ecx
testl %ecx, %ecx
je 0x4fc56
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd %xmm1, 0x38(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x38e99
movsd 0x38(%rsp), %xmm1
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
addsd 0x70(%rsp), %xmm1
movl 0x6c(%rsp), %eax
cmpl $0x2, %eax
je 0x4fc7b
cmpl $0x1, %eax
jne 0x4fc96
movapd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x464c1
jmp 0x4fc90
movl 0x44(%rsp), %edi
addl %ebx, %edi
movapd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x46930
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
callq 0x39194
movq 0x60(%rsp), %rdi
callq 0x39194
movsd 0x38(%rsp), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq