// File: /workspace/github_cpp_makefile_star2_O2/leonn[P]neuralNet/source/net.cpp
// Function: Net::backPropagation(std::vector<double, std::allocator<double>> const&, long double const&, long double const&)
void Net::backPropagation(const vector<double> &targetValues,const long double &eta ,const long double &alpha){

	//-----Calculate overall net error (RMS-root mean square error - of output neuron errors)
	Layer &outputLayer = layers.back();

	//overwall net error
	error=0.0;

 	for(unsigned n = 0; n < outputLayer.size() -1; n++){
 		long double delta= targetValues[n] - outputLayer[n].getOutputValue();
 		error+=delta*delta;
 	}
 	error*=0.5;

 	//error/=(* numPatterns); //get average error squared
	//error/=outputLayer.size()-1; //get average error squared
    //------ Implement a recent average measurement
    recentAverageError = error;

    //------ Calculate output layer gradients
	for(unsigned n = 0; n < outputLayer.size() -1; n++){
 		outputLayer[n].calculateOutputGradients(targetValues[n]);
  	}

    //------- Calculate hidden layer gradients
  	for(unsigned layerNumber = layers.size() -2; layerNumber >0 ; layerNumber--){
		Layer &hiddenLayer = layers[layerNumber];
		Layer &nextLayer = layers[layerNumber+1];

		for(unsigned n = 0; n < hiddenLayer.size(); n++){
			hiddenLayer[n].calculateHiddenGradients(nextLayer);
  		}
  	}

    //------- For all layers from outputs to first hidden layer,
    //------- update connection weights
  	for(unsigned layerNumber = layers.size() -1; layerNumber >0 ; layerNumber--){
		Layer &layer = layers[layerNumber];
		Layer &prevLayer = layers[layerNumber-1];

		for(unsigned n = 0; n < layer.size() -1; n++){
			layer[n].updateInputWeights(prevLayer,eta,alpha);
		}
  	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, -0x48(%rbp)
movq %rdx, %r14
movq %rsi, %rbx
movq 0x28(%rdi), %r15
fldz
movq %rdi, -0x30(%rbp)
fld %st(0)
fstpt (%rdi)
xorl %eax, %eax
pushq $0x60
popq %r13
movl %eax, %r12d
movq -0x18(%r15), %rdi
movq -0x10(%r15), %rcx
movq %rcx, %rax
subq %rdi, %rax
cqto
idivq %r13
decq %rax
cmpq %r12, %rax
jbe 0x2859
fstp %st(0)
movq (%rbx), %rax
fldl (%rax,%r12,8)
fstpt -0x40(%rbp)
imulq $0x60, %r12, %rax
addq %rax, %rdi
callq 0x40a8
fldt -0x40(%rbp)
fsubp %st, %st(1)
movq -0x30(%rbp), %rax
fldt (%rax)
fxch %st(1)
fmul %st, %st(0)
faddp %st, %st(1)
fld %st(0)
fstpt (%rax)
leal 0x1(%r12), %eax
jmp 0x2807
fmuls 0x27c1(%rip)            # 0x5020
movq -0x30(%rbp), %rax
fld %st(0)
fstpt (%rax)
fstpt 0x10(%rax)
xorl %eax, %eax
movl %eax, %r12d
subq %rdi, %rcx
movq %rcx, %rax
cqto
idivq %r13
decq %rax
cmpq %r12, %rax
jbe 0x28a7
imulq $0x60, %r12, %rax
addq %rax, %rdi
movq (%rbx), %rax
fldl (%rax,%r12,8)
fstpt (%rsp)
callq 0x4202
leal 0x1(%r12), %eax
movq -0x18(%r15), %rdi
movq -0x10(%r15), %rcx
jmp 0x286c
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rax
subq 0x20(%rcx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
addl $-0x2, %eax
movq %rax, %rcx
subq $0x1, %rcx
jb 0x2918
movq %rcx, -0x40(%rbp)
movq -0x30(%rbp), %rcx
movq 0x20(%rcx), %rcx
imulq $0x18, %rax, %r15
addq %rcx, %r15
incl %eax
imulq $0x18, %rax, %r12
addq %rcx, %r12
xorl %eax, %eax
movl %eax, %ebx
movq (%r15), %rdi
movq 0x8(%r15), %rax
subq %rdi, %rax
cqto
idivq %r13
cmpq %rbx, %rax
jbe 0x290f
imulq $0x60, %rbx, %rax
addq %rax, %rdi
movq %r12, %rsi
callq 0x42b8
leal 0x1(%rbx), %eax
jmp 0x28e5
movq -0x40(%rbp), %rcx
movq %rcx, %rax
jmp 0x28c1
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rax
subq 0x20(%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movl %eax, %ecx
decl %ecx
je 0x298d
movl %ecx, -0x40(%rbp)
movl %ecx, %ecx
movq -0x30(%rbp), %rdx
movq 0x20(%rdx), %rdx
imulq $0x18, %rcx, %r15
addq %rdx, %r15
addl $-0x2, %eax
imulq $0x18, %rax, %r12
addq %rdx, %r12
xorl %eax, %eax
movl %eax, %ebx
movq (%r15), %rdi
movq 0x8(%r15), %rax
subq %rdi, %rax
cqto
idivq %r13
decq %rax
cmpq %rbx, %rax
jbe 0x2986
imulq $0x60, %rbx, %rax
addq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq -0x48(%rbp), %rcx
callq 0x42e6
leal 0x1(%rbx), %eax
jmp 0x2952
movl -0x40(%rbp), %ecx
movl %ecx, %eax
jmp 0x292e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq