// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rcx, %r15
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x60(%rdi), %r14
movq %r14, %rdi
callq 0x460e
leaq 0x48(%rbx), %rdi
movq %r12, %rsi
callq 0x460e
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
pushq $0x18
popq %rbp
cqto
idivq %rbp
leaq 0x30(%rsp), %r12
leaq 0x7(%rsp), %rdx
movq %r12, %rdi
movq %rax, %rsi
callq 0x46ec
leaq 0x30(%rbx), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x4c48
movq %r12, %rdi
callq 0x473e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x80(%rbx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
cqto
idivq %rbp
movq %rax, %rbp
xorl %eax, %eax
leaq 0x18(%rsp), %r15
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, 0x78(%rbx)
cmpl %ebp, %eax
jae 0x31cd
movl %eax, %esi
movq %r14, %rdi
callq 0x476a
movq %r15, %rdi
movq %rax, %rsi
callq 0x2dc4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4760
movq %r15, %rdi
callq 0x281e
movq %rbx, %rdi
callq 0x32da
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4788
movl 0x78(%rbx), %esi
movq %r13, %rdi
callq 0x476a
movq %rax, %rdi
movq %r12, %rsi
callq 0x2926
movq %r12, %rdi
callq 0x281e
movq %rbx, %rdi
callq 0x341e
movl 0x78(%rbx), %eax
incl %eax
jmp 0x315e
movq %rbx, %rdi
callq 0x3430
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movq 0x6dea(%rip), %rdi      # 0x9fd8
leaq 0x2f2b(%rip), %rsi      # 0x6120
callq 0x2150
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x21f0
movq %rax, %rdi
leaq 0x3076(%rip), %rsi      # 0x6288
callq 0x2150
movq 0x10(%rsp), %rax
movsd 0x8(%rsp), %xmm0
ucomisd (%rbx), %xmm0
jbe 0x3232
cmpq %rax, 0x10(%rbx)
jg 0x3157
movq 0x6d9f(%rip), %rdi      # 0x9fd8
movq %rax, %r14
leaq 0x2eee(%rip), %rsi      # 0x6131
callq 0x2150
leaq 0x3039(%rip), %rbx      # 0x6288
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2150
leaq 0x2ee2(%rip), %rsi      # 0x6143
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x21f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2150
leaq 0x2eca(%rip), %rsi      # 0x6153
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movq %r14, %rsi
callq 0x20c0
leaq 0x2fe4(%rip), %rsi      # 0x6287
movq %rax, %rdi
callq 0x2150
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x32cc
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x281e
movq %rbx, %rdi
callq 0x2260
nop