// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/omnivariaterule.c
// Function: find_best_hybrid_condition_crossvalidation
Decisionconditionptr find_best_hybrid_condition_crossvalidation(Instanceptr* growset, int positive, Ripper_parameterptr param)
{
 /*!Last Changed 30.01.2004 added denom == 0 condition*/
 /*!Last Changed 22.01.2004*/
 int hybridspace = get_parameter_i("hybridspace");
 Decisionconditionptr result, condition;
 char **files, st[READLINELENGTH] = "-", pst[READLINELENGTH], buffer[READLINELENGTH];
 Instanceptr train = NULL, test = NULL, traindata, testdata;
 int bestmodel = 0, error, trainsize, testsize, *models, dummy, dummy2, i, j, k, datasize, testtype;
 FILE* errorfiles[3];
 files = safemalloc(hybridspace * sizeof(char *), "find_best_hybrid_ldt_split_crossvalidation", 6); 
 strcpy(buffer, get_parameter_s("tempdirectory"));
 strcat(buffer, "/univariate.txt");
 files[0] = strcopy(files[0], buffer);
 strcpy(buffer, get_parameter_s("tempdirectory"));
 strcat(buffer, "/linear.txt");
 files[1] = strcopy(files[1], buffer);
 if (hybridspace == 3)
  {
   strcpy(buffer, get_parameter_s("tempdirectory"));
   strcat(buffer, "/quadratic.txt");
   files[2] = strcopy(files[2], buffer);
  }
 for (i = 0; i < hybridspace; i++)
  {
   errorfiles[i] = fopen(files[i], "w");
   if (!errorfiles[i])
     return NULL;
  }
 for (i = 0; i < 5; i++)
  {
   divide_instancelist(growset, &train, &test, 2);
   trainsize = data_size(train);
   testsize = data_size(test);
   if (trainsize <= 1 || testsize <= 1)
    {
     *growset = restore_instancelist(*growset, train);
     merge_instancelist(growset, test); 
     bestmodel = 1;
     break;
    }
   for (j = 0; j < 2; j++)
    {
     if (j == 0)
      {
       traindata = train;
       testdata = test;
       datasize = testsize;
      }
     else
      {
       traindata = test;
       testdata = train;
       datasize = trainsize;
      }
     for (k = 0; k < hybridspace; k++)
      {
       switch (k)
        {
         case MODEL_UNI:condition = find_best_condition_for_realized_features(traindata, positive);
                        break;
         case MODEL_LIN:condition = find_best_multivariate_condition(&traindata, positive, MULTIVARIATE_LINEAR, param);
                        break;
         case MODEL_QUA:condition = find_best_multivariate_condition(&traindata, positive, MULTIVARIATE_QUADRATIC, param);
                        break;
        }
       error = return_error_and_free_condition(condition, testdata, positive);
       set_precision(pst, NULL, "\n");
       fprintf(errorfiles[k], pst, error / (datasize + 0.0));
      }
    }
   *growset = restore_instancelist(*growset, testdata);
   merge_instancelist(growset, traindata); 
   train = NULL;
   test = NULL;
  }
 for (i = 0; i < hybridspace; i++)
   fclose(errorfiles[i]);
 if (bestmodel)
  {
   free_2d((void**)files, hybridspace);
   result = find_best_condition_for_realized_features(*growset, positive);
   if (result)
     result->datasize = trainsize + testsize;
   return result;
  }
 testtype = get_parameter_l("testtype");
 if (in_list(testtype, 9, FTEST, PAIREDT5X2, COMBINEDT5X2, PERMUTATIONTEST, PAIREDPERMUTATIONTEST, SIGNTEST, RANKSUMTEST, SIGNEDRANKTEST, NOTEST))
   models = multiple_comparison(files, hybridspace, testtype, st, &dummy, &dummy2, param->correctiontype);
 else
   models = multiple_comparison(files, hybridspace, FTEST, st, &dummy, &dummy2, param->correctiontype);
 switch (models[0])
  {
   case 1:result = find_best_condition_for_realized_features(*growset, positive);
          break;
   case 2:result = find_best_multivariate_condition(growset, positive, MULTIVARIATE_LINEAR, param);
          break;
   case 3:result = find_best_multivariate_condition(growset, positive, MULTIVARIATE_QUADRATIC, param);
          break;
  }
 safe_free(models);
 free_2d((void**)files, hybridspace);
 if (result)
  {
   result->conditiontype = HYBRID_CONDITION;
   result->datasize = trainsize + testsize;
  }
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16e3f8, %rsp         # imm = 0x16E3F8
movq %rdx, 0x28(%rsp)
movl %esi, %ebp
movq %rdi, %r13
leaq 0x54eff(%rip), %rdi     # 0xa5c20
callq 0x5341c
movl %eax, %r15d
leaq 0x7a1b0(%rsp), %rbx
xorl %r14d, %r14d
movl $0x7a120, %edx          # imm = 0x7A120
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4050
movb $0x2d, (%rbx)
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movslq %r15d, %rdi
shlq $0x3, %rdi
leaq 0x56b3c(%rip), %rsi     # 0xa789a
movl $0x6, %edx
callq 0x390f5
movq %rax, %r12
leaq 0x5664a(%rip), %r14     # 0xa73bc
movq %r14, %rdi
callq 0x5356b
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movupd 0x56b28(%rip), %xmm0    # 0xa78c5
movupd %xmm0, 0x90(%rsp,%rax)
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x3a404
movq %rax, (%r12)
movq %r14, %rdi
callq 0x5356b
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movabsq $0x2e7261656e696c2f, %rcx # imm = 0x2E7261656E696C2F
movq %rcx, 0x90(%rsp,%rax)
movl $0x747874, 0x98(%rsp,%rax) # imm = 0x747874
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x3a404
movq %rax, 0x8(%r12)
movl %r15d, 0xc(%rsp)
cmpl $0x3, %r15d
jne 0x50e68
leaq 0x565aa(%rip), %rdi     # 0xa73bc
callq 0x5356b
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movabsq $0x746172646175712f, %rcx # imm = 0x746172646175712F
movq %rcx, 0x90(%rsp,%rax)
movabsq $0x7478742e636974, %rcx # imm = 0x7478742E636974
movq %rcx, 0x97(%rsp,%rax)
movq 0x10(%r12), %rdi
movq %rbx, %rsi
callq 0x3a404
movq %rax, 0x10(%r12)
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq %rcx, 0x30(%rsp)
testl %eax, %eax
jle 0x50ea7
xorl %ebx, %ebx
leaq 0x57a21(%rip), %r14     # 0xa88a1
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
movq %r14, %rsi
callq 0x40f0
movq %rax, 0x70(%rsp,%r15,8)
testq %rax, %rax
je 0x51201
incq %r15
cmpq %r15, 0x30(%rsp)
jne 0x50e83
leaq 0x20(%rsp), %rbx
leaq 0x18(%rsp), %r14
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x2, %ecx
callq 0x30746
movq (%rbx), %rdi
callq 0x2fa14
movl %eax, %ebx
movq (%r14), %rdi
callq 0x2fa14
movl %ebx, 0x14(%rsp)
cmpl $0x2, %ebx
setl %dl
movl %eax, 0x10(%rsp)
cmpl $0x2, %eax
setl %cl
xorl %r15d, %r15d
orb %dl, %cl
jne 0x51098
movq %r12, 0x48(%rsp)
leaq 0xf42d0(%rsp), %rbx
xorl %r15d, %r15d
movl 0x10(%rsp), %eax
movq %r13, 0x50(%rsp)
movl %eax, 0x10(%rsp)
movl %r15d, %eax
movq %rax, 0x40(%rsp)
xorl %edx, %edx
testl %edx, %edx
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rax
movq %rax, %rcx
cmoveq %r12, %rcx
cmoveq %rax, %r12
movq %rcx, 0x38(%rsp)
cmpl $0x0, 0xc(%rsp)
movq %rdx, 0x58(%rsp)
jle 0x50ff5
testl %edx, %edx
movl 0x14(%rsp), %eax
cmovel 0x10(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %r13d, %r13d
cmpl $0x2, %r13d
je 0x50f90
cmpl $0x1, %r13d
je 0x50f82
testl %r13d, %r13d
jne 0x50fa9
movq 0x38(%rsp), %rdi
movl %ebp, %esi
callq 0x9ba01
jmp 0x50fa6
leaq 0x38(%rsp), %rdi
movl %ebp, %esi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
jmp 0x50f9c
leaq 0x38(%rsp), %rdi
movl %ebp, %esi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
movq 0x28(%rsp), %rcx
callq 0x4b5d1
movq %rax, %r14
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x7ae50
movl %eax, %r15d
movq %rbx, %rdi
xorl %esi, %esi
leaq 0x551a6(%rip), %rdx     # 0xa616b
callq 0x39529
movq 0x70(%rsp,%r13,8), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd 0x60(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x42e0
incq %r13
cmpq %r13, 0x30(%rsp)
jne 0x50f63
movq 0x58(%rsp), %rcx
leal 0x1(%rcx), %eax
testl %ecx, %ecx
movl %eax, %edx
je 0x50f1c
movq 0x50(%rsp), %r13
movq (%r13), %rdi
movq %r12, %rsi
callq 0x30ad5
movq %rax, (%r13)
movq 0x38(%rsp), %rsi
movq %r13, %rdi
callq 0x2fd59
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rax
leal 0x1(%rax), %r15d
cmpl $0x5, %r15d
je 0x510b9
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movl $0x2, %ecx
callq 0x30746
movq 0x20(%rsp), %rdi
callq 0x2fa14
movl %eax, %r12d
movq 0x18(%rsp), %rdi
callq 0x2fa14
movl %r12d, 0x14(%rsp)
cmpl $0x2, %r12d
jl 0x51086
cmpl $0x2, %eax
jge 0x50f0e
movl %eax, 0x10(%rsp)
cmpl $0x4, 0x40(%rsp)
setae %r15b
movq 0x48(%rsp), %r12
movq (%r13), %rdi
movq 0x20(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r13)
movq 0x18(%rsp), %rsi
movq %r13, %rdi
callq 0x2fd59
jmp 0x510c7
cmpl $0x4, 0x40(%rsp)
setae %r15b
movq 0x48(%rsp), %r12
movq 0x30(%rsp), %r14
cmpl $0x0, 0xc(%rsp)
jle 0x510e7
xorl %ebx, %ebx
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x42a0
incq %rbx
cmpq %rbx, %r14
jne 0x510d5
testb %r15b, %r15b
je 0x51192
leaq 0x5630a(%rip), %rdi     # 0xa7401
callq 0x535f7
movl %eax, %ebx
subq $0x8, %rsp
movl $0x3, %r14d
movl %eax, %edi
movl $0x9, %esi
movl $0x3, %edx
movl $0xa, %ecx
movl $0xc, %r8d
movl $0xf, %r9d
xorl %eax, %eax
pushq $0x13
pushq $0x7
pushq $0x6
pushq $0xe
pushq $0x10
callq 0x39a80
addq $0x30, %rsp
testl %eax, %eax
movq 0x28(%rsp), %rax
movl 0x3c(%rax), %eax
cmovel %r14d, %ebx
subq $0x8, %rsp
leaq 0x7a1b8(%rsp), %rcx
leaq 0x74(%rsp), %r8
leaq 0x70(%rsp), %r9
movq %r12, %rdi
movl 0x14(%rsp), %esi
movl %ebx, %edx
pushq %rax
callq 0x8c4bc
addq $0x10, %rsp
movq %rax, %r14
movl (%rax), %eax
cmpl $0x3, %eax
je 0x511bf
cmpl $0x2, %eax
je 0x511b3
cmpl $0x1, %eax
jne 0x511d6
movq (%r13), %rdi
movl %ebp, %esi
callq 0x9ba01
jmp 0x511d3
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x3915f
movq (%r13), %rdi
movl %ebp, %esi
callq 0x9ba01
movq %rax, %rbx
testq %rax, %rax
jne 0x511f6
jmp 0x51201
movq %r13, %rdi
movl %ebp, %esi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
jmp 0x511c9
movq %r13, %rdi
movl %ebp, %esi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
movq 0x28(%rsp), %rcx
callq 0x4b5d1
movq %rax, %rbx
movq %r14, %rdi
callq 0x39194
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x3915f
testq %rbx, %rbx
je 0x51201
movl $0x2, 0x40(%rbx)
movl 0x10(%rsp), %eax
addl 0x14(%rsp), %eax
movl %eax, 0x38(%rbx)
movq %rbx, %rax
addq $0x16e3f8, %rsp         # imm = 0x16E3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq