// File: /workspace/github_c_makefile_star2_O2/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, %ebx
movl %ecx, 0xa8(%rsp)
movsd %xmm0, 0xe0(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0xb0(%rsp)
leaq 0xbc(%rsp), %rax
movl $0x1, (%rax)
pushq $-0x1
popq %r13
pushq $-0x2
popq %rbp
movq %rsi, %rdi
movl %r8d, %esi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x2c130
movq %rax, %r15
movq %rdx, 0xd8(%rsp)
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x2c130
movq %rax, 0xd0(%rsp)
movq %rdx, 0xc8(%rsp)
leaq 0x8cfe4(%rip), %rax     # 0xcd870
movq (%rax), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x10(%rax)
sete %cl
andl $0x0, 0x8(%rsp)
movl %ecx, 0x10(%rsp)
andl $0x0, (%rsp)
leaq 0x118(%rsp), %rdi
pushq $0x1
popq %rbx
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r12, 0xc0(%rsp)
movq %r12, %rsi
movq %r14, %rdx
movl %ebx, %ecx
movsd 0xe0(%rsp), %xmm0
movl %ebx, %r8d
leaq 0xbc(%rsp), %r9
callq 0x3df0e
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xe8(%rsp)
xorl %eax, %eax
movl 0xa8(%rsp), %ecx
testl %ecx, %ecx
cmovgl %ecx, %eax
negl %eax
movq %rax, 0xf8(%rsp)
movsd 0x54c09(%rip), %xmm0    # 0x95518
movsd %xmm0, 0xa8(%rsp)
leaq 0x1a8(%rsp), %r13
movq 0xf8(%rsp), %rax
addl %ebx, %eax
cmpl $0x1, %eax
je 0x40b5f
movq %rbx, 0xa0(%rsp)
movl %ebx, 0x160(%rsp)
leaq 0x240(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0xd8(%rsp), %r12
movq %r12, %rdx
movq 0xd0(%rsp), %rcx
movq 0xc8(%rsp), %r8
leaq 0x118(%rsp), %r9
callq 0x3d931
movl $0x98, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x8cee1(%rip), %rax     # 0xcd870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
movq %r15, %r14
pushq $0x13
popq %r15
movq %r15, %rcx
movq %rsp, %rdi
movq %r13, %rsi
je 0x409e0
rep  movsq (%rsi), %es:(%rdi)
movq 0xc0(%rsp), %rdi
callq 0x3e0b0
movq %rax, %rbp
movq %rdx, %rbx
movq %r15, %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %r12, %rsi
callq 0x3dc9a
movsd %xmm0, 0x100(%rsp)
jmp 0x40a16
rep  movsq (%rsi), %es:(%rdi)
movq 0xc0(%rsp), %rdi
callq 0x3e658
movq %rax, %rbp
movq %rdx, %rbx
movq %r15, %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %r12, %rsi
callq 0x3dd9a
movsd %xmm0, 0xf0(%rsp)
movq %r14, %r15
leaq 0x108(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3c5c1
movq %rax, %r12
movq 0x108(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x3929f
movq %r12, %rdi
movl %ebp, %esi
movsd 0xe0(%rsp), %xmm0
callq 0x4074c
movapd %xmm0, %xmm2
leaq 0x8ce0e(%rip), %rax     # 0xcd870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
movq %rbx, %r14
je 0x40a79
subsd 0x100(%rsp), %xmm2
jmp 0x40aab
addsd 0x55297(%rip), %xmm2    # 0x95d18
divsd 0xe8(%rsp), %xmm2
movsd 0x54a8e(%rip), %xmm1    # 0x95520
movapd %xmm1, %xmm0
subsd %xmm2, %xmm0
addsd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd 0xf0(%rsp), %xmm2
leaq 0x1a8(%rsp), %r13
movq 0xa0(%rsp), %rbx
cmpl $0x1, %ebx
movsd %xmm2, 0xa0(%rsp)
je 0x40aee
movsd 0xa8(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x40aee
movq 0xb0(%rsp), %rdi
callq 0x3eeb2
movsd 0xa0(%rsp), %xmm2
cmpl $0x1, %ebx
je 0x40b02
movsd 0xa8(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x40b45
pushq $0x13
popq %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x240(%rsp), %r12
movq %r12, %rdi
callq 0x3d854
movl $0x98, %edx
movq 0xb0(%rsp), %rdi
movq %r12, %rsi
callq 0x4310
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %r13, %rdi
callq 0x3eeb2
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3929f
incl %ebx
jmp 0x40920
movq %r15, %rdi
movq 0xd8(%rsp), %rsi
callq 0x3929f
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x3929f
movq 0xb0(%rsp), %rax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq