// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/rbf.c
// Function: train_rbfnetwork_reg
Rbfnetworkptr train_rbfnetwork_reg(Instanceptr traindata, Instanceptr cvdata, Rbf_parameterptr params)
{
	/*!Last Changed 19.08.2007*/
	int i, j, *array, datasize = data_size(traindata);
	double *p, *y, squaredError, minSquaredError;
	Instanceptr inst;
	Rbfnetworkptr bestnetwork, network;
 Rbfweights prevweights, delta;
	network = allocate_rbfnetwork(params);
	initialize_rbfnetwork(network, traindata, params);
	p = safemalloc((network->hidden + 1) * sizeof(double), "train_rbfnetwork_reg", 7);
	y = safemalloc(sizeof(double), "train_rbfnetwork_reg", 8);
	params->eta = params->initialeta;
 allocate_rbfweights(&prevweights, params);
 for (i = 0; i < params->epochs; i++)
	 {
		 array = random_array(datasize);
			for (j = 0; j < datasize; j++)
			 {
				 inst = data_x(traindata, array[j]);
				 rbf_forward_propagation(network, inst, p, y);
					delta = rbf_backward_propagation(network, inst, p, y, params);
     update_rbfweights(network, delta, prevweights, params);
     copy_rbfweights(&prevweights, delta);
     free_rbfweights(delta);
			 }
			safe_free(array);
			squaredError = test_rbfnetwork_reg(network, cvdata);
		 if (i > 0)
			 {
			  if (squaredError < minSquaredError)
					 {
				   params->bestepoch = i;
				   minSquaredError = squaredError;
				   free_rbfnetwork(bestnetwork);
							bestnetwork = copy_of_rbfnetwork(network, params);
					 }
			 }
		 else
			 {
			  params->bestepoch = i;
			  minSquaredError = squaredError;
					bestnetwork = copy_of_rbfnetwork(network, params);
			 }
		 params->eta *= params->etadecrease;
	 }
	safe_free(p);
	safe_free(y);
 free_rbfweights(prevweights);
	return bestnetwork;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %rbx
movq %rsi, 0x88(%rsp)
movq %rdi, %r14
callq 0x2c3cc
movl %eax, %ebp
movq %rbx, %rdi
callq 0x666ed
movq %rax, %r12
movq %rax, %rdi
movq %r14, 0x98(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
callq 0x66734
movslq (%r12), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x38444(%rip), %r14     # 0x9f692
pushq $0x7
popq %rdx
movq %r14, %rsi
callq 0x34f59
movq %rax, %r13
pushq $0x8
popq %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x34f59
movq %rax, %r14
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x28(%rbx)
leaq 0xd8(%rsp), %rdi
movq %rbx, %rsi
callq 0x6669f
testl %ebp, %ebp
movl %ebp, 0x74(%rsp)
movl %ebp, %eax
movl $0x0, %r15d
cmovlel %r15d, %eax
movq %rax, 0xa0(%rsp)
movq %rbx, 0x68(%rsp)
cmpl 0xc(%rbx), %r15d
jge 0x6746b
movq %r15, 0x90(%rsp)
movl 0x74(%rsp), %edi
callq 0x35cf7
movq %rax, %rbp
xorl %ebx, %ebx
cmpq %rbx, 0xa0(%rsp)
je 0x673dc
movl (%rbp,%rbx,4), %esi
movq 0x98(%rsp), %rdi
callq 0x2d761
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x668fe
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq %r14, %r8
movq 0x68(%rsp), %r15
movq %r15, %r9
callq 0x66a23
movups 0xd8(%rsp), %xmm0
movups 0xe8(%rsp), %xmm1
movups 0xf8(%rsp), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movups 0xa8(%rsp), %xmm0
movups 0xb8(%rsp), %xmm1
movups 0xc8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x66c94
movups 0xa8(%rsp), %xmm0
movups 0xb8(%rsp), %xmm1
movups 0xc8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x667fd
movupd 0xa8(%rsp), %xmm0
movupd 0xb8(%rsp), %xmm1
movups 0xc8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x6663c
incq %rbx
jmp 0x672c6
movq %rbp, %rdi
callq 0x34ff7
movq %r12, %rdi
movq 0x88(%rsp), %rsi
callq 0x67116
movapd %xmm0, %xmm1
movq 0x90(%rsp), %r15
testl %r15d, %r15d
je 0x67432
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movq 0x68(%rsp), %rbx
jbe 0x67454
movsd %xmm1, 0x80(%rsp)
movl %r15d, 0x10(%rbx)
movq 0x78(%rsp), %rdi
callq 0x6666b
jmp 0x67444
movsd %xmm1, 0x80(%rsp)
movq 0x68(%rsp), %rbx
andl $0x0, 0x10(%rbx)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6683a
movq %rax, 0x78(%rsp)
movsd 0x30(%rbx), %xmm0
mulsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x28(%rbx)
incl %r15d
jmp 0x672a6
movq %r13, %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movups 0xd8(%rsp), %xmm0
movups 0xe8(%rsp), %xmm1
movups 0xf8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x6663c
movq 0x78(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)