// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x8(%rsp)
movq (%rdi), %rax
movq 0x18(%rax), %r14
addq $0x8, %rax
cmpq %rax, %r14
je 0x49cf6
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %rcx
movq %rcx, 0x18(%rsp)
leaq 0xc0(%rax), %r12
leaq 0x20(%r14), %rbp
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x4a2b6
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
ucomisd 0xacf0d(%rip), %xmm0    # 0xf6ae8
jne 0x49be3
jnp 0x49cd6
movq 0x58(%r14), %rax
leaq 0x48(%r14), %rbx
movsd 0xacefd(%rip), %xmm0    # 0xf6af0
cmpq %rbx, %rax
je 0x49c5a
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd 0x28(%rax), %xmm0
xorl %ecx, %ecx
ucomisd %xmm0, %xmm0
setnp %dl
jp 0x49c30
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd (%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movb %dl, %cl
addl %ecx, %r15d
movq %rax, %rdi
callq 0x22670
cmpq %rbx, %rax
jne 0x49c04
decl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0xace96(%rip), %xmm1    # 0xf6af8
callq 0x23210
movsd %xmm0, 0x20(%rsp)
movq 0x58(%r14), %r13
cmpq %rbx, %r13
jne 0x49c86
jmp 0x49cd6
leaq 0xaef5d(%rip), %rdi     # 0xf8bdc
callq 0x22130
jmp 0x49c9e
movsd 0x28(%r13), %xmm0
ucomisd %xmm0, %xmm0
jp 0x49c78
subsd 0x10(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%r13), %r15
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4a1ce
movq %rax, %rdi
movq %r15, %rsi
callq 0x4a332
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r13, %rdi
callq 0x22670
movq %rax, %r13
cmpq %rbx, %rax
jne 0x49c86
movq %r14, %rdi
callq 0x22670
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq $0x8, %rax
cmpq %rax, %r14
jne 0x49bb8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop