// File: /workspace/github_c_makefile_star2_O1/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, %r13d
movl %ecx, %r12d
movsd %xmm0, 0xb8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0xc8(%rsp)
leaq 0xc4(%rsp), %rax
movl $0x1, (%rax)
leaq 0x7a410(%rsp), %r15
xorl %ebp, %ebp
movl $0x7a120, %edx          # imm = 0x7A120
movq %r15, %rdi
xorl %esi, %esi
callq 0x4050
movb $0x2d, (%r15)
movq %r12, 0xa0(%rsp)
movslq %r12d, %r15
leaq (,%r15,8), %rdi
leaq 0x609b6(%rip), %rsi     # 0xa738e
movl $0x9, %edx
callq 0x390f5
movq %rax, 0xa8(%rsp)
leaq 0x8be7f(%rip), %rax     # 0xd2870
movq (%rax), %rax
xorl %ecx, %ecx
cmpl %ebp, 0x10(%rax)
sete %cl
movq (%r14), %rsi
movl %ecx, 0x10(%rsp)
movl %ebp, 0x8(%rsp)
movl %ebp, (%rsp)
movl %r13d, %ebp
leaq 0x130(%rsp), %rdi
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdx
movl $0x1, %ecx
movsd 0xb8(%rsp), %xmm0
movl $0x1, %r8d
leaq 0xc4(%rsp), %r9
callq 0x43275
movq %rbx, %rdi
movl %r13d, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, %rsi
testl %r15d, %r15d
jle 0x46d78
movq 0xa0(%rsp), %rax
incl %eax
movq %rax, 0xf8(%rsp)
movl $0x1, %r12d
movq %r14, 0x108(%rsp)
movl %ebp, 0xc0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movl %r12d, 0x178(%rsp)
movl $0x1f4, %edi            # imm = 0x1F4
leaq 0x608e3(%rip), %rsi     # 0xa738e
movl $0xf, %edx
callq 0x390f5
movq %rax, %rbx
movq 0xa8(%rsp), %r15
movq %rax, -0x8(%r15,%r12,8)
leaq 0x608f0(%rip), %rdi     # 0xa73bc
callq 0x5356b
movq %rbx, %rdi
leaq 0x608d7(%rip), %rsi     # 0xa73b2
movq %rax, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x41b0
movq %r12, 0x100(%rsp)
movq -0x8(%r15,%r12,8), %rdi
leaq 0x61da5(%rip), %rsi     # 0xa88a1
callq 0x40f0
testq %rax, %rax
je 0x46e2b
movq %rax, %rcx
movl $0x5, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xb8(%rsp)
movq %r14, %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
movl $0x2, %ecx
callq 0x30746
movq 0xf0(%rsp), %rdi
movl %ebp, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, %r14
movq %rax, 0x118(%rsp)
movq %rdx, %rbx
movq %rdx, 0x120(%rsp)
movq 0xe8(%rsp), %rdi
movl %ebp, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, %r13
movq %rdx, %rbp
leaq 0x1c0(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq 0xd8(%rsp), %r14
movq %r14, %rcx
movq 0xd0(%rsp), %r15
movq %r15, %r8
leaq 0x130(%rsp), %r9
callq 0x42a8b
movl $0x98, %edx
leaq 0x258(%rsp), %r12
movq %r12, %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x4310
movl $0x13, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rdi
movq %r13, 0x110(%rsp)
movq %rbp, %rsi
movq %rbp, %rbx
callq 0x430e0
movsd %xmm0, 0xb0(%rsp)
movq %r12, %rdi
callq 0x442bb
leaq 0x2f0(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
leaq 0x5f548(%rip), %rdx     # 0xa616b
callq 0x39529
movq 0xe0(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movsd 0xb0(%rsp), %xmm0
movb $0x1, %al
callq 0x42e0
leaq 0x1c0(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %r13
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
leaq 0x130(%rsp), %r9
callq 0x42a8b
movl $0x98, %edx
leaq 0x258(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4310
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x118(%rsp), %r15
movq %r15, %rdi
movq 0x120(%rsp), %r14
movq %r14, %rsi
callq 0x430e0
movsd %xmm0, 0xb0(%rsp)
movq %rbx, %rdi
callq 0x442bb
leaq 0x2f0(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
leaq 0x5f498(%rip), %rdx     # 0xa616b
callq 0x39529
movq %rbp, %rdi
movq %rbx, %rsi
movsd 0xb0(%rsp), %xmm0
movb $0x1, %al
callq 0x42e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x3dbad
movq 0x110(%rsp), %rdi
movq %r13, %rsi
movl 0xc0(%rsp), %ebp
movq 0x108(%rsp), %r14
callq 0x3dbad
movq 0xf0(%rsp), %rax
movq %rax, (%r14)
movq 0xe8(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movl 0xb8(%rsp), %eax
decl %eax
jne 0x46b1a
movq 0xe0(%rsp), %rdi
callq 0x42a0
movq 0x100(%rsp), %r12
incq %r12
cmpq 0xf8(%rsp), %r12
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
jne 0x46a97
movl $0x1, (%rsp)
leaq 0x7a410(%rsp), %rcx
leaq 0x1c0(%rsp), %r8
leaq 0x12c(%rsp), %r9
movq %rdx, %r13
movq 0xa8(%rsp), %rdi
movq %rsi, %r12
movq 0xa0(%rsp), %rsi
movl $0xa, %edx
callq 0x8c4bc
movq %rax, %rbx
movq (%r14), %rdi
movl %ebp, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, %r14
movq %rdx, %r15
movl (%rbx), %eax
leaq 0x130(%rsp), %r9
movl %eax, 0x48(%r9)
movq 0xc8(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rcx
movq %r13, %r8
callq 0x42a8b
movq %r12, %rdi
movq %r13, %rsi
callq 0x3dbad
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dbad
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x3915f
movq %rbx, %rdi
callq 0x39194
movq 0xc8(%rsp), %rax
addq $0xf4538, %rsp          # imm = 0xF4538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq