// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/model.c
// Function: mlp_model_selection_crossvalidation
Mlpnetwork mlp_model_selection_crossvalidation(Instanceptr* data, Instanceptr validation, double alpha, int maxhidden, int problemtype)
{
	/*!Last Changed 26.06.2005*/
	int i, j, hiddennodes[1] = {1}, dummy, *models, dummy2;
	char **files, st[READLINELENGTH] = "-", pst[READLINELENGTH];
	FILE* mlpfile;
	Mlpparameters mlpparams;
	Instanceptr traindata, testdata;
	matrix train, test, cv, whole;
	Mlpnetwork neuralnetwork, best;
	double error;
	files = safemalloc(maxhidden * sizeof(char *), "mlp_model_selection_crossvalidation", 9);
 if (current_dataset->classno == 0)
	  mlpparams = prepare_Mlpparameters(*data, validation, 1, alpha, 1, hiddennodes, 0, 0.0, 0.0, 0, REGRESSION);
 else
   mlpparams = prepare_Mlpparameters(*data, validation, 1, alpha, 1, hiddennodes, 0, 0.0, 0.0, 0, CLASSIFICATION);
	cv = instancelist_to_matrix(validation, problemtype, -1, MULTIVARIATE_LINEAR);
	for (i = 1; i <= maxhidden; i++)
	 {
			mlpparams.hidden[0] = i;
		 files[i - 1] = safemalloc(500 * sizeof(char), "mlp_model_selection_crossvalidation", 15);
			sprintf(files[i - 1], "%s/%d.txt", get_parameter_s("tempdirectory"), i);
			mlpfile = fopen(files[i - 1], "w");
   if (!mlpfile)
     return best;
			for (j = 0; j < 5; j++)
			 {
				 divide_instancelist(data, &traindata, &testdata, 2);
	    train = instancelist_to_matrix(traindata, problemtype, -1, MULTIVARIATE_LINEAR);
	    test = instancelist_to_matrix(testdata, problemtype, -1, MULTIVARIATE_LINEAR);
					neuralnetwork = mlp_network_train_general(train, cv, &mlpparams);
					error = test_mlp_network(neuralnetwork, test);
					free_mlpnnetwork(&neuralnetwork);
			  set_precision(pst, NULL, "\n");
     fprintf(mlpfile, pst, error);
					neuralnetwork = mlp_network_train_general(test, cv, &mlpparams);
					error = test_mlp_network(neuralnetwork, train);
					free_mlpnnetwork(&neuralnetwork);
			  set_precision(pst, NULL, "\n");
     fprintf(mlpfile, pst, error);
					matrix_free(train);
					matrix_free(test);
					*data = traindata;
					merge_instancelist(data, testdata);
			 }
			fclose(mlpfile);
	 }
 models = multiple_comparison(files, maxhidden, PAIREDT5X2, st, &dummy, &dummy2, 1);
	whole = instancelist_to_matrix(*data, problemtype, -1, MULTIVARIATE_LINEAR); 
	mlpparams.hidden[0] = models[0];
	best = mlp_network_train_general(whole, cv, &mlpparams);
	matrix_free(cv);
	matrix_free(whole);
	free_2d((void **)files, maxhidden);
	safe_free(models);
	return best;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf4538, %rsp          # imm = 0xF4538
movl %r8d, %r12d
movl %ecx, %ebp
movsd %xmm0, 0xb8(%rsp)
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, 0xd0(%rsp)
leaq 0x12c(%rsp), %r14
movl $0x1, (%r14)
leaq 0x2f0(%rsp), %r15
movl $0x7a120, %edx          # imm = 0x7A120
movq %r15, %rdi
xorl %esi, %esi
callq 0x4050
movb $0x2d, (%r15)
movslq %ebp, %r15
leaq (,%r15,8), %rdi
leaq 0x5931e(%rip), %rsi     # 0x9a35e
pushq $0x9
popq %rdx
callq 0x34f59
movq %rax, 0xa8(%rsp)
leaq 0x8c819(%rip), %rax     # 0xcd870
movq (%rax), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x10(%rax)
sete %cl
movq %r13, 0xc0(%rsp)
movq (%r13), %rsi
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movl %ecx, 0x10(%rsp)
leaq 0x130(%rsp), %rdi
pushq $0x1
popq %rcx
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdx
movsd 0xb8(%rsp), %xmm0
movl %ecx, %r8d
movq %r14, %r9
callq 0x3df0e
pushq $-0x1
popq %rdx
pushq $-0x2
popq %rcx
movq %rbx, %rdi
movl %r12d, 0xa4(%rsp)
movl %r12d, %esi
callq 0x2c130
movq %rax, 0xe0(%rsp)
testl %r15d, %r15d
movl $0x0, %eax
movl %ebp, 0xcc(%rsp)
cmovgl %ebp, %eax
movq %rdx, 0xd8(%rsp)
incl %eax
movq %rax, 0x100(%rsp)
pushq $0x1
popq %r15
cmpq 0x100(%rsp), %r15
je 0x413b8
movl %r15d, 0x178(%rsp)
movl $0x1f4, %edi            # imm = 0x1F4
leaq 0x5924f(%rip), %rsi     # 0x9a35e
pushq $0xf
popq %rdx
callq 0x34f59
movq %rax, %rbx
movq 0xa8(%rsp), %r14
movq %rax, -0x8(%r14,%r15,8)
leaq 0x5925e(%rip), %rdi     # 0x9a38c
callq 0x4ce84
movq %rbx, %rdi
leaq 0x59245(%rip), %rsi     # 0x9a382
movq %rax, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x41b0
movq %r15, 0x108(%rsp)
movq -0x8(%r14,%r15,8), %rdi
leaq 0x5a733(%rip), %rsi     # 0x9b891
callq 0x40f0
movq %rax, 0xe8(%rsp)
testq %rax, %rax
je 0x41477
pushq $0x5
popq %rbx
subl $0x1, %ebx
jb 0x4139b
movq 0xc0(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
pushq $0x2
popq %rcx
movl %ebx, 0xb8(%rsp)
callq 0x2cfe5
movq 0xf8(%rsp), %rdi
movl 0xa4(%rsp), %r15d
movl %r15d, %esi
pushq $-0x1
popq %r14
movl %r14d, %edx
pushq $-0x2
popq %r12
movl %r12d, %ecx
callq 0x2c130
movq %rax, %r13
movq %rax, 0x118(%rsp)
movq %rdx, %rbx
movq %rdx, 0x120(%rsp)
movq 0xf0(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x2c130
movq %rax, %r12
movq %rdx, %r15
leaq 0x1c0(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq 0xe0(%rsp), %r13
movq %r13, %rcx
movq 0xd8(%rsp), %r14
movq %r14, %r8
leaq 0x130(%rsp), %r9
callq 0x3d931
movl $0x98, %edx
leaq 0x258(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4310
pushq $0x13
popq %rcx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
movq %r12, 0x110(%rsp)
movq %r15, %rsi
callq 0x3dd9a
movsd %xmm0, 0xb0(%rsp)
movq %rbp, %rdi
callq 0x3eeb2
leaq 0x7a410(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x57e7a(%rip), %rdx     # 0x9910b
callq 0x35305
movq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movsd 0xb0(%rsp), %xmm0
movb $0x1, %al
callq 0x42e0
leaq 0x1c0(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r15, %r12
movq %r13, %rcx
movq %r14, %r8
leaq 0x130(%rsp), %r9
callq 0x3d931
movl $0x98, %edx
leaq 0x258(%rsp), %r15
movq %r15, %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4310
pushq $0x13
popq %rcx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x118(%rsp), %r13
movq %r13, %rdi
movq 0x120(%rsp), %r14
movq %r14, %rsi
callq 0x3dd9a
movsd %xmm0, 0xb0(%rsp)
movq %r15, %rdi
callq 0x3eeb2
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x57dd2(%rip), %rdx     # 0x9910b
callq 0x35305
movq %rbx, %rdi
movq %rbp, %rsi
movsd 0xb0(%rsp), %xmm0
movb $0x1, %al
callq 0x42e0
movq %r13, %rdi
movq %r14, %rsi
callq 0x3929f
movq 0x110(%rsp), %rdi
movq %r12, %rsi
callq 0x3929f
movq 0xf8(%rsp), %rax
movq 0xc0(%rsp), %rdi
movq %rax, (%rdi)
movq 0xf0(%rsp), %rsi
callq 0x2c6e4
movl 0xb8(%rsp), %ebx
jmp 0x41177
movq 0xe8(%rsp), %rdi
callq 0x42a0
movq 0x108(%rsp), %r15
incq %r15
jmp 0x410ed
movl $0x1, (%rsp)
pushq $0xa
popq %rdx
leaq 0x2f0(%rsp), %rcx
leaq 0x1c0(%rsp), %r8
leaq 0x128(%rsp), %r9
movq 0xa8(%rsp), %rdi
movl 0xcc(%rsp), %ebp
movl %ebp, %esi
callq 0x81133
movq %rax, %rbx
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
pushq $-0x1
popq %rdx
pushq $-0x2
popq %rcx
movl 0xa4(%rsp), %esi
callq 0x2c130
movq %rax, %r14
movq %rdx, %r15
movl (%rbx), %eax
leaq 0x130(%rsp), %r9
movl %eax, 0x48(%r9)
movq 0xd0(%rsp), %rdi
movq %r14, %rsi
movq 0xe0(%rsp), %r13
movq %r13, %rcx
movq 0xd8(%rsp), %r12
movq %r12, %r8
callq 0x3d931
movq %r13, %rdi
movq %r12, %rsi
callq 0x3929f
movq %r14, %rdi
movq %r15, %rsi
callq 0x3929f
movq 0xa8(%rsp), %rdi
movl %ebp, %esi
callq 0x34fc3
movq %rbx, %rdi
callq 0x34ff7
movq 0xd0(%rsp), %rax
addq $0xf4538, %rsp          # imm = 0xF4538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq