// File: /workspace/github_c_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdx, %rbx
movq %rsi, 0xc8(%rsp)
movq %rdi, %r14
callq 0x30309
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6fc47
movq %rax, %r12
movq %rax, %rdi
movq %r14, 0xf0(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
callq 0x6fc92
movslq (%r12), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x3ee88(%rip), %r14     # 0xaf772
movq %r14, %rsi
movl $0x7, %edx
callq 0x3a0e1
movq %rax, 0x88(%rsp)
movl $0x8, %edi
movq %r14, %rsi
movl $0x8, %edx
callq 0x3a0e1
movq %rax, %r13
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x28(%rbx)
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
callq 0x6fbf7
movq %rbx, 0x68(%rsp)
cmpl $0x0, 0xc(%rbx)
jle 0x70bd1
movl %ebp, %eax
movq %rax, 0xe0(%rsp)
movq $0x0, 0x78(%rsp)
movq 0x88(%rsp), %r14
movl %ebp, 0x74(%rsp)
movq %r12, 0xe8(%rsp)
movq %r13, 0xd8(%rsp)
movl %ebp, %edi
callq 0x3afe4
movq %rax, %rdx
testl %ebp, %ebp
movq %r13, %rbp
jle 0x70b09
xorl %r13d, %r13d
movq %rdx, 0xf8(%rsp)
movq 0x68(%rsp), %rbx
movl (%rdx,%r13,4), %esi
movq 0xf0(%rsp), %rdi
callq 0x31851
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x6fe88
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
callq 0x6ffb1
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movupd 0x108(%rsp), %xmm0
movupd 0x118(%rsp), %xmm1
movups 0x128(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x7024b
movq 0x108(%rsp), %rbp
movq 0x110(%rsp), %r14
movq 0x118(%rsp), %r12
movq %r12, 0x80(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x128(%rsp), %rbx
movq 0x130(%rsp), %r15
leaq 0x98(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x406d5
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
movq 0x100(%rsp), %r12
movq %r12, %rdx
callq 0x406d5
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x406d5
movq %rbp, %rdi
movq 0xd8(%rsp), %rbp
movq %r14, %rsi
movq 0x88(%rsp), %r14
callq 0x3ed51
movq 0x80(%rsp), %rdi
movq %r12, %rsi
movq 0xe8(%rsp), %r12
callq 0x3ed51
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3ed51
movq 0xe0(%rsp), %rcx
movq 0xf8(%rsp), %rdx
incq %r13
cmpq %r13, %rcx
jne 0x7098c
movq %rdx, %rdi
callq 0x3a180
movq %r12, %rdi
movq 0xc8(%rsp), %rsi
callq 0x707a2
movapd %xmm0, %xmm1
cmpl $0x0, 0x78(%rsp)
je 0x70b63
movsd 0xd0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movq %rbp, %r13
jbe 0x70ba2
movsd %xmm1, 0x80(%rsp)
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
movl %eax, 0x10(%rcx)
movq 0x90(%rsp), %rdi
callq 0x6fba7
jmp 0x70b7b
movsd %xmm1, 0x80(%rsp)
movq 0x68(%rsp), %rax
movl $0x0, 0x10(%rax)
movq %rbp, %r13
movq %r12, %rdi
movq 0x68(%rsp), %rsi
callq 0x6fda4
movq %rax, 0x90(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
movl 0x74(%rsp), %ebp
movq 0x68(%rsp), %rcx
movsd 0x30(%rcx), %xmm0
mulsd 0x28(%rcx), %xmm0
movsd %xmm0, 0x28(%rcx)
movq 0x78(%rsp), %rax
incl %eax
movq %rax, 0x78(%rsp)
cmpl 0xc(%rcx), %eax
jl 0x7096c
jmp 0x70bd9
movq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x3a180
movq %r13, %rdi
callq 0x3a180
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rbx
movq 0xb0(%rsp), %r14
movq 0xb8(%rsp), %r15
movq 0xc0(%rsp), %r12
callq 0x3ed51
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ed51
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ed51
movq 0x90(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop