// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movl %ecx, 0x5c(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r13
xorl %r15d, %r15d
leaq 0xa0(%rsp), %rbx
xorl %r12d, %r12d
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x4975b
cmpl $0x0, (%r14,%r15,4)
jne 0x49752
cmpl %ebp, (%rbx)
jne 0x49752
movq %rbx, %rdi
callq 0x70638
addl %eax, %r12d
addq $0x30, %rbx
incq %r15
jmp 0x49734
movl %r12d, 0x48(%rsp)
movl %r15d, %ebx
leaq 0x510aa(%rip), %r15     # 0x9a814
pushq $0x4
popq %r12
pushq $0xe
popq %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, 0x60(%rsp)
pushq $0xf
popq %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x0, 0x4c(%rsp)
testq %r13, %r13
je 0x4984d
movq %r13, %rdi
callq 0x2b47e
movl %eax, %r12d
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r15
movq (%r15), %r15
testq %r15, %r15
je 0x49817
cmpl $0x0, (%r14,%rbx)
jne 0x4980d
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movupd (%r15), %xmm0
movupd 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r13, %rdi
callq 0x71406
testl %eax, %eax
jne 0x49830
addq $0x30, %r15
addq $0x4, %rbx
jmp 0x497c9
cmpl %ebp, %r12d
jne 0x4982a
movq 0x40(%rsp), %rax
incl %eax
movq %rax, 0x40(%rsp)
jmp 0x49844
incl 0x4c(%rsp)
jmp 0x49844
cmpl %r12d, (%r15)
jne 0x4983c
movq 0x60(%rsp), %rax
jmp 0x49841
movq 0x50(%rsp), %rax
incl (%rax,%rbx)
movq 0x10(%r13), %r13
jmp 0x497ab
leaq 0xa0(%rsp), %rax
movl 0x10(%rax), %r12d
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
xorpd %xmm0, %xmm0
xorl %ebp, %ebp
movq 0x60(%rsp), %rbx
cmpq %r13, %r12
je 0x498af
cmpl $0x0, (%r14,%r13,4)
jne 0x498aa
movl (%rbx,%r13,4), %edi
addl %edi, %ebp
movq 0x50(%rsp), %rax
movl (%rax,%r13,4), %esi
movsd %xmm0, 0x38(%rsp)
callq 0x493b4
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
incq %r13
jmp 0x4986e
movq 0x40(%rsp), %r14
movl %r14d, %edi
movl 0x4c(%rsp), %esi
movsd %xmm0, 0x38(%rsp)
callq 0x493b4
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
movl 0x5c(%rsp), %eax
cmpl $0x2, %eax
je 0x498f9
cmpl $0x1, %eax
movl 0x48(%rsp), %eax
jne 0x4990f
cvtsi2sd %eax, %xmm1
callq 0x40bcb
jmp 0x49909
addl %r14d, %ebp
cvtsi2sdl 0x48(%rsp), %xmm1
movl %ebp, %edi
callq 0x40fa5
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
callq 0x34ff7
movq 0x50(%rsp), %rdi
callq 0x34ff7
movsd 0x40(%rsp), %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq