// File: richardposner[P]BioNetFit2/src/code/Data.cpp
// Function: Data::standardizeData()
void Data::standardizeData() {
	// This function standardizes our data around a mean of 0

	double mean;
	double sqtotal;
	int counter;
	double stdev;

	// Loop through data map
	for(map<string,map<double,double> >::iterator c = dataCurrent->begin(); c != dataCurrent->end(); ++c) {

		// Grab our mean, which has already been calculated
		mean = colAverages[c->first];
		sqtotal = 0;
		counter = 0;

		// Skip the column if mean is already 0
		if (mean == 0) {
			continue;
		}

		// Here we get the riemann sum squared for use in the stdev calculation
		for(map<double,double>::iterator v = c->second.begin(); v != c->second.end(); ++v) {
			//cout << "sd loop" << endl;
			if (std::isnan(v->second)) {
				continue;
			}
			sqtotal += pow(mean - v->second, 2);
			counter++;
		}

		// Cacualate the standard deviation
		stdev = pow((sqtotal / (counter - 1)), 0.5);

		// Loop through and set values according to formula: val_new = (val_old - column_mean) / (column_stdev)
		for(map<double,double>::iterator v = c->second.begin(); v != c->second.end(); ++v) {
			//cout << "stand loop" << endl;
			if (std::isnan(v->second)) {
				dataStandardized_[c->first][v->first] = nan("1");
				continue;
			}
			//cout << "inserting: " << (v->second - mean) / stdev << endl;
			dataStandardized_[c->first][v->first] = (v->second - mean) / stdev;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq (%rax), %rdi
callq 0x8e350
movq %rax, -0x30(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
callq 0x8e3b0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8e380
testb $0x1, %al
jne 0x8d7d9
jmp 0x8da48
movq -0x60(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x68(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x8e3e0
movsd (%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x8d827
jp 0x8d827
jmp 0x8da3a
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e4e0
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e540
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8e510
testb $0x1, %al
jne 0x8d86c
jmp 0x8d8cf
leaq -0x40(%rbp), %rdi
callq 0x8e590
movsd 0x8(%rax), %xmm0
callq 0x8e570
testb $0x1, %al
jne 0x8d885
jmp 0x8d887
jmp 0x8d8c1
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x8e590
movsd -0x70(%rbp), %xmm0
subsd 0x8(%rax), %xmm0
movl $0x2, %edi
callq 0x8e5b0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x8e5e0
jmp 0x8d840
movsd -0x18(%rbp), %xmm0
movl -0x1c(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd 0x14b906(%rip), %xmm1   # 0x1d91f0
callq 0x2f8c0
movsd %xmm0, -0x28(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e4e0
movq %rax, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x8e540
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x8e510
testb $0x1, %al
jne 0x8d93c
jmp 0x8da38
leaq -0x50(%rbp), %rdi
callq 0x8e590
movsd 0x8(%rax), %xmm0
callq 0x8e570
testb $0x1, %al
jne 0x8d955
jmp 0x8d9b3
leaq 0x157522(%rip), %rdi    # 0x1e4e7e
callq 0x2fd70
movq -0x60(%rbp), %rax
movsd %xmm0, -0x78(%rbp)
addq $0xc0, %rax
movq %rax, -0x88(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x8e190
movq %rax, -0x80(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8e590
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x8e610
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x8da2a
leaq -0x50(%rbp), %rdi
callq 0x8e590
movq %rax, %rcx
movq -0x60(%rbp), %rax
movsd 0x8(%rcx), %xmm0
subsd -0x10(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0xc0, %rax
movq %rax, -0xa0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8e4c0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x8e190
movq %rax, -0x98(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8e590
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x8e610
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x8e5e0
jmp 0x8d90d
jmp 0x8da3a
leaq -0x30(%rbp), %rdi
callq 0x8e6f0
jmp 0x8d7b3
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)