// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/mlp.c
// Function: dnc_cls
Mlpnetwork dnc_cls(matrix Train, Mlpparametersptr P)
{
 /*!Last Changed 16.04.2007*/
 Mlpnetwork nN;
 matrixptr prevWeights, H;
 double *errorinwidth, sqrdError, lastError, control;
 int tr, trial, *I, iindex, k, lastNum = 0;
 nN = allocate_mlpnnetwork(*P);
 prevWeights = allocate_weights(*P, INITIAL_VALUE, 0);
 H = allocate_hiddens(*P);
 errorinwidth = safemalloc(P->windowsize * sizeof(double), "dnc_cls", 8);
 P->eta = P->initialeta;
 for (tr = 0; tr < P->epochs; tr++)
  {
   trial = tr + 1;
   sqrdError = 0.0;  
   I = random_array(P->inputnum);
   for (k = 0; k < P->inputnum; k++)
    {
     iindex = I[k];
     sqrdError = sqrdError + backPropMlpn_cls(Train.values[iindex], nN.weights, H, prevWeights, *P);
    }
   safe_free(I);
   sqrdError = sqrdError / P->inputnum; 
   P->sqrderror = sqrdError;
   if (sqrdError <= P->errorthreshold)
     break;
   if (tr == 0)
     lastError = sqrdError;  
   if ((trial > P->windowsize) && ((trial - P->windowsize) >= lastNum))
    {
				 if (P->maxhidden != 0 && P->hidden[0] == P->maxhidden)
						 break;
     control = fabs(sqrdError - errorinwidth[(trial - 1) % P->windowsize]) / lastError;
     if (control < P->errordropratio)
      {
       lastError = sqrdError;
       lastNum = trial;
       free_weights(prevWeights, P->layernum);
							reallocate_weights(*P, nN.weights, 0, 1, RANDOM, 0);
							reallocate_hiddens(H, *P, 0, 1);
							H[0].values[0][P->hidden[0]] = 0.0;
       P->hidden[0]++;
       P->eta = P->initialeta;
       prevWeights = allocate_weights(*P, INITIAL_VALUE, 0);
      }
    }
   errorinwidth[(trial - 1) % P->windowsize] = sqrdError;    
   P->eta = P->eta * P->etadecrease;
  }    
 nN.P = *P;
 safe_free(errorinwidth);
 free_weights(prevWeights, P->layernum);
 free_hiddens(H, P->layernum);    
 P->epochstrained = trial;
 return nN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rcx, %rbp
movq %rdx, %r12
movq %rdi, %r14
leaq 0x178(%rsp), %r13
movl $0x90, %edx
movq %r13, %rdi
movq %rcx, %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %r15d, %r15d
xorl %edi, %edi
xorl %esi, %esi
callq 0x43f69
movq %rax, (%r14)
leaq 0x8(%r14), %rdi
movl $0x90, %edx
movq %rdi, 0xd0(%rsp)
movq %r13, %rsi
callq 0x4310
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %edi
xorl %esi, %esi
callq 0x43f69
movq %rax, %rbx
leaq 0xe8(%rsp), %r13
movl $0x90, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4310
movslq 0x54(%r13), %r13
testq %r13, %r13
movq %r14, 0xa0(%rsp)
jle 0x45894
movq %r13, %rdi
shlq $0x4, %rdi
leaq 0x61ab1(%rip), %rsi     # 0xa7305
movl $0x4, %edx
callq 0x390f5
movq %rax, %r15
shlq $0x2, %r13
xorl %r14d, %r14d
movl 0x130(%rsp,%r14), %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, (%r15,%r14,4)
movq %rdx, 0x8(%r15,%r14,4)
addq $0x4, %r14
cmpq %r14, %r13
jne 0x45868
movq 0xa0(%rsp), %r14
movslq 0x68(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x61a73(%rip), %rsi     # 0xa7316
movl $0x8, %edx
callq 0x390f5
movq %rax, 0xa8(%rsp)
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x38(%rbp)
cmpl $0x0, 0x14(%rbp)
jle 0x45b5c
movq $0x0, 0xc0(%rsp)
xorl %r13d, %r13d
movq %r12, 0xd8(%rsp)
movq %r15, 0xb0(%rsp)
movq %rbx, 0xb8(%rsp)
movl %r13d, %eax
movq %rax, 0xc8(%rsp)
movl 0x8(%rbp), %edi
callq 0x39fdc
movq %rax, %r12
movq %rbp, %rax
cmpl $0x0, 0x8(%rbp)
jle 0x45994
xorpd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
xorl %r14d, %r14d
movq 0xd8(%rsp), %r15
movq 0xb0(%rsp), %r13
movq 0xb8(%rsp), %rbx
movq %rax, %rbp
movslq (%r12,%r14,4), %rax
movq (%r15,%rax,8), %rax
movq 0xa0(%rsp), %rcx
movq (%rcx), %rdx
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
movq %rdx, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x447e6
movsd 0x98(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rsp)
incq %r14
movslq 0x8(%rbp), %rax
cmpq %rax, %r14
jl 0x4593e
jmp 0x459a4
xorpd %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
movq %rax, %rbp
movq 0xc8(%rsp), %rbx
leal 0x1(%rbx), %r13d
movq %r12, %rdi
callq 0x39194
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rbp), %xmm0
movsd 0x98(%rsp), %xmm3
divsd %xmm0, %xmm3
movsd %xmm3, 0x88(%rbp)
movsd 0x70(%rbp), %xmm0
ucomisd %xmm3, %xmm0
jae 0x45b5e
movapd %xmm3, %xmm0
testl %ebx, %ebx
movq %rbx, %rsi
je 0x459f8
movsd 0xe0(%rsp), %xmm0
movl 0x68(%rbp), %ecx
cmpl %ecx, %esi
setl %al
movl %r13d, %edx
subl %ecx, %edx
cmpl 0xc0(%rsp), %edx
setl %dl
orb %al, %dl
movq 0xa0(%rsp), %r14
movq 0xb0(%rsp), %r15
movq 0xb8(%rsp), %rbx
jne 0x45b25
movl 0x84(%rbp), %eax
testl %eax, %eax
je 0x45a42
cmpl %eax, 0x48(%rbp)
je 0x45b76
movl %esi, %eax
cltd
idivl %ecx
movapd %xmm3, %xmm1
movq 0xa8(%rsp), %rax
subsd (%rax,%rdx,8), %xmm1
andpd 0x5d780(%rip), %xmm1    # 0xa31e0
divsd %xmm0, %xmm1
movsd 0x78(%rbp), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x45b25
movl 0x54(%rbp), %esi
movq %rbx, %rdi
movsd %xmm3, 0x98(%rsp)
callq 0x442c9
movq (%r14), %rax
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
xorl %esi, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x440b0
movl 0x48(%rbp), %ecx
incl %ecx
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movl $0x1, %edx
callq 0x3e404
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
movq (%rdx), %rax
movslq 0x48(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x48(%rbp)
movsd 0x20(%rbp), %xmm0
movsd %xmm0, 0x38(%rbp)
movl $0x12, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %edi
xorl %esi, %esi
callq 0x43f69
movsd 0x98(%rsp), %xmm3
movq 0xc8(%rsp), %rsi
movq %rax, %rbx
movapd %xmm3, %xmm0
movl %r13d, %eax
movq %rax, 0xc0(%rsp)
movl %esi, %eax
cltd
idivl 0x68(%rbp)
movq 0xa8(%rsp), %rax
movsd %xmm3, (%rax,%rdx,8)
movsd 0x38(%rbp), %xmm1
mulsd 0x40(%rbp), %xmm1
movsd %xmm1, 0x38(%rbp)
movsd %xmm0, 0xe0(%rsp)
cmpl 0x14(%rbp), %r13d
jl 0x458e8
jmp 0x45b76
jmp 0x45b76
movq 0xa0(%rsp), %r14
movq 0xb0(%rsp), %r15
movq 0xb8(%rsp), %rbx
movl $0x90, %edx
movq 0xd0(%rsp), %rdi
movq %rbp, %rsi
callq 0x4310
movq 0xa8(%rsp), %rdi
callq 0x39194
movl 0x54(%rbp), %esi
movq %rbx, %rdi
callq 0x442c9
movl 0x54(%rbp), %esi
movq %r15, %rdi
callq 0x44307
movl %r13d, 0x80(%rbp)
movq %r14, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq