// File: /workspace/github_c_makefile_star2_O1/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, 0x70(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%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 0x39a80
addq $0x70, %rsp
testl %eax, %eax
je 0x5381
leal -0x3e8(%r12), %r14d
cmpl $0x28, %r14d
ja 0x53dd
leaq 0xcd512(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9d3cc(%rip), %rsi     # 0xa273c
movl $0x14, %edx
callq 0x390f5
movq %rax, 0x28(%rsp)
jmp 0x53e6
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 0x39a80
testl %eax, %eax
je 0x53ba
leaq 0x9d381(%rip), %rdi     # 0xa2732
callq 0x535f7
testl %eax, %eax
je 0x5345
leal -0x3e8(%r12), %eax
cmpl $0x28, %eax
ja 0x5922
movl %eax, %eax
leaq (%rax,%rax,4), %rax
leaq 0xcbde8(%rip), %rcx     # 0xd11c0
jmp 0x5937
movq $0x0, 0x28(%rsp)
leaq 0x9d380(%rip), %rdi     # 0xa276d
callq 0xa075c
testq %rax, %rax
je 0x542d
movq %rax, 0x38(%rsp)
movq %rax, %rdi
callq 0xa0e78
movl %r12d, %edi
movl $0x2, %esi
movl $0x3e9, %edx            # imm = 0x3E9
movl $0x7d1, %ecx            # imm = 0x7D1
xorl %eax, %eax
callq 0x39a80
testl %eax, %eax
je 0x5441
leaq 0xa88c2(%rip), %rdx     # 0xadcea
jmp 0x5530
leaq 0x9d76d(%rip), %rdi     # 0xa2ba1
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 0x39a80
testl %eax, %eax
je 0x5476
leaq 0x9d310(%rip), %rdx     # 0xa2781
jmp 0x5530
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 0x39a80
addq $0x20, %rsp
testl %eax, %eax
je 0x54bf
leaq 0x9d2d5(%rip), %rdx     # 0xa2792
jmp 0x5530
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 0x39a80
addq $0x20, %rsp
testl %eax, %eax
je 0x5508
leaq 0x9d07f(%rip), %rdx     # 0xa2585
jmp 0x5530
movl %r12d, %edi
movl $0x2, %esi
movl $0x403, %edx            # imm = 0x403
movl $0x40c, %ecx            # imm = 0x40C
xorl %eax, %eax
callq 0x39a80
testl %eax, %eax
je 0x5908
leaq 0x9d26f(%rip), %rdx     # 0xa279f
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xa6574(%rip), %rsi     # 0xabab4
callq 0xa0d71
movq %rax, %r15
movq %rax, %rdi
callq 0xa0d0f
movq $0x0, 0x20(%rsp)
movl %eax, 0x34(%rsp)
testl %eax, %eax
jle 0x58be
leal -0x7d0(%r12), %eax
cmpl $0x29, %r14d
movq 0x20(%r15), %rcx
movq %rcx, (%rsp)
cltq
leaq (%rax,%rax,4), %rax
leaq 0xcc2aa(%rip), %rcx     # 0xd1830
leaq (%rcx,%rax,8), %rdx
movl %r14d, %eax
leaq (%rax,%rax,4), %rax
leaq 0xcbc28(%rip), %rcx     # 0xd11c0
leaq (%rcx,%rax,8), %rax
movq %rdx, 0x80(%rsp)
movq %rax, 0x78(%rsp)
cmovbq %rax, %rdx
movq %rdx, 0x68(%rsp)
leal -0x3e9(%r12), %r15d
leal -0x7d1(%r12), %eax
movq %rax, 0x40(%rsp)
xorl %r13d, %r13d
movq %r12, 0x48(%rsp)
movq %r15, 0x60(%rsp)
cmpl $0x23, %r15d
ja 0x5601
leaq 0x9cc97(%rip), %rcx     # 0xa2278
movslq (%rcx,%r15,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x8(%rbx)
jmp 0x56e9
cmpl $0xa, 0x40(%rsp)
ja 0x56e9
movq 0x40(%rsp), %rax
leaq 0x9ccf0(%rip), %rcx     # 0xa2308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x38(%rbx)
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x9d164(%rip), %rdi     # 0xa27ab
movsd 0x9cec1(%rip), %xmm0    # 0xa2510
movsd 0x9cec1(%rip), %xmm1    # 0xa2518
callq 0x534e2
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x28(%rbx)
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, (%rbx)
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x30(%rbx)
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
movsd %xmm0, 0x20(%rbx)
jmp 0x56e9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x4(%rbx)
leaq 0xcd1ab(%rip), %rcx     # 0xd2870
movq (%rcx), %rcx
movl 0x1bc(%rcx), %ecx
decl %ecx
cmpl %ecx, %eax
jl 0x56e9
jmp 0x58a6
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x4(%rbx)
movq %r13, 0x50(%rsp)
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movq 0x68(%rsp), %rax
callq *(%rax)
movq %rax, %r13
movq 0x70(%rsp), %rax
movq (%rax), %r12
xorpd %xmm0, %xmm0
testq %r12, %r12
je 0x57d9
movsd %xmm0, 0x8(%rsp)
movq 0x10(%r12), %rbp
movq $0x0, 0x10(%r12)
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
cmpl $0x28, %r14d
ja 0x5751
movq 0x28(%rsp), %r8
movq 0x78(%rsp), %rax
jmp 0x575c
xorl %r8d, %r8d
movq 0x80(%rsp), %rax
callq *0x8(%rax)
movsd 0x90(%rsp), %xmm0
movl 0x98(%rsp), %r15d
movq %rbp, 0x10(%r12)
movq %r12, %rdi
cmpl $0x28, %r14d
ja 0x579e
callq 0x2eaca
cmpl %r15d, %eax
je 0x57c9
movsd 0x8(%rsp), %xmm0
addsd 0x9cd8a(%rip), %xmm0    # 0xa2520
movsd %xmm0, 0x8(%rsp)
jmp 0x57c9
movsd %xmm0, 0x88(%rsp)
callq 0x2eaee
subsd 0x88(%rsp), %xmm0
mulsd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x5720
jmp 0x57df
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x580f
movsd 0x58(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
ja 0x580f
movq %r13, %rsi
movq 0x50(%rsp), %r13
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x48(%rsp), %r12
jmp 0x5877
leaq 0x3a980a(%rip), %rax    # 0x3af020
movl (%rax), %r12d
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4130
leaq 0x9cf83(%rip), %rdi     # 0xa27b0
movl %r12d, %esi
movl $0xf, %edx
leaq 0x9fde5(%rip), %rcx     # 0xa5621
movb $0x1, %al
callq 0x32c64
movq 0x48(%rsp), %r12
cmpl $0x7d1, %r12d           # imm = 0x7D1
je 0x585a
cmpl $0x3e9, %r12d           # imm = 0x3E9
jne 0x586b
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4200
movl %eax, 0x30(%rsp)
movq 0x50(%rsp), %rsi
cmpl $0x0, 0x20(%rsp)
je 0x5889
leaq 0xccff2(%rip), %rax     # 0xd2870
movq (%rax), %rdx
movl %r12d, %edi
callq 0x4d52
movq (%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, (%rsp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x60(%rsp), %r15
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
cmpl 0x34(%rsp), %eax
jne 0x55d4
jmp 0x58c1
xorl %r13d, %r13d
cmpl $0x7d1, %r12d           # imm = 0x7D1
movq 0x38(%rsp), %rdi
je 0x58d8
cmpl $0x3e9, %r12d           # imm = 0x3E9
jne 0x58de
movl 0x30(%rsp), %eax
movl %eax, (%rbx)
callq 0xa0e5a
cmpl $0x28, %r14d
ja 0x58f3
movq 0x28(%rsp), %rdi
callq 0x39194
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9d2cb(%rip), %rdi     # 0xa2bda
callq 0x4090
cmpl $0x28, %r14d
ja 0x5922
movl %r14d, %eax
jmp 0x53cd
addl $0xfffff830, %r12d      # imm = 0xFFFFF830
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
leaq 0xcbef9(%rip), %rcx     # 0xd1830
movq (%rcx,%rax,8), %rax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax