pair<const vec_t *, const vec_t *> model::regress(const mat_t &training_input, const mat_t &testing_input) { for (int i = 0; i < testing_input.n_cols; ++i) { COV_FUNC->comp_ker(mixture_cov.get(), training_input, testing_input.col(i)); COV_FUNC->comp_ker(testing_cov.get(), testing_input.col(i), testing_input.col(i)); (*testing_cov)(0, 0) += VAR_NOISE; *v = arma::solve(arma::trimatl(chol_cov->t()), *mixture_cov); (*testing_target)(i) = arma::sum(mixture_cov->t() * *alpha); (*testing_var)(i) = arma::sum(*testing_cov - v->t() * *v); } return make_pair(testing_target.get(), testing_var.get()); }
void dTv1(mat_t& drt3_dt1, mat_t& dt3_dt1) { drt3_dt1.create(3, 3); dt3_dt1.create(3, 3); for(int i = 0; i < 3; ++i) { ev.setTo(Scalar(0)); ev(i, 0) = eps; composeRT( rv1, tv1 + ev, rv2, tv2, rv3_p, tv3_p); composeRT( rv1, tv1 - ev, rv2, tv2, rv3_m, tv3_m); drt3_dt1.col(i) = rv3_p - rv3_m; dt3_dt1.col(i) = tv3_p - tv3_m; } drt3_dt1 /= 2 * eps; dt3_dt1 /= 2 * eps; }
void dRv2(mat_t& dr3_dr2, mat_t& dt3_dr2) { dr3_dr2.create(3, 3); dt3_dr2.create(3, 3); for(int i = 0; i < 3; ++i) { ev.setTo(Scalar(0)); ev(i, 0) = eps; composeRT( rv1, tv1, rv2 + ev, tv2, rv3_p, tv3_p); composeRT( rv1, tv1, rv2 - ev, tv2, rv3_m, tv3_m); dr3_dr2.col(i) = rv3_p - rv3_m; dt3_dr2.col(i) = tv3_p - tv3_m; } dr3_dr2 /= 2 * eps; dt3_dr2 /= 2 * eps; }
bool operator == (const mat_t &rhs) { if(rows == rhs.rows && cols == rhs.cols && stride == rhs.stride) { for(unsigned r=0;r<rows;r++){ for(unsigned c=0;c<cols;c++){ if(std::abs(at(r,c) - rhs.at(r,c)) > 0.001) return false; } } return true; } else { return false; } }
void mat_mat_mul( mat_t dst, const mat_t a, const mat_t b ){ if((dst.rows==1) || (dst.cols==1)){ for(unsigned row=0;row<dst.rows;row++){ for(unsigned col=0;col<dst.cols;col++){ double acc=0.0; for(unsigned i=0;i<a.cols;i++){ acc += a.at(row,i) * b.at(i,col); } dst.at(row,col) = acc; } } }else{ local_mat_t right(dst.rows, dst.cols); mat_mat_mul(dst.quad(0,0), a.quad(0,0), b.quad(0,0)); mat_mat_mul(dst.quad(0,1), a.quad(0,0), b.quad(0,1)); mat_mat_mul(dst.quad(1,0), a.quad(1,0), b.quad(0,0)); mat_mat_mul(dst.quad(1,1), a.quad(1,0), b.quad(0,1)); mat_mat_mul(right.quad(0,0), a.quad(0,1), b.quad(1,0)); mat_mat_mul(right.quad(0,1), a.quad(0,1), b.quad(1,1)); mat_mat_mul(right.quad(1,0), a.quad(1,1), b.quad(1,0)); mat_mat_mul(right.quad(1,1), a.quad(1,1), b.quad(1,1)); for(unsigned row=0;row<dst.rows;row++){ for(unsigned col=0;col<dst.cols;col++){ dst.at(row,col) += right.at(row,col); } } } }