// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/model.c
// Function: mlp_model_selection
double mlp_model_selection(Instanceptr* data, MODEL_SELECTION_TYPE modelselectionmethod, int* hiddennodes, int maxhidden, double* bestalpha)
{
	/*!Last Changed 25.06.2005*/
 char varname[MAXLENGTH];
 char varvalue[MAXLENGTH], pst[READLINELENGTH];
	Mlpnetwork best, neuralnetwork;
	double a, alphaerror, besterror = +INT_MAX, result, besta;
	matrix alpha, test;
	int i, problemtype, totalrun = 1;
	Instanceptr testdata, data1, data2, data3, alphavalidation, epochvalidation;
	if (current_dataset->classno == 0)
		 problemtype = REGRESSION;
	else
		 problemtype = CLASSIFICATION;
	divide_instancelist(data, &testdata, &data1, 5);
	divide_instancelist(&data1, &alphavalidation, &data2, 5);
	divide_instancelist(&data2, &epochvalidation, &data3, 5);
	alpha = instancelist_to_matrix(alphavalidation, problemtype, -1, MULTIVARIATE_LINEAR);
	test = instancelist_to_matrix(testdata, problemtype, -1, MULTIVARIATE_LINEAR);
	/*Exponential search*/
	for (a = 0.001; a < 100; a *= 2)
	 {
  	switch (modelselectionmethod)
			 {
			  case MODEL_SELECTION_CV :neuralnetwork = mlp_model_selection_crossvalidation(&data3, epochvalidation, a, maxhidden, problemtype);
				                          break;
	    case MODEL_SELECTION_AIC:neuralnetwork = mlp_model_selection_aic(data3, epochvalidation, a, maxhidden, problemtype);
			  	                        break;
			  case MODEL_SELECTION_BIC:neuralnetwork = mlp_model_selection_bic(data3, epochvalidation, a, maxhidden, problemtype);
				                          break;
     default                 :break;
			 }
			alphaerror = test_mlp_network(neuralnetwork, alpha);
			if (a != 0.001 && alphaerror < besterror)
				 free_mlpnnetwork(&best);
			if (a == 0.001 || alphaerror < besterror)
			 {
					besta = a;
					best = copy_of_Mlpnetwork(neuralnetwork);
					besterror = alphaerror;
			 }
	  sprintf(varname, "aout1[%d]", totalrun);
	  sprintf(varvalue, "%d", neuralnetwork.P.hidden[0]);
  	set_variable(varname, varvalue);
	  sprintf(varname, "aout2[%d]", totalrun);
			set_precision(pst, NULL, NULL);
	  sprintf(varvalue, pst, alphaerror);
  	set_variable(varname, varvalue);
   totalrun++;
			free_mlpnnetwork(&neuralnetwork);
	 }
	/*Linear search*/
	for (i = 1; i < 12; i++)
	 {
		 a = besta / 2 + (i * besta) / 8;
  	switch (modelselectionmethod)
			 {
			  case MODEL_SELECTION_CV :neuralnetwork = mlp_model_selection_crossvalidation(&data3, epochvalidation, a, maxhidden, problemtype);
				                          break;
	    case MODEL_SELECTION_AIC:neuralnetwork = mlp_model_selection_aic(data3, epochvalidation, a, maxhidden, problemtype);
			  	                        break;
			  case MODEL_SELECTION_BIC:neuralnetwork = mlp_model_selection_bic(data3, epochvalidation, a, maxhidden, problemtype);
				                          break;
     default                 :break;
			 }
			alphaerror = test_mlp_network(neuralnetwork, alpha);
			if (alphaerror < besterror)
			 {
	  		free_mlpnnetwork(&best);
					best = copy_of_Mlpnetwork(neuralnetwork);
					besta = a;
					besterror = alphaerror;
			 }
	  sprintf(varname, "aout1[%d]", totalrun);
	  sprintf(varvalue, "%d", neuralnetwork.P.hidden[0]);
   set_variable(varname, varvalue);
	  sprintf(varname, "aout2[%d]", totalrun);
			set_precision(pst, NULL, NULL);
	  sprintf(varvalue, pst, alphaerror);
  	set_variable(varname, varvalue);
   totalrun++;
			free_mlpnnetwork(&neuralnetwork);
	 }
	matrix_free(alpha);
	*hiddennodes = best.P.hidden[0];
	result = test_mlp_network(best, test);
	free_mlpnnetwork(&best);
	matrix_free(test);
	deallocate(testdata);
	deallocate(alphavalidation);
	deallocate(epochvalidation);
	deallocate(data3);
	*bestalpha = besta;
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16e658, %rsp         # imm = 0x16E658
movq %r8, 0x100(%rsp)
movl %ecx, 0x9c(%rsp)
movq %rdx, 0xf8(%rsp)
movl %esi, %r15d
leaq 0x8b9f9(%rip), %rax     # 0xd2870
movq (%rax), %rax
xorl %ebp, %ebp
cmpl $0x0, 0x10(%rax)
sete %bpl
leaq 0x110(%rsp), %rbx
leaq 0x120(%rsp), %r14
movq %rbx, %rsi
movq %r14, %rdx
movl $0x5, %ecx
callq 0x30746
leaq 0x108(%rsp), %r12
leaq 0x118(%rsp), %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl $0x5, %ecx
callq 0x30746
leaq 0xa8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
movq %r13, %rdi
movl $0x5, %ecx
callq 0x30746
movq (%r12), %rdi
movl %ebp, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq (%rbx), %rdi
movl %ebp, 0x98(%rsp)
movl %ebp, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movl $0x1, %r13d
movsd 0x5b5d6(%rip), %xmm0    # 0xa2518
movsd %xmm0, 0xc0(%rsp)
movsd 0x5dd25(%rip), %xmm1    # 0xa4c78
leaq 0x258(%rsp), %r12
leaq 0xf4530(%rsp), %rbx
leaq 0x7a410(%rsp), %r14
cmpl $0x2, %r15d
movsd %xmm1, 0xa0(%rsp)
je 0x46ff8
cmpl $0x1, %r15d
je 0x46fc3
testl %r15d, %r15d
jne 0x4703b
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
leaq 0xb0(%rsp), %rsi
movsd 0xa0(%rsp), %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x46965
jmp 0x4702b
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
movapd %xmm1, %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x460b9
jmp 0x4702b
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
movapd %xmm1, %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x464ca
movl $0x98, %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4310
movl $0x13, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x430e0
movapd %xmm0, %xmm2
movsd 0xa0(%rsp), %xmm0
ucomisd 0x5dc05(%rip), %xmm0    # 0xa4c78
movapd %xmm0, %xmm1
movsd %xmm2, 0xb8(%rsp)
jne 0x47084
jnp 0x470b2
movsd 0xc0(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x470b2
leaq 0x1c0(%rsp), %rdi
callq 0x442bb
movsd 0xb8(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm1
ucomisd 0x5dbbe(%rip), %xmm1    # 0xa4c78
jne 0x470be
jnp 0x470cd
movsd 0xc0(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x47124
movl $0x13, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
callq 0x42990
movl $0x98, %edx
leaq 0x1c0(%rsp), %rdi
movq %rbp, %rsi
callq 0x4310
movsd 0xb8(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd %xmm2, 0xc0(%rsp)
movq %rbx, %rdi
leaq 0x5f475(%rip), %rsi     # 0xa65a3
movl %r13d, %edx
xorl %eax, %eax
callq 0x41b0
movl 0x2a8(%rsp), %edx
movq %r14, %rdi
leaq 0x66a14(%rip), %rsi     # 0xadb5d
xorl %eax, %eax
callq 0x41b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32e47
movq %rbx, %rdi
leaq 0x60265(%rip), %rsi     # 0xa73ca
movl %r13d, %edx
xorl %eax, %eax
callq 0x41b0
leaq 0x2f0(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x39529
movq %r14, %rdi
movq %rbp, %rsi
movsd 0xb8(%rsp), %xmm0
movb $0x1, %al
callq 0x41b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32e47
incl %r13d
movq %r12, %rdi
callq 0x442bb
movsd 0xa0(%rsp), %xmm1
addsd %xmm1, %xmm1
cmpl $0x12, %r13d
jne 0x46f6b
movsd 0x5b352(%rip), %xmm2    # 0xa2520
movl $0x12, %ebp
leaq 0x258(%rsp), %r13
leaq 0xf4530(%rsp), %r14
movsd 0xc8(%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd 0x5bb20(%rip), %xmm0    # 0xa2d18
mulsd %xmm2, %xmm1
mulsd 0x5db3c(%rip), %xmm1    # 0xa4d40
addsd %xmm0, %xmm1
cmpl $0x2, %r15d
movsd %xmm2, 0xb8(%rsp)
movsd %xmm1, 0xe0(%rsp)
je 0x4729e
cmpl $0x1, %r15d
je 0x47269
testl %r15d, %r15d
jne 0x472e1
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %r12
movq %r12, %rdi
leaq 0xb0(%rsp), %rsi
movsd 0xe0(%rsp), %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x46965
jmp 0x472d1
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %r12
movq %r12, %rdi
movapd %xmm1, %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x460b9
jmp 0x472d1
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x128(%rsp), %r12
movq %r12, %rdi
movapd %xmm1, %xmm0
movl 0x9c(%rsp), %ecx
movl 0x98(%rsp), %r8d
callq 0x464ca
movl $0x98, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x4310
movl $0x13, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x430e0
movapd %xmm0, %xmm1
movsd 0xc0(%rsp), %xmm0
movsd %xmm1, 0xa0(%rsp)
ucomisd %xmm1, %xmm0
jbe 0x47390
leaq 0x1c0(%rsp), %rdi
callq 0x442bb
movl $0x13, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %r15d, %ebx
movq %r13, %r15
leaq 0x128(%rsp), %r13
movq %r13, %rdi
callq 0x42990
movl $0x98, %edx
leaq 0x1c0(%rsp), %rdi
movq %r13, %rsi
movq %r15, %r13
movl %ebx, %r15d
callq 0x4310
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movq %r14, %rdi
leaq 0x5f209(%rip), %rsi     # 0xa65a3
movl %ebp, %edx
xorl %eax, %eax
callq 0x41b0
movl 0x2a8(%rsp), %edx
leaq 0x7a410(%rsp), %r12
movq %r12, %rdi
leaq 0x667a1(%rip), %rsi     # 0xadb5d
xorl %eax, %eax
callq 0x41b0
movq %r14, %rdi
movq %r12, %rsi
callq 0x32e47
movq %r14, %rdi
leaq 0x5fff2(%rip), %rsi     # 0xa73ca
movl %ebp, %edx
xorl %eax, %eax
callq 0x41b0
leaq 0x2f0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x39529
movq %r12, %rdi
movq %rbx, %rsi
movsd 0xa0(%rsp), %xmm0
movb $0x1, %al
callq 0x41b0
movq %r14, %rdi
movq %r12, %rsi
callq 0x32e47
incl %ebp
movq %r13, %rdi
callq 0x442bb
movsd 0xb8(%rsp), %xmm2
addsd 0x5b0ef(%rip), %xmm2    # 0xa2520
cmpl $0x1d, %ebp
jne 0x471e3
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x3dbad
leaq 0x1c0(%rsp), %rbx
movl 0x50(%rbx), %eax
movq 0xf8(%rsp), %rcx
movl %eax, (%rcx)
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xf0(%rsp), %r14
movq %r14, %rdi
movq 0xe8(%rsp), %r15
movq %r15, %rsi
callq 0x430e0
movsd %xmm0, 0xa0(%rsp)
movq %rbx, %rdi
callq 0x442bb
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dbad
movq 0x110(%rsp), %rdi
callq 0x2f616
movq 0x108(%rsp), %rdi
callq 0x2f616
movq 0xa8(%rsp), %rdi
callq 0x2f616
movq 0xb0(%rsp), %rdi
callq 0x2f616
movq 0x100(%rsp), %rax
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xa0(%rsp), %xmm0
addq $0x16e658, %rsp         # imm = 0x16E658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq