// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x16eb00, %rsp         # imm = 0x16EB00
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movsd 0x7af8b(%rip), %xmm0    # 0xe2010
movsd %xmm0, -0x16e4d8(%rbp)
movl $0x1, -0x16e514(%rbp)
leaq 0x9e7a2(%rip), %rax     # 0x105840
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jne 0x670b3
movl $0x1, -0x16e510(%rbp)
jmp 0x670bd
movl $0x0, -0x16e510(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x16e520(%rbp), %rsi
leaq -0x16e528(%rbp), %rdx
movl $0x5, %ecx
callq 0x45f60
leaq -0x16e528(%rbp), %rdi
leaq -0x16e540(%rbp), %rsi
leaq -0x16e530(%rbp), %rdx
movl $0x5, %ecx
callq 0x45f60
leaq -0x16e530(%rbp), %rdi
leaq -0x16e548(%rbp), %rsi
leaq -0x16e538(%rbp), %rdx
movl $0x5, %ecx
callq 0x45f60
movq -0x16e540(%rbp), %rdi
movl -0x16e510(%rbp), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x44720
movq %rax, -0x16e558(%rbp)
movq %rdx, -0x16e550(%rbp)
movq -0x16e558(%rbp), %rax
movq %rax, -0x16e4f8(%rbp)
movq -0x16e550(%rbp), %rax
movq %rax, -0x16e4f0(%rbp)
movq -0x16e520(%rbp), %rdi
movl -0x16e510(%rbp), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x44720
movq %rax, -0x16e568(%rbp)
movq %rdx, -0x16e560(%rbp)
movq -0x16e568(%rbp), %rax
movq %rax, -0x16e508(%rbp)
movq -0x16e560(%rbp), %rax
movq %rax, -0x16e500(%rbp)
movsd 0x7d6cd(%rip), %xmm0    # 0xe4878
movsd %xmm0, -0x16e4c8(%rbp)
movsd 0x7b885(%rip), %xmm0    # 0xe2a40
ucomisd -0x16e4c8(%rbp), %xmm0
jbe 0x674ba
movl -0xc(%rbp), %eax
movl %eax, -0x16ea2c(%rbp)
testl %eax, %eax
je 0x671f9
jmp 0x671d8
movl -0x16ea2c(%rbp), %eax
subl $0x1, %eax
je 0x67242
jmp 0x671e5
movl -0x16ea2c(%rbp), %eax
subl $0x2, %eax
je 0x67288
jmp 0x672ce
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e600(%rbp), %rdi
leaq -0x16e538(%rbp), %rsi
callq 0x66a50
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e600(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x672d0
movq -0x16e538(%rbp), %rsi
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e698(%rbp), %rdi
callq 0x65f00
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e698(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x672d0
movq -0x16e538(%rbp), %rsi
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e730(%rbp), %rdi
callq 0x66470
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e730(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x672d0
jmp 0x672d0
movq -0x16e4f8(%rbp), %rax
movq %rax, -0x16ea38(%rbp)
movq -0x16e4f0(%rbp), %rax
movq %rax, -0x16ea40(%rbp)
movq %rsp, %rdi
movl $0x13, %ecx
leaq -0x16e4c0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x16ea40(%rbp), %rsi
movq -0x16ea38(%rbp), %rdi
callq 0x61da0
movsd %xmm0, -0x16e4d0(%rbp)
movsd -0x16e4c8(%rbp), %xmm0
movsd 0x7d54f(%rip), %xmm1    # 0xe4878
ucomisd %xmm1, %xmm0
jne 0x67333
jp 0x67333
jmp 0x67355
movsd -0x16e4d0(%rbp), %xmm1
movsd -0x16e4d8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x67355
leaq -0x16e428(%rbp), %rdi
callq 0x63ab0
movsd -0x16e4c8(%rbp), %xmm0
movsd 0x7d513(%rip), %xmm1    # 0xe4878
ucomisd %xmm1, %xmm0
jne 0x6736f
jp 0x6736f
jmp 0x67385
movsd -0x16e4d0(%rbp), %xmm1
movsd -0x16e4d8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x673db
movsd -0x16e4c8(%rbp), %xmm0
movsd %xmm0, -0x16e4e8(%rbp)
movq %rsp, %rdi
movl $0x13, %ecx
leaq -0x16e4c0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x16e7c8(%rbp), %rdi
callq 0x61510
leaq -0x16e428(%rbp), %rdi
leaq -0x16e7c8(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
movsd -0x16e4d0(%rbp), %xmm0
movsd %xmm0, -0x16e4d8(%rbp)
leaq -0x7a150(%rbp), %rdi
movl -0x16e514(%rbp), %edx
leaq 0x7ed84(%rip), %rsi     # 0xe6173
movb $0x0, %al
callq 0x4170
leaq -0xf4270(%rbp), %rdi
movl -0x16e470(%rbp), %edx
leaq 0x85e5b(%rip), %rsi     # 0xed265
movb $0x0, %al
callq 0x4170
leaq -0x7a150(%rbp), %rdi
leaq -0xf4270(%rbp), %rsi
callq 0x493b0
leaq -0x7a150(%rbp), %rdi
movl -0x16e514(%rbp), %edx
leaq 0x7fb52(%rip), %rsi     # 0xe6f8a
movb $0x0, %al
callq 0x4170
leaq -0x16e390(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x53310
leaq -0xf4270(%rbp), %rdi
leaq -0x16e390(%rbp), %rsi
movsd -0x16e4d0(%rbp), %xmm0
movb $0x1, %al
callq 0x4170
leaq -0x7a150(%rbp), %rdi
leaq -0xf4270(%rbp), %rsi
callq 0x493b0
movl -0x16e514(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16e514(%rbp)
leaq -0x16e4c0(%rbp), %rdi
callq 0x63ab0
movsd 0x7b7fb(%rip), %xmm0    # 0xe2ca0
mulsd -0x16e4c8(%rbp), %xmm0
movsd %xmm0, -0x16e4c8(%rbp)
jmp 0x671b3
movl $0x1, -0x16e50c(%rbp)
cmpl $0xc, -0x16e50c(%rbp)
jge 0x677aa
movsd -0x16e4e8(%rbp), %xmm2
movsd 0x7b4d7(%rip), %xmm1    # 0xe29b8
movaps %xmm2, %xmm0
mulsd %xmm1, %xmm0
cvtsi2sdl -0x16e50c(%rbp), %xmm1
mulsd %xmm2, %xmm1
movsd 0x7f9ec(%rip), %xmm2    # 0xe6ee8
mulsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x16e4c8(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x16ea44(%rbp)
testl %eax, %eax
je 0x6753c
jmp 0x6751b
movl -0x16ea44(%rbp), %eax
subl $0x1, %eax
je 0x67585
jmp 0x67528
movl -0x16ea44(%rbp), %eax
subl $0x2, %eax
je 0x675cb
jmp 0x67611
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e860(%rbp), %rdi
leaq -0x16e538(%rbp), %rsi
callq 0x66a50
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e860(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x67613
movq -0x16e538(%rbp), %rsi
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e8f8(%rbp), %rdi
callq 0x65f00
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e8f8(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x67613
movq -0x16e538(%rbp), %rsi
movq -0x16e548(%rbp), %rdx
movsd -0x16e4c8(%rbp), %xmm0
movl -0x1c(%rbp), %ecx
movl -0x16e510(%rbp), %r8d
leaq -0x16e990(%rbp), %rdi
callq 0x66470
leaq -0x16e4c0(%rbp), %rdi
leaq -0x16e990(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
jmp 0x67613
jmp 0x67613
movq -0x16e4f8(%rbp), %rax
movq %rax, -0x16ea50(%rbp)
movq -0x16e4f0(%rbp), %rax
movq %rax, -0x16ea58(%rbp)
movq %rsp, %rdi
movl $0x13, %ecx
leaq -0x16e4c0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x16ea58(%rbp), %rsi
movq -0x16ea50(%rbp), %rdi
callq 0x61da0
movsd %xmm0, -0x16e4d0(%rbp)
movsd -0x16e4d0(%rbp), %xmm1
movsd -0x16e4d8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x676d4
leaq -0x16e428(%rbp), %rdi
callq 0x63ab0
movq %rsp, %rdi
movl $0x13, %ecx
leaq -0x16e4c0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x16ea28(%rbp), %rdi
callq 0x61510
leaq -0x16e428(%rbp), %rdi
leaq -0x16ea28(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
movsd -0x16e4c8(%rbp), %xmm0
movsd %xmm0, -0x16e4e8(%rbp)
movsd -0x16e4d0(%rbp), %xmm0
movsd %xmm0, -0x16e4d8(%rbp)
leaq -0x7a150(%rbp), %rdi
movl -0x16e514(%rbp), %edx
leaq 0x7ea8b(%rip), %rsi     # 0xe6173
movb $0x0, %al
callq 0x4170
leaq -0xf4270(%rbp), %rdi
movl -0x16e470(%rbp), %edx
leaq 0x85b62(%rip), %rsi     # 0xed265
movb $0x0, %al
callq 0x4170
leaq -0x7a150(%rbp), %rdi
leaq -0xf4270(%rbp), %rsi
callq 0x493b0
leaq -0x7a150(%rbp), %rdi
movl -0x16e514(%rbp), %edx
leaq 0x7f859(%rip), %rsi     # 0xe6f8a
movb $0x0, %al
callq 0x4170
leaq -0x16e390(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x53310
leaq -0xf4270(%rbp), %rdi
leaq -0x16e390(%rbp), %rsi
movsd -0x16e4d0(%rbp), %xmm0
movb $0x1, %al
callq 0x4170
leaq -0x7a150(%rbp), %rdi
leaq -0xf4270(%rbp), %rsi
callq 0x493b0
movl -0x16e514(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16e514(%rbp)
leaq -0x16e4c0(%rbp), %rdi
callq 0x63ab0
movl -0x16e50c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16e50c(%rbp)
jmp 0x674c4
movq -0x16e4f8(%rbp), %rdi
movq -0x16e4f0(%rbp), %rsi
callq 0x59ea0
movl -0x16e3d8(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x16e508(%rbp), %rax
movq %rax, -0x16ea60(%rbp)
movq -0x16e500(%rbp), %rax
movq %rax, -0x16ea68(%rbp)
movq %rsp, %rdi
movl $0x13, %ecx
leaq -0x16e428(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x16ea68(%rbp), %rsi
movq -0x16ea60(%rbp), %rdi
callq 0x61da0
movsd %xmm0, -0x16e4e0(%rbp)
leaq -0x16e428(%rbp), %rdi
callq 0x63ab0
movq -0x16e508(%rbp), %rdi
movq -0x16e500(%rbp), %rsi
callq 0x59ea0
movq -0x16e520(%rbp), %rdi
callq 0x44510
movq -0x16e540(%rbp), %rdi
callq 0x44510
movq -0x16e548(%rbp), %rdi
callq 0x44510
movq -0x16e538(%rbp), %rdi
callq 0x44510
movsd -0x16e4e8(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x16e4e0(%rbp), %xmm0
addq $0x16eb00, %rsp         # imm = 0x16EB00
popq %rbp
retq
nopw %cs:(%rax,%rax)