void BetaMultiple::print(std::ostream& os) { if (n == 0) { oprintf(os,"BetaMultiple (%s): n=0\n",name.c_str()); } else { compute(); oprintf(os,"BetaMultiple (%s)...\n",name.c_str()); mrutils::ColumnBuilder cb; cb.cols(-1,"","Estimate","Std. Error","t value","Pr(>|t|)","",NULL); for (unsigned i = 0; i <= beta.size(); ++i) { const double err = i == 0 ? alphaStderr : betaStderr[i-1]; const double coef = i == 0 ? alpha : beta[i-1]; const double sig = 2*stats::pnorm(-ABS_(coef)/err); cb.fro(i == 0 ? "(intercept)" : xnames[i-1]); cb.add(coef); cb.add(err); if (sig < 2e-16) { cb.add("< 2e-16"); } else cb.add(sig); if (sig < 0.001) cb.add("***"); else if (sig < 0.01) cb.add("**"); else if (sig < 0.05) cb.add("*"); else if (sig < 0.1) cb.add("."); } cb.print(os); cb.clear(); cb.cols(2,"",""); cb.fro(" n:"); cb.add(n); cb.fro(" RSS:"); cb.add(RSS); cb.fro(" stderr:"); cb.add(residStderr); cb.fro(" R2:"); cb.add(R2); cb.print(); } }
static inline __m128i _mm_sad_epu8(__m128i a, __m128i b) { __m128i r = {}; r.m128i_u16[0] = ABS_(a.m128i_u8[ 0] - b.m128i_u8[ 0]) + ABS_(a.m128i_u8[ 1] - b.m128i_u8[ 1]) + ABS_(a.m128i_u8[ 2] - b.m128i_u8[ 2]) + ABS_(a.m128i_u8[ 3] - b.m128i_u8[ 3]) + ABS_(a.m128i_u8[ 4] - b.m128i_u8[ 4]) + ABS_(a.m128i_u8[ 5] - b.m128i_u8[ 5]) + ABS_(a.m128i_u8[ 6] - b.m128i_u8[ 6]) + ABS_(a.m128i_u8[ 7] - b.m128i_u8[ 7]); r.m128i_u16[4] = ABS_(a.m128i_u8[ 8] - b.m128i_u8[ 8]) + ABS_(a.m128i_u8[ 9] - b.m128i_u8[ 9]) + ABS_(a.m128i_u8[10] - b.m128i_u8[10]) + ABS_(a.m128i_u8[11] - b.m128i_u8[11]) + ABS_(a.m128i_u8[12] - b.m128i_u8[12]) + ABS_(a.m128i_u8[13] - b.m128i_u8[13]) + ABS_(a.m128i_u8[14] - b.m128i_u8[14]) + ABS_(a.m128i_u8[15] - b.m128i_u8[15]); return r; }
void BetaMultiple::compute() { if (!dirty) return; if (col <= 0) { houseTransform(M, n, cols+2, diag, dp, maxCols+2); col = cols + 1; } dirty = false; mrutils::printVector(std::cout,diag); beta.resize(cols); xnames.resize(cols); betaStderr.resize(cols); memset(&XtXI[0],0,col*col*8); double sum = 0; /* Invert R */ for (int j = col-1; j >= 0; --j) { if (ABS_(diag[j]) < 1e-6) continue; XtXI[j*col+j] = 1/diag[j]; for (int i = j - 1; i >= 0; i--) { sum = -M(i,j)/diag[j]; for (int k = j-1; k > i; k--) { sum -= M(i,k)*XtXI[col*k+j]; } if (ABS_(diag[i]) >= 1e-6) XtXI[col*i+j] = sum/diag[i]; } } // compute solution for (int i = 0; i < col; ++i) { sum = 0; for (int j = 0; j < col; ++j) { sum += XtXI[col*i+j] * Y(j); } if (i == 0) alpha = sum; else beta[i-1] = sum; } // RSS RSS = SQ(diag[maxCols+1]); R2 = (1 - RSS/(Syy - Sy*Sy/n)); residStderr = sqrt(RSS/(n-cols-1)); // multiply upper triangular by t(upper triangular) // to get standard errors for (int i = 0; i < col; ++i) { for (int j = i; j < col; ++j) { XtXI[col*i+j] *= XtXI[col*j+j]; for (int k = j+1; k < col; ++k) { XtXI[col*i+j] += XtXI[col*i+k] * XtXI[col*j+k]; } } if (i == 0) alphaStderr = sqrt(XtXI[0]) * residStderr; else betaStderr[i-1] = sqrt(XtXI[col*i+i]) * residStderr; } if (storeData) { fitted.clear(); fitted.reserve(n); resid.clear(); resid.reserve(n); for (unsigned i = 0; i < ys.size(); ++i) { double y = alpha; for (int j = 0; j < cols; ++j) y += beta[j] * xs[j][i]; fitted.push_back(y); resid.push_back(y - ys[i]); } } }
void line(t_set set, unsigned int color) { t_draw_line val; t_bunny_position pos; int x1; int y1; int x2; int y2; x1 = set.position1.x; y1 = set.position1.y; x2 = set.position2.x; y2 = set.position2.y; val.dx = x2 - x1; /* la distance horizontal de la ligne */ val.dy = y2 - y1; /* la distance verticale de la ligne */ val.dxabs = ABS_(val.dx); val.dyabs = ABS_(val.dy); val.sdx = SGN_(val.dx); val.sdy = SGN_(val.dy); val.x = val.dyabs>>1; val.y = val.dxabs>>1; val.px = x1; val.py = y1; if (val.dxabs >= val.dyabs) /* la ligne est plus horizontal que vertical */ { val.i = 0; while (val.i < val.dxabs) { val.y += val.dyabs; val.i++; if (val.y >= val.dxabs) { val.y -= val.dxabs; val.py += val.sdy; } val.px += val.sdx; pos.x = val.px; pos.y = val.py; my_set_pix(set.pix, &pos, color); } } else /* la ligne est plus verticale que horizontal */ { val.i = 0; while (val.i < val.dyabs) { val.x += val.dxabs; val.i++; if (val.x >= val.dyabs) { val.x -= val.dyabs; val.px += val.sdx; } val.py += val.sdy; pos.x = val.px; pos.y = val.py; my_set_pix(set.pix, &pos, color); } } }