// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/model.c
// Function: mlp_model_selection_aic
Mlpnetwork mlp_model_selection_aic(Instanceptr data, Instanceptr validation, double alpha, int maxhidden, int problemtype)
{
	/*!Last Changed 25.06.2005*/
 int i, hiddennodes[1] = {1};
	Mlpparameters mlpparams;
	matrix train, cv, hessian, eigenvectors;
	Mlpnetwork neuralnetwork, best;
	double* eigenvalues, d, aicerror, loglikelihood, trainerror, besterror = +INT_MAX;
	train = instancelist_to_matrix(data, problemtype, -1, MULTIVARIATE_LINEAR);
	cv = instancelist_to_matrix(validation, problemtype, -1, MULTIVARIATE_LINEAR);
 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);
	for (i = 1; i <= maxhidden; i++)
	 {
			mlpparams.hidden[0] = i;
			neuralnetwork = mlp_network_train_general(train, cv, &mlpparams);
			if (current_dataset->classno == 0)
			 {
     hessian = hessian_matrix_reg(neuralnetwork, data);
					trainerror = test_mlp_network(neuralnetwork, train);
			 }
			else
			 {
     hessian = hessian_matrix_cls(neuralnetwork, data);
			  loglikelihood = log_likelihood_of_mlp_network(neuralnetwork, train);
			 }
   eigenvalues = find_eigenvalues_eigenvectors_symmetric(&eigenvectors, hessian);
			matrix_free(eigenvectors);
			d = number_of_free_parameters_of_hessian(eigenvalues, hessian.row, alpha);
			if (current_dataset->classno == 0)
				 aicerror = aic_squared_error(trainerror, d, train.row);
			else
  			aicerror = aic_loglikelihood(loglikelihood, d);
			if (i != 1 && aicerror < besterror)
				 free_mlpnnetwork(&best);
			if (i == 1 || aicerror < besterror)
			 {
					best = copy_of_Mlpnetwork(neuralnetwork);
					besterror = aicerror;
			 }
			free_mlpnnetwork(&neuralnetwork);
			matrix_free(hessian);
	 }
	matrix_free(train);
	matrix_free(cv);
	return best;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movl %r8d, %ebp
movl %ecx, %r13d
movsd %xmm0, 0xb8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0xa0(%rsp)
leaq 0xb4(%rsp), %rax
movl $0x1, (%rax)
movq %rsi, %rdi
movl %r8d, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, %r15
movq %rbx, %rdi
movl %ebp, %esi
movq %rdx, %rbp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x2f755
movq %rax, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
leaq 0x8c735(%rip), %rax     # 0xd2870
movq (%rax), %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl %ecx, 0x10(%rax)
sete %dl
movl %edx, 0x10(%rsp)
movl %ecx, 0x8(%rsp)
movl %ecx, (%rsp)
leaq 0x1b0(%rsp), %rdi
movl $0x1, %r12d
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r14, 0xc8(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
movsd 0xb8(%rsp), %xmm0
movl $0x1, %r8d
leaq 0xb4(%rsp), %r9
callq 0x43275
movq %rbp, %r14
movl %r13d, 0xb0(%rsp)
testl %r13d, %r13d
jle 0x46457
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x5c353(%rip), %xmm0    # 0xa2518
movsd %xmm0, 0xa8(%rsp)
leaq 0x118(%rsp), %rbp
movq %r14, 0xc0(%rsp)
movl %r12d, 0x1f8(%rsp)
leaq 0x240(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0xd8(%rsp), %rcx
movq 0xd0(%rsp), %r8
leaq 0x1b0(%rsp), %r9
callq 0x42a8b
movl $0x98, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x8c645(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x46279
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %rdi
callq 0x4341f
movq %rax, %rbx
movq %rdx, %r13
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movq %r14, %rsi
callq 0x42fce
movsd %xmm0, 0xf8(%rsp)
jmp 0x462bc
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xc8(%rsp), %rdi
callq 0x43a20
movq %rax, %rbx
movq %rdx, %r13
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movq %r14, %rsi
callq 0x430e0
movsd %xmm0, 0xf0(%rsp)
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x41571
movq %rax, %rbp
movq 0x108(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x3dbad
testl %ebx, %ebx
jle 0x46321
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorpd %xmm3, %xmm3
xorl %ecx, %ecx
movsd 0xb8(%rsp), %xmm2
movsd (%rbp,%rcx,8), %xmm0
movapd %xmm0, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm3
incq %rcx
cmpq %rcx, %rax
jne 0x46301
jmp 0x46325
xorpd %xmm3, %xmm3
movq %r13, 0x100(%rsp)
leaq 0x8c53c(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x46348
subsd 0xf8(%rsp), %xmm3
jmp 0x4637a
addsd 0x5c9b8(%rip), %xmm3    # 0xa2d08
divsd 0xe8(%rsp), %xmm3
movsd 0x5c1bf(%rip), %xmm1    # 0xa2520
movapd %xmm1, %xmm0
subsd %xmm3, %xmm0
addsd %xmm1, %xmm3
divsd %xmm0, %xmm3
mulsd 0xf0(%rsp), %xmm3
movq 0xc0(%rsp), %r13
leaq 0x118(%rsp), %rbp
cmpl $0x1, %r12d
movsd %xmm3, 0xe0(%rsp)
je 0x463be
movsd 0xa8(%rsp), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x463be
movq 0xa0(%rsp), %rdi
callq 0x442bb
movsd 0xe0(%rsp), %xmm3
cmpl $0x1, %r12d
je 0x463d3
movsd 0xa8(%rsp), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x46426
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %r14
leaq 0x240(%rsp), %r15
movq %r15, %rdi
callq 0x42990
movl $0x98, %edx
movq 0xa0(%rsp), %rdi
movq %r15, %rsi
movq %r14, %r15
leaq 0x118(%rsp), %rbp
callq 0x4310
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %rbp, %rdi
callq 0x442bb
movq %rbx, %rdi
movq 0x100(%rsp), %rsi
callq 0x3dbad
leal 0x1(%r12), %eax
cmpl 0xb0(%rsp), %r12d
movl %eax, %r12d
movq %r13, %r14
jne 0x461de
movq %r15, %rdi
movq %r14, %rsi
callq 0x3dbad
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x3dbad
movq 0xa0(%rsp), %rax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq