// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/rbf.c
// Function: train_rbfnetwork_cls
Rbfnetworkptr train_rbfnetwork_cls(Instanceptr traindata, Instanceptr cvdata, Rbf_parameterptr params)
{
	/*!Last Changed 19.08.2007*/
	int i, j, *array, performance, bestperformance, datasize = data_size(traindata);
	double *p, *y;
	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_cls", 7);
	y = safemalloc(network->output * sizeof(double), "train_rbfnetwork_cls", 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);
			performance = test_rbfnetwork_cls(network, cvdata);
		 if (i > 0)
			 {
			  if (performance > bestperformance)
					 {
				   params->bestepoch = i;
				   bestperformance = performance;
				   free_rbfnetwork(bestnetwork);
							bestnetwork = copy_of_rbfnetwork(network, params);
					 }
			 }
		 else
			 {
			  params->bestepoch = i;
			  bestperformance = performance;
					bestnetwork = copy_of_rbfnetwork(network, params);
			 }
		 params->eta *= params->etadecrease;
	 }
	safe_free(p);
	safe_free(y);
 free_rbfweights(prevweights);
 free_rbfnetwork(network);
	return bestnetwork;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %r14
movq %rsi, 0x80(%rsp)
movq %rdi, %r15
callq 0x2c3cc
movl %eax, %ebp
movq %r14, %rdi
callq 0x666ed
movq %rax, %rbx
movq %rax, %rdi
movq %r15, 0x88(%rsp)
movq %r15, %rsi
movq %r14, %rdx
callq 0x66734
movslq (%rbx), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x387b4(%rip), %r15     # 0x9f669
pushq $0x7
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r13
movslq 0x4(%rbx), %rdi
shlq $0x3, %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r15
movsd 0x18(%r14), %xmm0
movsd %xmm0, 0x28(%r14)
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
callq 0x6669f
xorl %ecx, %ecx
testl %ebp, %ebp
movl %ebp, 0x68(%rsp)
movl %ebp, %eax
cmovlel %ecx, %eax
movq %rax, 0x90(%rsp)
movq %r14, 0x60(%rsp)
cmpl 0xc(%r14), %ecx
jge 0x670bc
movq %rcx, 0x78(%rsp)
movl 0x68(%rsp), %edi
callq 0x35cf7
movq %rax, %rbp
xorl %r14d, %r14d
cmpq %r14, 0x90(%rsp)
je 0x67042
movl (%rbp,%r14,4), %esi
movq 0x88(%rsp), %rdi
callq 0x2d761
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x668fe
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
movq 0x60(%rsp), %r12
movq %r12, %r9
callq 0x66a23
movups 0xc8(%rsp), %xmm0
movups 0xd8(%rsp), %xmm1
movups 0xe8(%rsp), %xmm2
movups %xmm2, 0x50(%rsp)
movups %xmm1, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x66c94
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x667fd
movupd 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x6663c
incq %r14
jmp 0x66f2d
movq %rbp, %rdi
callq 0x34ff7
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
callq 0x66db5
movl %eax, %ebp
movq 0x78(%rsp), %rcx
testl %ecx, %ecx
je 0x67080
cmpl 0x6c(%rsp), %ebp
movq 0x60(%rsp), %r14
jle 0x670a3
movl %ecx, 0x10(%r14)
movq 0x70(%rsp), %rdi
callq 0x6666b
jmp 0x6708a
movq 0x60(%rsp), %r14
andl $0x0, 0x10(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6683a
movq %rax, 0x70(%rsp)
movl %ebp, 0x6c(%rsp)
movq 0x78(%rsp), %rcx
movsd 0x30(%r14), %xmm0
mulsd 0x28(%r14), %xmm0
movsd %xmm0, 0x28(%r14)
incl %ecx
jmp 0x66f0f
movq %r13, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movups 0xc8(%rsp), %xmm0
movups 0xd8(%rsp), %xmm1
movups 0xe8(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x6663c
movq %rbx, %rdi
callq 0x6666b
movq 0x70(%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq