// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::Normalization()
Matrix Matrix::Normalization()
{
    // includes normalization, centering and standarization per sample
    auto dim = Dimension();
    Matrix m(dim);

    // step 1) normalize
    double min = MinInSection(0, dim.first, 0, dim.second);
    double max = MaxInSection(0, dim.first, 0, dim.second);

    double amp = max - min;

    if(amp > 0)
        for(size_t i=0;i<dim.first;i++)
            for(size_t j=0;j<dim.second;j++)
                m[i][j] = (*this)[i][j] / amp;

    // step 2) cenering
    double average = 0;
    // find min, max, mean
    for(size_t i=0;i<dim.first;i++){
        for(size_t j=0;j<dim.second;j++)
        {
            average += m[i][j];
        }
    }
    double N = dim.first * dim.second;
    average /= N;
    if(average != 0)
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++)
            {
                m[i][j] = m[i][j] - average;
            }
        }

    // step 3) standardization
    // find sigma
    double sigma = 0;
    for(size_t i=0;i<dim.first;i++){
        for(size_t j=0;j<dim.second;j++)
        {
            double tmp = m[i][j];
            sigma += tmp*tmp;
        }
    }
    sigma = sqrt(sigma);
    if(sigma > 0)
        for(size_t i=0;i<dim.first;i++){
            for(size_t j=0;j<dim.second;j++)
            {
                m[i][j]/=sigma;
            }
        }

    return m;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq 0x108(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x3bae0
movq 0x30(%rsp), %rdi
movq %rax, 0xf8(%rsp)
movq %rdx, 0x100(%rsp)
movb $0x0, 0xf7(%rsp)
movups 0xf8(%rsp), %xmm0
movaps %xmm0, 0xe0(%rsp)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
callq 0x3b4a0
movq 0x38(%rsp), %rdi
movq 0xf8(%rsp), %rdx
movq 0x100(%rsp), %r8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0x3e6d0
movsd %xmm0, 0x40(%rsp)
jmp 0x3e1d1
movq 0x38(%rsp), %rdi
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movq 0xf8(%rsp), %rdx
movq 0x100(%rsp), %r8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
callq 0x3e860
movsd %xmm0, 0x20(%rsp)
jmp 0x3e209
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
movsd 0xc0(%rsp), %xmm0
subsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0xb8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3e347
movq $0x0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x3e345
movq $0x0, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x3e32a
movq 0x38(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0xa8(%rsp), %rsi
callq 0x1fd60
movq 0x30(%rsp), %rdi
movsd (%rax), %xmm0
divsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xb0(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0xa8(%rsp), %rsi
callq 0x1fd60
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0xa8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
jmp 0x3e277
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
callq 0x3bb80
jmp 0x3e6c0
jmp 0x3e32c
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x3e255
jmp 0x3e347
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq $0x0, 0x98(%rsp)
movq 0x98(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x3e3fc
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x3e3e1
movq 0x30(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x90(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
addsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x3e381
jmp 0x3e3e3
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0x3e35f
movq 0xf8(%rsp), %rax
movq 0x100(%rsp), %rcx
imulq %rcx, %rax
movq %rax, %xmm0
movaps 0x13c44(%rip), %xmm1    # 0x52060
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x13c48(%rip), %xmm1    # 0x52070
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3e478
jp 0x3e478
jmp 0x3e53a
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x3e538
movq $0x0, 0x78(%rsp)
movq 0x78(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x3e51d
movq 0x30(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x1fd60
movq 0x30(%rsp), %rdi
movsd (%rax), %xmm0
subsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x80(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x1fd60
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x3e4a3
jmp 0x3e51f
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0x3e484
jmp 0x3e53a
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x3e5e2
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x3e5cd
movq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x60(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm0
movsd 0x58(%rsp), %xmm2
movsd 0x70(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x3e568
jmp 0x3e5cf
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x3e54c
movsd 0x70(%rsp), %xmm0
callq 0x4468
movsd %xmm0, 0x70(%rsp)
movsd 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3e697
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0xf8(%rsp), %rax
jae 0x3e695
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x3e680
movq 0x30(%rsp), %rdi
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x50(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x48(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm1
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x3e627
jmp 0x3e682
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x3e60f
jmp 0x3e697
movb $0x1, 0xf7(%rsp)
testb $0x1, 0xf7(%rsp)
jne 0x3e6b3
movq 0x30(%rsp), %rdi
callq 0x3bb80
movq 0x28(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xd0(%rsp), %rdi
callq 0x43f0
nopl (%rax)