// File: /workspace/github_c_makefile_star2_O2/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 $0x16e3e8, %rsp         # imm = 0x16E3E8
movq %rdx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, (%rsp)
leaq 0x4e310(%rip), %rdi     # 0x98c18
callq 0x4cd35
movl %eax, %ebp
leaq 0x7a1a0(%rsp), %rbx
xorl %r14d, %r14d
movl $0x7a120, %edx          # imm = 0x7A120
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4050
andq $0x0, 0x20(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x2d, (%rbx)
movslq %ebp, %rdi
shlq $0x3, %rdi
leaq 0x4ff24(%rip), %rsi     # 0x9a86a
pushq $0x6
popq %rdx
callq 0x34f59
movq %rax, %r12
leaq 0x4fa34(%rip), %r15     # 0x9a38c
movq %r15, %rdi
callq 0x4ce84
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movupd 0x4ff12(%rip), %xmm0    # 0x9a895
movupd %xmm0, 0x80(%rsp,%rax)
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x3604c
movq %rax, (%r12)
movq %r15, %rdi
callq 0x4ce84
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movabsq $0x2e7261656e696c2f, %rcx # imm = 0x2E7261656E696C2F
movq %rcx, 0x80(%rsp,%rax)
movl $0x747874, 0x88(%rsp,%rax) # imm = 0x747874
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x3604c
movq %rax, 0x8(%r12)
cmpl $0x3, %ebp
jne 0x4aa48
leaq 0x4f99a(%rip), %rdi     # 0x9a38c
callq 0x4ce84
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4270
movq %rbx, %rdi
callq 0x4190
movabsq $0x746172646175712f, %rcx # imm = 0x746172646175712F
movq %rcx, 0x80(%rsp,%rax)
movabsq $0x7478742e636974, %rcx # imm = 0x7478742E636974
movq %rcx, 0x87(%rsp,%rax)
movq 0x10(%r12), %rdi
movq %rbx, %rsi
callq 0x3604c
movq %rax, 0x10(%r12)
testl %ebp, %ebp
movl %ebp, %r13d
cmovlel %r14d, %r13d
leaq 0x50e39(%rip), %rbx     # 0x9b891
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x4aa7e
movq (%r12,%r15,8), %rdi
movq %rbx, %rsi
callq 0x40f0
movq %rax, 0x60(%rsp,%r15,8)
incq %r15
testq %rax, %rax
jne 0x4aa5b
jmp 0x4ad66
movq %r12, 0x48(%rsp)
movl %ebp, 0x38(%rsp)
xorl %ecx, %ecx
leaq 0xf42c0(%rsp), %rbx
movl 0xc(%rsp), %r15d
cmpl $0x5, %ecx
je 0x4ac08
movq %rcx, 0x40(%rsp)
movq (%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
pushq $0x2
popq %rcx
callq 0x2cfe5
movq 0x20(%rsp), %rdi
callq 0x2c3cc
movl %eax, %ebp
movq 0x18(%rsp), %rdi
callq 0x2c3cc
movl %ebp, 0x2c(%rsp)
cmpl $0x2, %ebp
movl %eax, 0x28(%rsp)
jl 0x4ac0d
cmpl $0x2, %eax
jl 0x4ac0d
xorl %ecx, %ecx
cmpl $0x2, %ecx
je 0x4abcf
movl %ecx, 0x3c(%rsp)
testl %ecx, %ecx
movl 0x2c(%rsp), %esi
cmovel %eax, %esi
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
cmoveq %r14, %rdx
cmoveq %rcx, %r14
movq %rdx, 0x30(%rsp)
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x50(%rsp)
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x4abbb
cmpl $0x2, %ebp
movl 0xc(%rsp), %r15d
je 0x4ab5f
cmpl $0x1, %ebp
je 0x4ab53
testl %ebp, %ebp
jne 0x4ab77
movq 0x30(%rsp), %rdi
movl %r15d, %esi
callq 0x8f7c3
jmp 0x4ab74
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
pushq $-0x2
jmp 0x4ab69
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
pushq $-0x3
popq %rdx
movq 0x10(%rsp), %rcx
callq 0x45899
movq %rax, %r12
movq %r12, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x72045
movl %eax, %r15d
movq %rbx, %rdi
xorl %esi, %esi
leaq 0x4e577(%rip), %rdx     # 0x9910b
callq 0x35305
movq 0x60(%rsp,%rbp,8), %rdi
cvtsi2sd %r15d, %xmm0
divsd 0x50(%rsp), %xmm0
movq %rbx, %rsi
movb $0x1, %al
callq 0x42e0
incq %rbp
jmp 0x4ab28
movl 0x3c(%rsp), %ecx
incl %ecx
movl 0xc(%rsp), %r15d
movl 0x28(%rsp), %eax
jmp 0x4aaec
movq (%rsp), %rbp
movq (%rbp), %rdi
movq %r14, %rsi
callq 0x2d2da
movq %rax, (%rbp)
movq 0x30(%rsp), %rsi
movq %rbp, %rdi
callq 0x2c6e4
andq $0x0, 0x20(%rsp)
andq $0x0, 0x18(%rsp)
movq 0x40(%rsp), %rcx
incl %ecx
jmp 0x4aa96
movb $0x1, %r14b
jmp 0x4ac37
cmpl $0x5, 0x40(%rsp)
setae %r14b
movq (%rsp), %rbx
movq (%rbx), %rdi
movq 0x20(%rsp), %rsi
callq 0x2d2da
movq %rax, (%rbx)
movq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x2c6e4
xorl %ebx, %ebx
movl 0x38(%rsp), %ebp
movq 0x48(%rsp), %r12
cmpq %rbx, %r13
je 0x4ac56
movq 0x60(%rsp,%rbx,8), %rdi
callq 0x42a0
incq %rbx
jmp 0x4ac42
testb %r14b, %r14b
je 0x4acf8
leaq 0x4f76b(%rip), %rdi     # 0x9a3d1
callq 0x4cf11
movl %eax, %ebx
subq $0x8, %rsp
pushq $0x9
popq %rsi
pushq $0x3
popq %r14
pushq $0xa
popq %rcx
pushq $0xc
popq %r8
pushq $0xf
popq %r9
movl %eax, %edi
movl %r14d, %edx
movl $0x0, %eax
pushq $0x13
pushq $0x7
pushq $0x6
pushq $0xe
pushq $0x10
callq 0x35812
addq $0x30, %rsp
testl %eax, %eax
movq 0x10(%rsp), %rax
movl 0x3c(%rax), %eax
cmovel %r14d, %ebx
subq $0x8, %rsp
leaq 0x7a1a8(%rsp), %rcx
leaq 0x64(%rsp), %r8
leaq 0x60(%rsp), %r9
movq %r12, %rdi
movl %ebp, %esi
movl %ebx, %edx
pushq %rax
callq 0x81133
popq %rcx
popq %rdx
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x3, %eax
je 0x4ad1f
cmpl $0x2, %eax
je 0x4ad1b
cmpl $0x1, %eax
jne 0x4ad36
movq (%rsp), %rax
movq (%rax), %rdi
movl %r15d, %esi
callq 0x8f7c3
jmp 0x4ad33
movq %r12, %rdi
movl %ebp, %esi
callq 0x34fc3
movq (%rsp), %rax
movq (%rax), %rdi
movl %r15d, %esi
callq 0x8f7c3
movq %rax, %r14
testq %rax, %rax
jne 0x4ad55
jmp 0x4ad63
pushq $-0x2
jmp 0x4ad21
pushq $-0x3
popq %rdx
movq (%rsp), %rdi
movl %r15d, %esi
movq 0x10(%rsp), %rcx
callq 0x45899
movq %rax, %r14
movq %rbx, %rdi
callq 0x34ff7
movq %r12, %rdi
movl %ebp, %esi
callq 0x34fc3
testq %r14, %r14
je 0x4ad63
movl $0x2, 0x40(%r14)
movl 0x28(%rsp), %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x38(%r14)
jmp 0x4ad66
xorl %r14d, %r14d
movq %r14, %rax
addq $0x16e3e8, %rsp         # imm = 0x16E3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq