// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %rdx, %r15
movq %rdi, %rbx
addq $0x60, %rdi
callq 0x5068
leaq 0x48(%rbx), %rdi
movq %r15, %rsi
callq 0x5068
movq 0x68(%rbx), %rsi
subq 0x60(%rbx), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbp, %rsi
leaq 0x50(%rsp), %r12
leaq 0xf(%rsp), %rdx
movq %r12, %rdi
callq 0x51e0
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq 0x30(%rbx), %rax
movups 0x38(%rbx), %xmm0
movq (%r12), %rcx
movq %rcx, 0x30(%rbx)
movq 0x8(%r12), %rcx
movq %rcx, 0x38(%rbx)
movq 0x10(%r12), %rcx
movq %rcx, 0x40(%rbx)
movq (%r15), %rcx
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rsi
movq %rax, (%r15)
movups %xmm0, 0x8(%r15)
movq %rcx, (%r12)
movq %rdx, 0x8(%r12)
movq %rsi, 0x10(%r12)
movq %r15, %rdi
callq 0x5268
movq %r12, %rdi
callq 0x5268
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x80(%rbx)
movsd 0x10(%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 0x322d
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 0x3352
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %r13, %rdi
callq 0x2e86
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0x52b6
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x31ae
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x3396
movq 0x20(%rbx), %rsi
addq $-0x30, %rsi
movq %r15, %rdi
callq 0x2d28
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 0x3344
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r15, %rsi
callq 0x2908
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x320c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x36ca
movq %rbx, %rdi
callq 0x3ad6
movl 0x78(%rbx), %eax
incl %eax
movl %eax, 0x78(%rbx)
cmpl %r12d, %eax
jb 0x315d
movq %rbx, %rdi
callq 0x35fe
movsd %xmm0, 0x10(%rsp)
incl %r14d
movq %r14, 0x18(%rsp)
movl $0x10, %edx
movq 0x7d89(%rip), %r14      # 0xafd8
movq %r14, %rdi
leaq 0x3edf(%rip), %rsi      # 0x7138
callq 0x2190
movq %r14, %rdi
movq 0x18(%rsp), %r14
movsd 0x10(%rsp), %xmm0
callq 0x2200
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4020(%rip), %rsi      # 0x72a0
callq 0x2190
movsd 0x10(%rsp), %xmm0
ucomisd (%rbx), %xmm0
jbe 0x329b
cmpq %r14, 0x10(%rbx)
jg 0x314b
movq 0x7d36(%rip), %rbx      # 0xafd8
leaq 0x3ea0(%rip), %rsi      # 0x7149
movl $0x11, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0x3fe3(%rip), %r15      # 0x72a0
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2190
leaq 0x3e87(%rip), %rsi      # 0x715b
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x2200
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2190
leaq 0x3e62(%rip), %rsi      # 0x716b
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2190
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20c0
leaq 0x3f77(%rip), %rsi      # 0x729f
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 0x3d68(%rip), %rdi      # 0x70b3
xorl %eax, %eax
callq 0x21d0
leaq 0x3d5a(%rip), %rdi      # 0x70b3
xorl %eax, %eax
callq 0x21d0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x338e
movq 0x48(%rsp), %rsi
jmp 0x3386
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x338e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2260