// File: /workspace/github_c_makefile_star2_O1/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, 0xc8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0xa8(%rsp)
leaq 0xc4(%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, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
leaq 0x8c324(%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, 0xd8(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
movsd 0xc8(%rsp), %xmm0
movl $0x1, %r8d
leaq 0xc4(%rsp), %r9
callq 0x43275
movq %rbp, %r14
movl %r13d, 0xc0(%rsp)
testl %r13d, %r13d
jle 0x468a7
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0x5bf42(%rip), %xmm0    # 0xa2518
movsd %xmm0, 0xb8(%rsp)
leaq 0x118(%rsp), %rbp
movq %r14, 0xd0(%rsp)
movl %r12d, 0x1f8(%rsp)
leaq 0x240(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq 0xe8(%rsp), %rcx
movq 0xe0(%rsp), %r8
leaq 0x1b0(%rsp), %r9
callq 0x42a8b
movl $0x98, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x8c234(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x4668a
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd8(%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 0x466cd
movl $0x13, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0xd8(%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 0x46732
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorpd %xmm3, %xmm3
xorl %ecx, %ecx
movsd 0xc8(%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 0x46712
jmp 0x46736
xorpd %xmm3, %xmm3
movsd %xmm3, 0xa0(%rsp)
movq %r13, 0x100(%rsp)
leaq 0x8c122(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x46785
movsd 0xb0(%rsp), %xmm0
callq 0x4160
movsd 0xa0(%rsp), %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5c59e(%rip), %xmm1    # 0xa2d18
subsd 0xf8(%rsp), %xmm1
jmp 0x467ca
movsd 0xb0(%rsp), %xmm0
callq 0x4160
movapd %xmm0, %xmm1
addsd 0x5c609(%rip), %xmm1    # 0xa2da8
movsd 0xa0(%rsp), %xmm2
mulsd %xmm2, %xmm1
movsd 0xb0(%rsp), %xmm0
addsd %xmm0, %xmm1
subsd %xmm2, %xmm0
divsd %xmm0, %xmm1
mulsd 0xf0(%rsp), %xmm1
movq 0xd0(%rsp), %r13
leaq 0x118(%rsp), %rbp
cmpl $0x1, %r12d
movsd %xmm1, 0xa0(%rsp)
je 0x4680e
movsd 0xb8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4680e
movq 0xa8(%rsp), %rdi
callq 0x442bb
movsd 0xa0(%rsp), %xmm1
cmpl $0x1, %r12d
je 0x46823
movsd 0xb8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x46876
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 0xa8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %r15
leaq 0x118(%rsp), %rbp
callq 0x4310
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq %rbp, %rdi
callq 0x442bb
movq %rbx, %rdi
movq 0x100(%rsp), %rsi
callq 0x3dbad
leal 0x1(%r12), %eax
cmpl 0xc0(%rsp), %r12d
movl %eax, %r12d
movq %r13, %r14
jne 0x465ef
movq %r15, %rdi
movq %r14, %rsi
callq 0x3dbad
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x3dbad
movq 0xa8(%rsp), %rax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq