// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/algorithm.c
// Function: tune_hyperparameters_of_the_supervised_algorithm
void* tune_hyperparameters_of_the_supervised_algorithm(int algorithm, Instanceptr* traindata, Instanceptr* cvdata, Instanceptr* tunedata, void* parameters)
{
 /*!Last Changed 12.03.2009*/
 Xmldocumentptr doc;
 Xmlelementptr element, child;
 void* bestmodel = NULL;
 void* model;
 int valuecount, i, classno, bestnear;
 Knn_parameterptr pknn;
 C45_parameterptr pc45;
 Multildt_parameterptr pmultildt;
 Logistic_parameterptr plogistic;
 Rbf_parameterptr prbf;
 Mlpparametersptr pmlp;
 Svm_parameterptr psvm;
 Svm_simplex_parameterptr ssvm;
 Randomforest_parameterptr prf;
 Kforest_parameterptr pkf;
 double* posteriors = NULL;
 Instanceptr test, next;
 Prediction predicted;
 double performance, bestperformance, real;
 if (in_list(algorithm, 18, KNN, KNNREG, LOGISTIC, RBF, RBFREG, MLPGENERIC, MLPGENERICREG, DNC, DNCREG, SVM, SIMPLEXSVM, SVMREG, SIMPLEXSVMREG, SVMTREE, MULTIRIPPER, HYBRIDRIPPER, RANDOMFOREST, KFOREST) || (in_list(algorithm, 4, C45, LDT, MULTILDT, OMNILDT) && (get_parameter_l("prunetype") == PREPRUNING)))
  {
   if (get_algorithm_type(algorithm) == CLASSIFICATION)
     posteriors = safemalloc(current_dataset->classno * sizeof(double), "tune_hyperparameters_of_the_supervised_algorithm", 20);   
   doc = xml_document("hyperparameters.xml");
   if (!doc)
    {
     printf(m1428);
     return NULL;
    }
   xml_parse(doc);
   if (in_list(algorithm, 2, KNN, KNNREG))
     element = xml_get_child_with_specific_attribute_value(doc->root, "name", "k");
   else
     if (in_list(algorithm, 4, C45, LDT, MULTILDT, OMNILDT))
       element = xml_get_child_with_specific_attribute_value(doc->root, "name", "pruningthreshold");
     else
       if (in_list(algorithm, 7, LOGISTIC, RBF, RBFREG, MLPGENERIC, MLPGENERICREG, DNC, DNCREG))
         element = xml_get_child_with_specific_attribute_value(doc->root, "name", "learningrate");
       else
         if (in_list(algorithm, 7, SVM, SIMPLEXSVM, SVMREG, SIMPLEXSVMREG, SVMTREE, MULTIRIPPER, HYBRIDRIPPER))
           element = xml_get_child_with_specific_attribute_value(doc->root, "name", "C");
         else
           if (in_list(algorithm, 2, RANDOMFOREST, KFOREST))
             element = xml_get_child_with_specific_attribute_value(doc->root, "name", "featuresize");
           else
            {
             printf(m1451);
             if (get_algorithm_type(algorithm) == CLASSIFICATION)
               return classification_algorithms[algorithm - SELECTMAX].train_algorithm(traindata, cvdata, parameters);
             else
               return regression_algorithms[algorithm - ONEFEATURE].train_algorithm(traindata, cvdata, parameters);
            }
   valuecount = xml_number_of_children(element);
   child = element->child;
   for (i = 0; i < valuecount; i++)
    {
     switch (algorithm){
       case KNN          :
       case KNNREG       :pknn = (Knn_parameterptr) parameters;
                          pknn->nearcount = atoi(child->pcdata);
                          break;
       case C45          :
       case LDT          :
       case SVMTREE      :pc45 = (C45_parameterptr) parameters;
                          pc45->pruningthreshold = atof(child->pcdata);
                          break;
       case MULTILDT     :
       case OMNILDT      :pmultildt = (Multildt_parameterptr) parameters;
                          pmultildt->c45param.pruningthreshold = atof(child->pcdata);
                          break;
       case LOGISTIC     :plogistic = (Logistic_parameterptr) parameters;
                          plogistic->learning_rate = atof(child->pcdata);
                          break;
       case RBF          :
       case RBFREG       :prbf = (Rbf_parameterptr) parameters;
                          prbf->eta = atof(child->pcdata);
                          break;
       case MLPGENERIC   :
       case MLPGENERICREG:
       case DNC          :
       case DNCREG       :pmlp = (Mlpparametersptr) parameters;
                          pmlp->eta = atof(child->pcdata);
                          break;
       case SVM          :
       case SVMREG       :psvm = (Svm_parameterptr) parameters;
                          psvm->C = atof(child->pcdata);
                          break;
       case SIMPLEXSVM   :
       case SIMPLEXSVMREG:ssvm = (Svm_simplex_parameterptr) parameters;
                          ssvm->C = atof(child->pcdata);
                          break;
						 case MULTIRIPPER  :
						 case HYBRIDRIPPER :set_parameter_f("svmC", child->pcdata, -INT_MAX, +INT_MAX);
							                   break;
       case RANDOMFOREST :prf = (Randomforest_parameterptr) parameters;
                          prf->featuresize = atoi(child->pcdata);
                          if (prf->featuresize >= current_dataset->featurecount - 1)
                            continue;
                          break;
       case KFOREST      :pkf = (Kforest_parameterptr) parameters;
                          pkf->featuresize = atoi(child->pcdata);
                          break;
     }
     if (get_algorithm_type(algorithm) == CLASSIFICATION)
       model = classification_algorithms[algorithm - SELECTMAX].train_algorithm(traindata, cvdata, parameters);
     else
       model = regression_algorithms[algorithm - ONEFEATURE].train_algorithm(traindata, cvdata, parameters);
     test = *tunedata;
     performance = 0.0;
     while (test)
      {
       next = test->next;
       test->next = NULL;
       if (get_algorithm_type(algorithm) == CLASSIFICATION)
         predicted = classification_algorithms[algorithm - SELECTMAX].test_algorithm(test, model, parameters, posteriors);
       else
         predicted = regression_algorithms[algorithm - ONEFEATURE].test_algorithm(test, model, parameters, NULL);
       test->next = next;
       if (get_algorithm_type(algorithm) == CLASSIFICATION)
        {
         classno = give_classno(test);
         if (classno != predicted.classno)
           performance++;
        }
       else
        {
         real = give_regressionvalue(test);
         performance += (real - predicted.regvalue) * (real - predicted.regvalue);
        }
       test = test->next;
      }
     if (i == 0 || performance < bestperformance)
      {
       bestperformance = performance;
       write_array_variables("aout", totalrun, 15, "f", atof(child->pcdata));
       if (algorithm == KNN || algorithm == KNNREG)
         bestnear = atoi(child->pcdata);
       if (i != 0)
         free_model_of_supervised_algorithm(algorithm, bestmodel, current_dataset);
       bestmodel = model;
      }
     else
       free_model_of_supervised_algorithm(algorithm, model, current_dataset);
     child = child->sibling;
    }
   if (algorithm == KNN || algorithm == KNNREG)
    {    
     pknn = (Knn_parameterptr) parameters;
     pknn->nearcount = bestnear;    
    }
   xml_free_document(doc);
   if (get_algorithm_type(algorithm) == CLASSIFICATION)
     safe_free(posteriors);
   return bestmodel;
  }
 else
  {
   if (get_algorithm_type(algorithm) == CLASSIFICATION)
     return classification_algorithms[algorithm - SELECTMAX].train_algorithm(traindata, cvdata, parameters);
   else
     return regression_algorithms[algorithm - ONEFEATURE].train_algorithm(traindata, cvdata, parameters);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %rbx
movq %rcx, 0x80(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl %edi, %r12d
movl $0x12, %esi
movl $0x3e9, %edx            # imm = 0x3E9
movl $0x7d1, %ecx            # imm = 0x7D1
movl $0x3f8, %r8d            # imm = 0x3F8
movl $0x402, %r9d            # imm = 0x402
xorl %eax, %eax
pushq $0x40c                  # imm = 0x40C
pushq $0x403                  # imm = 0x403
pushq $0x3f3                  # imm = 0x3F3
pushq $0x3f2                  # imm = 0x3F2
pushq $0x3fb                  # imm = 0x3FB
pushq $0x7d9                  # imm = 0x7D9
pushq $0x7d8                  # imm = 0x7D8
pushq $0x3fa                  # imm = 0x3FA
pushq $0x3f9                  # imm = 0x3F9
pushq $0x7da                  # imm = 0x7DA
pushq $0x3ff                  # imm = 0x3FF
pushq $0x7d3                  # imm = 0x7D3
pushq $0x3f4                  # imm = 0x3F4
pushq $0x7db                  # imm = 0x7DB
callq 0x3aa8c
addq $0x70, %rsp
testl %eax, %eax
je 0x5372
leal -0x3e8(%r12), %r14d
cmpl $0x28, %r14d
ja 0x53ce
leaq 0xd0521(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0xa03db(%rip), %rsi     # 0xa573c
movl $0x14, %edx
callq 0x3a0e1
movq %rax, 0x38(%rsp)
jmp 0x53d7
movl %r12d, %edi
movl $0x4, %esi
movl $0x3ea, %edx            # imm = 0x3EA
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x3f6, %r8d            # imm = 0x3F6
movl $0x3f7, %r9d            # imm = 0x3F7
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x53ab
leaq 0xa0390(%rip), %rdi     # 0xa5732
callq 0x54afc
testl %eax, %eax
je 0x5336
leal -0x3e8(%r12), %eax
cmpl $0x29, %eax
jae 0x5922
movl %eax, %eax
leaq (%rax,%rax,4), %rax
leaq 0xcedf7(%rip), %rcx     # 0xd41c0
jmp 0x5937
movq $0x0, 0x38(%rsp)
leaq 0xa038f(%rip), %rdi     # 0xa576d
callq 0xa36cc
testq %rax, %rax
je 0x541e
movq %rax, 0x48(%rsp)
movq %rax, %rdi
callq 0xa3de1
movl %r12d, %edi
movl $0x2, %esi
movl $0x3e9, %edx            # imm = 0x3E9
movl $0x7d1, %ecx            # imm = 0x7D1
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x5432
leaq 0xab969(%rip), %rdx     # 0xb0d82
jmp 0x5521
leaq 0xa077c(%rip), %rdi     # 0xa5ba1
callq 0x4090
xorl %r13d, %r13d
jmp 0x58f3
movl %r12d, %edi
movl $0x4, %esi
movl $0x3ea, %edx            # imm = 0x3EA
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x3f6, %r8d            # imm = 0x3F6
movl $0x3f7, %r9d            # imm = 0x3F7
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x5467
leaq 0xa031f(%rip), %rdx     # 0xa5781
jmp 0x5521
subq $0x8, %rsp
movl %r12d, %edi
movl $0x7, %esi
movl $0x3f8, %edx            # imm = 0x3F8
movl $0x402, %ecx            # imm = 0x402
movl $0x7db, %r8d            # imm = 0x7DB
movl $0x3f4, %r9d            # imm = 0x3F4
xorl %eax, %eax
pushq $0x7da                  # imm = 0x7DA
pushq $0x3ff                  # imm = 0x3FF
pushq $0x7d3                  # imm = 0x7D3
callq 0x3aa8c
addq $0x20, %rsp
testl %eax, %eax
je 0x54b0
leaq 0xa02e4(%rip), %rdx     # 0xa5792
jmp 0x5521
subq $0x8, %rsp
movl %r12d, %edi
movl $0x7, %esi
movl $0x3f9, %edx            # imm = 0x3F9
movl $0x3fa, %ecx            # imm = 0x3FA
movl $0x7d8, %r8d            # imm = 0x7D8
movl $0x7d9, %r9d            # imm = 0x7D9
xorl %eax, %eax
pushq $0x3f3                  # imm = 0x3F3
pushq $0x3f2                  # imm = 0x3F2
pushq $0x3fb                  # imm = 0x3FB
callq 0x3aa8c
addq $0x20, %rsp
testl %eax, %eax
je 0x54f9
leaq 0xa008e(%rip), %rdx     # 0xa5585
jmp 0x5521
movl %r12d, %edi
movl $0x2, %esi
movl $0x403, %edx            # imm = 0x403
movl $0x40c, %ecx            # imm = 0x40C
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x5908
leaq 0xa027e(%rip), %rdx     # 0xa579f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xa964f(%rip), %rsi     # 0xaeb80
callq 0xa3cda
movq %rax, %r15
movq %rax, %rdi
callq 0xa3c78
movq $0x0, 0x28(%rsp)
movl %eax, 0x44(%rsp)
testl %eax, %eax
jle 0x58be
movq 0x20(%r15), %rax
movq %rax, 0x8(%rsp)
leal -0x7d0(%r12), %eax
cltq
leaq (%rax,%rax,4), %rax
leaq 0xcf2bc(%rip), %rcx     # 0xd4830
leaq (%rcx,%rax,8), %rax
movq %rax, 0x68(%rsp)
movl %r14d, %eax
leaq (%rax,%rax,4), %rax
leaq 0xcec35(%rip), %rcx     # 0xd41c0
leaq (%rcx,%rax,8), %rax
movq %rax, 0x70(%rsp)
leal -0x3e9(%r12), %r15d
leal -0x7d1(%r12), %eax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq %r12, 0x58(%rsp)
movq %r15, 0x78(%rsp)
cmpl $0x23, %r15d
movq %r13, 0x30(%rsp)
ja 0x55e9
leaq 0x9fcb0(%rip), %rcx     # 0xa5278
movslq (%rcx,%r15,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x8(%rbx)
jmp 0x569f
cmpl $0xa, 0x50(%rsp)
ja 0x5694
movq 0x50(%rsp), %rax
leaq 0x9fd08(%rip), %rcx     # 0xa5308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x38(%rbx)
jmp 0x5694
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xa017d(%rip), %rdi     # 0xa57ab
movsd 0x9feda(%rip), %xmm0    # 0xa5510
movsd 0x9feda(%rip), %xmm1    # 0xa5518
callq 0x549e6
jmp 0x569f
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x28(%rbx)
jmp 0x5694
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, (%rbx)
jmp 0x5694
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x30(%rbx)
jmp 0x5694
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x20(%rbx)
movq 0x68(%rsp), %rax
cmpl $0x28, %r14d
ja 0x56a4
movq 0x70(%rsp), %rax
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq *(%rax)
movq %rax, %r13
movq 0x80(%rsp), %rax
movq (%rax), %r12
xorpd %xmm0, %xmm0
testq %r12, %r12
je 0x578d
movsd %xmm0, 0x10(%rsp)
movq 0x10(%r12), %rbp
movq $0x0, 0x10(%r12)
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
cmpl $0x29, %r14d
jae 0x5736
movq 0x38(%rsp), %r8
movq 0x70(%rsp), %rax
callq *0x8(%rax)
movl 0x98(%rsp), %r15d
movq %rbp, 0x10(%r12)
movq %r12, %rdi
callq 0x2f33a
cmpl %r15d, %eax
je 0x577d
movsd 0x10(%rsp), %xmm0
addsd 0x9fdf2(%rip), %xmm0    # 0xa5520
movsd %xmm0, 0x10(%rsp)
jmp 0x577d
xorl %r8d, %r8d
movq 0x68(%rsp), %rax
callq *0x8(%rax)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movq %rbp, 0x10(%r12)
movq %r12, %rdi
callq 0x2f35e
subsd 0x88(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x56d4
jmp 0x5793
movsd %xmm0, 0x10(%rsp)
cmpl $0x0, 0x28(%rsp)
je 0x57c3
movsd 0x60(%rsp), %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x57c3
movq %r13, %rsi
movq 0x30(%rsp), %r13
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x58(%rsp), %r12
jmp 0x582d
leaq 0x3ac856(%rip), %rax    # 0x3b2020
movl (%rax), %r12d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
leaq 0x9ffce(%rip), %rdi     # 0xa57b0
movl %r12d, %esi
movl $0xf, %edx
leaq 0xa2e88(%rip), %rcx     # 0xa8679
movb $0x1, %al
callq 0x33644
movq 0x58(%rsp), %r12
cmpl $0x7d1, %r12d           # imm = 0x7D1
je 0x580f
cmpl $0x3e9, %r12d           # imm = 0x3E9
jne 0x5821
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x40(%rsp)
movq 0x30(%rsp), %rsi
cmpl $0x0, 0x28(%rsp)
je 0x583f
leaq 0xd003c(%rip), %rax     # 0xd5870
movq (%rax), %rdx
movl %r12d, %edi
callq 0x4d38
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x78(%rsp), %r15
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
cmpl 0x44(%rsp), %eax
jne 0x55b6
jmp 0x58c1
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x4(%rbx)
leaq 0xcffe2(%rip), %rcx     # 0xd5870
movq (%rcx), %rcx
movl 0x1bc(%rcx), %ecx
decl %ecx
cmpl %ecx, %eax
jl 0x569f
movq 0x30(%rsp), %r13
jmp 0x585e
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x4(%rbx)
jmp 0x569f
xorl %r13d, %r13d
cmpl $0x7d1, %r12d           # imm = 0x7D1
movq 0x48(%rsp), %rdi
je 0x58d8
cmpl $0x3e9, %r12d           # imm = 0x3E9
jne 0x58de
movl 0x40(%rsp), %eax
movl %eax, (%rbx)
callq 0xa3dc3
cmpl $0x28, %r14d
ja 0x58f3
movq 0x38(%rsp), %rdi
callq 0x3a180
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa02cb(%rip), %rdi     # 0xa5bda
callq 0x4090
cmpl $0x29, %r14d
jae 0x5922
movl %r14d, %eax
jmp 0x53be
addl $0xfffff830, %r12d      # imm = 0xFFFFF830
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
leaq 0xceef9(%rip), %rcx     # 0xd4830
movq (%rcx,%rax,8), %rax
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax