// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/regression.c
// Function: train_linearregression
void* train_linearregression(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
	/*!Last Changed 10.12.2004*/
	Model_linearregressionptr m;
	int i, datacount = 0;
	matrix rxy, rxx, mx, mxprime, bmatrix;
	Instanceptr tmp;
	double regmean, y;
 Instance mean;
	m = safemalloc(sizeof(Model_linearregression), "train_linearregression", 6);
	rxy = matrix_alloc(1, current_dataset->multifeaturecount - 1);
 mean = find_mean(*trdata);
	mxprime = instance_to_matrix(&mean);
	mx = matrix_transpose(mxprime);
	matrix_free(mxprime);
	regmean = find_mean_of_regression_value(*trdata);
	rxx = covariance(*trdata, mean);
	matrix_inverse(&rxx);
	tmp = *trdata;
	while (tmp)
	 {
		 datacount++;
		 y = give_regressionvalue(tmp);
		 for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
				 rxy.values[0][i] += (real_feature(tmp, i) - real_feature(&mean, i)) * (y - regmean);
		 tmp = tmp->next;
	 }
	for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
		 rxy.values[0][i] /= (datacount - 1);
	m->w = matrix_multiply(rxy, rxx);
	matrix_free(rxy);
 bmatrix = matrix_multiply(m->w, mx);
 m->b = regmean - bmatrix.values[0][0];
	safe_free(mean.values);
	matrix_free(bmatrix);
	matrix_free(mx);
	matrix_free(rxx);
	return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %r14
leaq 0x364d4(%rip), %rsi     # 0x9fa17
pushq $0x18
popq %rdi
pushq $0x6
popq %rdx
callq 0x34f59
movq %rax, 0x60(%rsp)
leaq 0x64316(%rip), %rbx     # 0xcd870
movq (%rbx), %rax
movl 0x1c0(%rax), %esi
decl %esi
pushq $0x1
popq %rdi
callq 0x380d3
movq %rax, 0x48(%rsp)
movq %rdx, %r13
movq (%r14), %rsi
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x116b6
movq %r15, %rdi
callq 0x2b20d
movq %rax, %r12
movq %rdx, %rbp
movq %rax, %rdi
movq %rdx, %rsi
callq 0x392ac
movq %rax, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3929f
movq (%r14), %rdi
callq 0x2c08f
movsd %xmm0, 0x30(%rsp)
movq (%r14), %rdi
movupd (%r15), %xmm0
movupd 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x106d9
leaq 0x38(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x3a9f7
xorl %ebp, %ebp
movq (%r14), %r14
testq %r14, %r14
je 0x69676
movq %r14, %rdi
callq 0x2b4a0
subsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
xorl %r12d, %r12d
movq (%rbx), %rax
movslq 0x1c0(%rax), %rax
decq %rax
cmpq %rax, %r12
jge 0x6966e
movq %r14, %rdi
movl %r12d, %esi
callq 0x2aea2
movsd %xmm0, 0x70(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x2aea2
movsd 0x70(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x68(%rsp), %xmm1
movq (%r13), %rax
addsd (%rax,%r12,8), %xmm1
movsd %xmm1, (%rax,%r12,8)
incq %r12
jmp 0x6961b
incl %ebp
addq $0x10, %r14
jmp 0x695fc
movq (%rbx), %rax
movl 0x1c0(%rax), %eax
decl %ebp
cvtsi2sd %ebp, %xmm0
cmpl $0x2, %eax
pushq $0x1
popq %rdx
cmovgel %eax, %edx
decl %edx
xorl %eax, %eax
cmpq %rax, %rdx
je 0x696ae
movq (%r13), %rcx
movsd (%rcx,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
incq %rax
jmp 0x69692
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3933d
movq 0x60(%rsp), %r15
movq %rax, 0x8(%r15)
movq %rdx, 0x10(%r15)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3929f
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq 0x58(%rsp), %r12
movq %r12, %rdx
movq 0x50(%rsp), %r13
movq %r13, %rcx
callq 0x3933d
movq %rax, %rbx
movq %rdx, %r14
movq (%rdx), %rax
movsd (%rax), %xmm0
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r15)
movq 0x78(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3929f
movq %r12, %rdi
movq %r13, %rsi
callq 0x3929f
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x3929f
movq %r15, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq