// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/model.c
// Function: mlp_model_selection_bic
Mlpnetwork mlp_model_selection_bic(Instanceptr data, Instanceptr validation, double alpha, int maxhidden, int problemtype)
{
	/*!Last Changed 25.06.2005*/
	/*!Last Changed 25.06.2005*/
 int i, hiddennodes[1] = {1};
	Mlpparameters mlpparams;
	matrix train, cv, hessian, eigenvectors;
	Mlpnetwork neuralnetwork, best;
	double* eigenvalues, d, bicerror, trainerror, besterror = +INT_MAX, loglikelihood;
	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)
				 bicerror = bic_squared_error(trainerror, d, train.row);
			else
  			bicerror = bic_loglikelihood(loglikelihood, d, train.row);
			if (i != 1 && bicerror < besterror)
				 free_mlpnnetwork(&best);
			if (i == 1 || bicerror < besterror)
			 {
					best = copy_of_Mlpnetwork(neuralnetwork);
					besterror = bicerror;
			 }
			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, 0xc0(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0xa8(%rsp)
leaq 0xbc(%rsp), %rax
movl $0x1, (%rax)
movq %rsi, %rdi
movl %r8d, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x3008b
movq %rax, %r15
movq %rbx, %rdi
movl %ebp, %esi
movq %rdx, %rbp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x3008b
movq %rax, 0xe0(%rsp)
movq %rdx, 0xd8(%rsp)
leaq 0x8df74(%rip), %rax     # 0xd5870
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, 0xd0(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
movsd 0xc0(%rsp), %xmm0
movl $0x1, %r8d
leaq 0xbc(%rsp), %r9
callq 0x445fb
movq %rbp, %r14
movl %r13d, 0xb8(%rsp)
testl %r13d, %r13d
jle 0x47c4e
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x5db92(%rip), %xmm0    # 0xa5518
movsd %xmm0, 0xb0(%rsp)
leaq 0x118(%rsp), %rbp
movq %r14, 0xc8(%rsp)
movl %r12d, 0x1f8(%rsp)
leaq 0x240(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %r8
leaq 0x1b0(%rsp), %r9
callq 0x43df7
movl $0x98, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x8de84(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x47a3a
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd0(%rsp), %rdi
callq 0x447a5
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 0x44354
movsd %xmm0, 0xf8(%rsp)
jmp 0x47a7d
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd0(%rsp), %rdi
callq 0x44dad
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 0x44466
movsd %xmm0, 0xf0(%rsp)
leaq 0x108(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x428e9
movq %rax, %rbp
movq 0x108(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x3ed51
testl %ebx, %ebx
jle 0x47ae2
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorpd %xmm3, %xmm3
xorl %ecx, %ecx
movsd 0xc0(%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 0x47ac2
jmp 0x47ae6
xorpd %xmm3, %xmm3
movsd %xmm3, 0xa0(%rsp)
movq %r13, 0x100(%rsp)
leaq 0x8dd72(%rip), %rax     # 0xd5870
movq (%rax), %rax
movl 0x10(%rax), %ebp
movsd 0xe8(%rsp), %xmm0
callq 0x4160
movapd %xmm0, %xmm1
testl %ebp, %ebp
je 0x47b3e
movsd 0xa0(%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x5e1e9(%rip), %xmm0    # 0xa5d18
subsd 0xf8(%rsp), %xmm0
movapd %xmm0, %xmm1
jmp 0x47b71
addsd 0x5e262(%rip), %xmm1    # 0xa5da8
movsd 0xa0(%rsp), %xmm2
mulsd %xmm2, %xmm1
movsd 0xe8(%rsp), %xmm0
addsd %xmm0, %xmm1
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
mulsd 0xf0(%rsp), %xmm1
movq 0xc8(%rsp), %r13
leaq 0x118(%rsp), %rbp
cmpl $0x1, %r12d
movsd %xmm1, 0xa0(%rsp)
je 0x47bb5
movsd 0xb0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x47bb5
movq 0xa8(%rsp), %rdi
callq 0x45646
movsd 0xa0(%rsp), %xmm1
cmpl $0x1, %r12d
je 0x47bca
movsd 0xb0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x47c1d
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 0x43d0c
movl $0x98, %edx
movq 0xa8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %r15
leaq 0x118(%rsp), %rbp
callq 0x4310
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq %rbp, %rdi
callq 0x45646
movq %rbx, %rdi
movq 0x100(%rsp), %rsi
callq 0x3ed51
leal 0x1(%r12), %eax
cmpl 0xb8(%rsp), %r12d
movl %eax, %r12d
movq %r13, %r14
jne 0x4799f
movq %r15, %rdi
movq %r14, %rsi
callq 0x3ed51
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x3ed51
movq 0xa8(%rsp), %rax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq