// File: /workspace/github_cpp_makefile_star2_O1/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 0x49f1c
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 0x4a4da
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
ucomisd 0xacd37(%rip), %xmm0    # 0xf6b38
jne 0x49e09
jnp 0x49efc
movq 0x58(%r14), %rax
leaq 0x48(%r14), %rbx
movsd 0xacd27(%rip), %xmm0    # 0xf6b40
cmpq %rbx, %rax
je 0x49e80
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd 0x28(%rax), %xmm0
xorl %ecx, %ecx
ucomisd %xmm0, %xmm0
setnp %dl
jp 0x49e56
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 0x49e2a
decl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0xaccc0(%rip), %xmm1    # 0xf6b48
callq 0x23210
movsd %xmm0, 0x20(%rsp)
movq 0x58(%r14), %r13
cmpq %rbx, %r13
jne 0x49eac
jmp 0x49efc
leaq 0xaed57(%rip), %rdi     # 0xf8bfc
callq 0x22130
jmp 0x49ec4
movsd 0x28(%r13), %xmm0
ucomisd %xmm0, %xmm0
jp 0x49e9e
subsd 0x10(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%r13), %r15
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4a3f4
movq %rax, %rdi
movq %r15, %rsi
callq 0x4a556
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r13, %rdi
callq 0x22670
movq %rax, %r13
cmpq %rbx, %rax
jne 0x49eac
movq %r14, %rdi
callq 0x22670
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq $0x8, %rax
cmpq %rax, %r14
jne 0x49dde
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop