// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x108(%rbp)
movq %rdi, -0x110(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq %rcx, -0x18(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x18(%rbp), %rsi
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq -0x100(%rbp), %rdi
callq 0x61600
movq -0x108(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0x98, %edx
callq 0x42b0
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %edi
xorl %esi, %esi
callq 0x634e0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rsi
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x63970
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq 0x68(%rax), %rdi
shlq $0x3, %rdi
leaq 0x81a8a(%rip), %rsi     # 0xe6ed5
movl $0x8, %edx
callq 0x52d70
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x6578d
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x54600
movq %rax, -0x58(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x65553
movq -0x108(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x5c(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movq -0x8(%rbp), %rcx
movslq -0x5c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rcx, -0x128(%rbp)
movq (%rax), %rax
movq %rax, -0x130(%rbp)
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x18(%rbp), %rsi
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rcx
callq 0x643e0
movaps %xmm0, %xmm1
movsd -0x118(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x654aa
movq -0x58(%rbp), %rdi
callq 0x52e80
movsd -0x38(%rbp), %xmm0
movq -0x18(%rbp), %rax
cvtsi2sdl 0x8(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x88(%rax)
movsd -0x38(%rbp), %xmm1
movq -0x18(%rbp), %rax
movsd 0x70(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x6559d
jmp 0x6578d
cmpl $0x0, -0x4c(%rbp)
jne 0x655ad
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x50(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jle 0x65737
movl -0x50(%rbp), %eax
movq -0x18(%rbp), %rcx
subl 0x68(%rcx), %eax
cmpl -0x64(%rbp), %eax
jl 0x65737
movq -0x18(%rbp), %rax
cmpl $0x0, 0x84(%rax)
je 0x655f5
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x84(%rcx), %eax
jne 0x655f5
jmp 0x6578d
movsd -0x38(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x50(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x68(%rcx)
movq -0x138(%rbp), %rax
movslq %edx, %rcx
subsd (%rax,%rcx,8), %xmm0
movaps 0x7d837(%rip), %xmm1    # 0xe2e60
pand %xmm1, %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm1
movq -0x18(%rbp), %rax
movsd 0x78(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x65735
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x54(%rax), %esi
callq 0x63ae0
movq -0x108(%rbp), %rax
movq -0x18(%rbp), %rsi
movq (%rax), %rax
movq %rax, -0x148(%rbp)
xorl %eax, %eax
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x148(%rbp), %rdi
movl $0x1, %edx
xorl %r8d, %r8d
movl %r8d, %esi
movl %r8d, %ecx
callq 0x63700
movq -0x28(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x140(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x63a30
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x48(%rcx), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movl 0x48(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x48(%rax)
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movq %rsp, %rdi
movl $0x12, %ecx
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %edi
xorl %esi, %esi
callq 0x634e0
movq %rax, -0x20(%rbp)
jmp 0x65737
movsd -0x38(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x50(%rbp), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
cltd
idivl 0x68(%rcx)
movq -0x150(%rbp), %rax
movslq %edx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movsd 0x38(%rax), %xmm0
movq -0x18(%rbp), %rax
mulsd 0x40(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x65472
movq -0x108(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
movl $0x90, %edx
callq 0x42b0
movq -0x30(%rbp), %rdi
callq 0x52e80
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x54(%rax), %esi
callq 0x63ae0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x54(%rax), %esi
callq 0x63b40
movq -0x110(%rbp), %rax
movl -0x50(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x80(%rcx)
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopl (%rax)