// File: /workspace/github_cpp_makefile_star2_O3/gkosae[P]ArduinoNeuralNet/neuralnet.cpp
// Function: NeuralNet::train(std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>, double, double, long)
void NeuralNet::train(vector<vector<double>> input_samples,
                             vector<vector<double>> output_samples,
                             double learn_rate,
                             double new_lambda,
                             long max_iter)
{
    input_data = input_samples;
    expected_output = output_samples;
    actual_output = std::vector<vector<double>>(input_data.size());

    lambda = new_lambda;
    learning_rate = learn_rate;
    max_iteration_number = max_iter;

    double overall_error = 0;
    unsigned int number_of_samples = input_data.size();
    unsigned int iteration_number = 0;

    do
    {
        for(current_sample = 0; current_sample <  number_of_samples; ++current_sample) {
          feed(input_data.at(current_sample));
          forward();

          actual_output.at(current_sample) = getOutputs();
          updateWeights();
        }

        overall_error = calculateOverallError();
        ++iteration_number;

        #ifdef VERBOSE
            std::cout << "Current error = " << overall_error << "\n";
        #endif
    } while (overall_error > minimum_error && iteration_number < max_iteration_number);

    #ifdef VERBOSE
    std::cout << "\nTRAINING RESULTS" << "\n"
              << "Overall error: " << overall_error << "\n"
              << "Total number of iterations: " << iteration_number << "\n\n";
    #endif

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r14
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rdx, %r15
movq %rdi, %rbx
addq $0x60, %rdi
callq 0x5110
leaq 0x48(%rbx), %rdi
movq %r15, %rsi
callq 0x5110
movq 0x68(%rbx), %rsi
subq 0x60(%rbx), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbp, %rsi
leaq 0x50(%rsp), %r12
leaq 0x7(%rsp), %rdx
movq %r12, %rdi
callq 0x52ae
movq 0x40(%rbx), %rax
movaps (%r12), %xmm0
movq 0x10(%r12), %rcx
movq %rcx, 0x40(%rbx)
movups 0x30(%rbx), %xmm1
movups %xmm0, 0x30(%rbx)
leaq 0x10(%rsp), %r15
movaps %xmm1, (%r15)
movq %rax, 0x10(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movq %r15, %rdi
callq 0x532c
movq %r12, %rdi
callq 0x532c
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x80(%rbx)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %r12d # imm = 0xAAAAAAAB
xorl %r14d, %r14d
leaq 0x38(%rsp), %r13
movl $0x0, 0x78(%rbx)
testl %r12d, %r12d
je 0x329c
xorl %eax, %eax
movl %eax, %esi
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %rbp, %rdx
cmpq %rsi, %rdx
jbe 0x33c2
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r13, %rdi
callq 0x2ee4
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0x5380
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x31eb
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x3406
movq 0x20(%rbx), %rsi
addq $-0x30, %rsi
movq %r15, %rdi
callq 0x2d80
movl 0x78(%rbx), %esi
movq 0x30(%rbx), %rax
movq 0x38(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %rbp, %rdx
cmpq %rsi, %rdx
jbe 0x33b4
leaq (%rsi,%rsi,2), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x10(%rax,%rcx,8), %rsi
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x327b
subq %rdi, %rsi
callq 0x2180
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x327b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x3744
movq %rbx, %rdi
callq 0x3b80
movl 0x78(%rbx), %eax
incl %eax
movl %eax, 0x78(%rbx)
cmpl %r12d, %eax
jb 0x319a
movq %rbx, %rdi
callq 0x3678
movsd %xmm0, 0x8(%rsp)
incl %r14d
movl $0x10, %edx
movq %r14, %r15
movq 0x7d1c(%rip), %r14      # 0xafd8
movq %r14, %rdi
leaq 0x3ea2(%rip), %rsi      # 0x7168
callq 0x2190
movq %r14, %rdi
movq %r15, %r14
leaq 0x10(%rsp), %r15
movsd 0x8(%rsp), %xmm0
callq 0x2200
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3fe0(%rip), %rsi      # 0x72d0
callq 0x2190
movsd 0x8(%rsp), %xmm0
ucomisd (%rbx), %xmm0
jbe 0x330b
cmpq %r14, 0x10(%rbx)
jg 0x3188
movq 0x7cc6(%rip), %rbx      # 0xafd8
leaq 0x3e60(%rip), %rsi      # 0x7179
movl $0x11, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x3fa3(%rip), %r15      # 0x72d0
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2190
leaq 0x3e47(%rip), %rsi      # 0x718b
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2200
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2190
leaq 0x3e22(%rip), %rsi      # 0x719b
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20c0
leaq 0x3f37(%rip), %rsi      # 0x72cf
movl $0x2, %edx
movq %rax, %rdi
callq 0x2190
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d28(%rip), %rdi      # 0x70e3
xorl %eax, %eax
callq 0x21d0
leaq 0x3d1a(%rip), %rdi      # 0x70e3
xorl %eax, %eax
callq 0x21d0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x33fe
movq 0x48(%rsp), %rsi
jmp 0x33f6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x33fe
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2260