// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/softregtree.c
// Function: gradient_descent_soft_regtree
void gradient_descent_soft_regtree(Regressionnodeptr rootnode, Regressionnodeptr node, Softregtree_parameterptr param, double eta, double lambda)
{
 int i, j, k, *array, datasize;
 double o, r, multiplier, delta, feature_value;
 Instanceptr inst; 
 Regressionnodeptr tmpnode;
 datasize = data_size(rootnode->instances);
 node->w = random_matrix(current_dataset->multifeaturecount, 1, -0.01, +0.01);
 if (param->leaftype == CONSTANTLEAF)
  {
   node->left->regressionvalue = produce_random_value(-0.01, +0.01);
   node->right->regressionvalue = produce_random_value(-0.01, +0.01);
  }
 else
  {
   node->left->w = random_matrix(current_dataset->multifeaturecount, 1, -0.01, +0.01);
   node->right->w = random_matrix(current_dataset->multifeaturecount, 1, -0.01, +0.01);
  }
 for (i = 0; i < param->epochs; i++)
  {
   array = random_array(datasize);
   for (j = 0; j < datasize; j++)
    {
     inst = data_x(rootnode->instances, array[j]);
     o = soft_regtree_output(rootnode, inst);
     r = give_regressionvalue(inst);
     multiplier = eta * (r - o);
     tmpnode = node;
     while (tmpnode->parent)
      {
       multiplier *= tmpnode->weight;
       tmpnode = tmpnode->parent;
      }
     if (param->leaftype == CONSTANTLEAF)
      {
       node->left->regressionvalue += multiplier * node->left->weight;
       node->right->regressionvalue += multiplier * node->right->weight;
      }
     for (k = 0; k < current_dataset->multifeaturecount; k++)
      {      
       if (k != 0)
         feature_value = real_feature(inst, k - 1);
       else
         feature_value = 1;
       delta = multiplier * feature_value;
       if (param->regularization == NO_REGULARIZATION)
         node->w.values[k][0] += delta * (node->left->output - node->right->output) * node->left->weight * node->right->weight;
       else
         if (param->regularization == L1_REGULARIZATION)
          {
           if (feature_value > 0)
             node->w.values[k][0] += ((1 - lambda) * delta * (node->left->output - node->right->output) * node->left->weight * node->right->weight) / datasize + eta * lambda / current_dataset->multifeaturecount;
           else
             node->w.values[k][0] += ((1 - lambda) * delta * (node->left->output - node->right->output) * node->left->weight * node->right->weight) / datasize - eta * lambda / current_dataset->multifeaturecount;
          }
         else
           node->w.values[k][0] += ((1 - lambda) * delta * (node->left->output - node->right->output) * node->left->weight * node->right->weight) / datasize + (eta * lambda * feature_value) / current_dataset->multifeaturecount;           
       if (param->leaftype != CONSTANTLEAF)
        { 
         node->left->w.values[k][0] += delta * node->left->weight;
         node->right->w.values[k][0] += delta * node->right->weight;
        }
      }
    }
   safe_free(array);   
   eta = eta * param->etadecrease;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x50(%rsp)
movq 0x20(%rdi), %rdi
callq 0x2fa14
movl %eax, 0x4(%rsp)
leaq 0x4a617(%rip), %rbp     # 0xd2870
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
movsd 0x1ab4d(%rip), %xmm0    # 0xa2db8
movsd 0x1ab4d(%rip), %xmm1    # 0xa2dc0
movl $0x1, %esi
callq 0x3dd75
movq %rax, 0x30(%r14)
movq %rdx, 0x38(%r14)
cmpl $0x0, (%rbx)
je 0x882eb
movq (%r14), %r15
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
movsd 0x1ab19(%rip), %xmm0    # 0xa2db8
movsd 0x1ab19(%rip), %xmm1    # 0xa2dc0
movl $0x1, %esi
callq 0x3dd75
movq %rax, 0x30(%r15)
movq %rdx, 0x38(%r15)
movq 0x8(%r14), %r15
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
movl $0x1, %esi
movsd 0x1aae4(%rip), %xmm0    # 0xa2db8
movsd 0x1aae4(%rip), %xmm1    # 0xa2dc0
callq 0x3dd75
movq %rax, 0x30(%r15)
movq %rdx, 0x38(%r15)
jmp 0x88326
movsd 0x1aac5(%rip), %xmm0    # 0xa2db8
movsd 0x1aac5(%rip), %xmm1    # 0xa2dc0
callq 0x39f62
movq (%r14), %rax
movsd %xmm0, 0x70(%rax)
movsd 0x1aaa8(%rip), %xmm0    # 0xa2db8
movsd 0x1aaa8(%rip), %xmm1    # 0xa2dc0
callq 0x39f62
movq 0x8(%r14), %rax
movsd %xmm0, 0x70(%rax)
cmpl $0x0, 0x4(%rbx)
jle 0x88635
movsd 0x1a1e8(%rip), %xmm0    # 0xa2520
movl 0x4(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x18(%rsp)
subsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl %eax, %eax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movl 0x4(%rsp), %r15d
movl %r15d, %edi
callq 0x39fdc
movq %rax, 0x38(%rsp)
testl %r15d, %r15d
jle 0x8860a
movsd 0x8(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r12d, %r12d
movq 0x50(%rsp), %r15
movq 0x20(%r15), %rdi
movq 0x38(%rsp), %rax
movl (%rax,%r12,4), %esi
callq 0x30fe5
movq %rax, %r13
movq %r15, %rdi
movq %rax, %rsi
callq 0x880ec
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
callq 0x2eaee
movapd %xmm0, %xmm6
subsd 0x10(%rsp), %xmm6
mulsd 0x8(%rsp), %xmm6
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x883f3
movq %r14, %rcx
mulsd 0x48(%rcx), %xmm6
movq %rax, %rcx
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0x883e2
cmpl $0x0, (%rbx)
jne 0x88425
movq (%r14), %rax
movsd 0x48(%rax), %xmm0
mulsd %xmm6, %xmm0
addsd 0x70(%rax), %xmm0
movsd %xmm0, 0x70(%rax)
movq 0x8(%r14), %rax
movsd 0x48(%rax), %xmm0
mulsd %xmm6, %xmm0
addsd 0x70(%rax), %xmm0
movsd %xmm0, 0x70(%rax)
movq (%rbp), %rax
cmpl $0x0, 0x1c0(%rax)
jle 0x885fc
xorl %r15d, %r15d
movsd %xmm6, 0x10(%rsp)
movsd 0x1a0d9(%rip), %xmm0    # 0xa2520
testq %r15, %r15
je 0x8845e
leal -0x1(%r15), %esi
movq %r13, %rdi
callq 0x2e4b6
movsd 0x10(%rsp), %xmm6
movapd %xmm6, %xmm1
mulsd %xmm0, %xmm1
movl 0x20(%rbx), %eax
cmpl $0x1, %eax
je 0x8849e
testl %eax, %eax
jne 0x88511
movq (%r14), %rax
movq 0x8(%r14), %rcx
movsd 0x40(%rax), %xmm0
subsd 0x40(%rcx), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x48(%rax), %xmm0
movq 0x38(%r14), %rax
mulsd 0x48(%rcx), %xmm0
jmp 0x88561
ucomisd 0x1a862(%rip), %xmm0    # 0xa2d08
movq (%r14), %rax
movq 0x38(%r14), %rcx
movsd 0x40(%rax), %xmm4
movsd 0x48(%rax), %xmm0
movq (%rbp), %rax
xorps %xmm3, %xmm3
cvtsi2sdl 0x1c0(%rax), %xmm3
movq (%rcx,%r15,8), %rax
movsd (%rax), %xmm2
jbe 0x8856f
movsd 0x20(%rsp), %xmm5
mulsd %xmm1, %xmm5
movq 0x8(%r14), %rcx
subsd 0x40(%rcx), %xmm4
mulsd %xmm5, %xmm4
mulsd %xmm4, %xmm0
mulsd 0x48(%rcx), %xmm0
divsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm4
divsd %xmm3, %xmm4
addsd %xmm0, %xmm4
addsd %xmm4, %xmm2
jmp 0x885a7
movsd 0x20(%rsp), %xmm2
mulsd %xmm1, %xmm2
movq (%r14), %rax
movq 0x8(%r14), %rcx
movsd 0x40(%rax), %xmm3
subsd 0x40(%rcx), %xmm3
mulsd %xmm2, %xmm3
mulsd 0x48(%rax), %xmm3
mulsd 0x48(%rcx), %xmm3
divsd 0x18(%rsp), %xmm3
movq (%rbp), %rax
xorps %xmm2, %xmm2
cvtsi2sdl 0x1c0(%rax), %xmm2
mulsd 0x28(%rsp), %xmm0
divsd %xmm2, %xmm0
addsd %xmm3, %xmm0
movq 0x38(%r14), %rax
movq (%rax,%r15,8), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x885ab
movsd 0x20(%rsp), %xmm5
mulsd %xmm1, %xmm5
movq 0x8(%r14), %rcx
subsd 0x40(%rcx), %xmm4
mulsd %xmm5, %xmm4
mulsd %xmm4, %xmm0
mulsd 0x48(%rcx), %xmm0
divsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm4
divsd %xmm3, %xmm4
subsd %xmm4, %xmm0
addsd %xmm0, %xmm2
movsd %xmm2, (%rax)
cmpl $0x0, (%rbx)
je 0x885e5
movq (%r14), %rax
movq 0x38(%rax), %rcx
movq (%rcx,%r15,8), %rcx
movsd 0x48(%rax), %xmm0
mulsd %xmm1, %xmm0
addsd (%rcx), %xmm0
movsd %xmm0, (%rcx)
movq 0x8(%r14), %rax
movq 0x38(%rax), %rcx
mulsd 0x48(%rax), %xmm1
movq (%rcx,%r15,8), %rax
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
incq %r15
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
cmpq %rax, %r15
jl 0x8843f
incq %r12
cmpq 0x48(%rsp), %r12
jne 0x88393
movq 0x38(%rsp), %rdi
callq 0x39194
movsd 0x8(%rsp), %xmm0
mulsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rax
incl %eax
cmpl 0x4(%rbx), %eax
jl 0x8835e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq