static Term eval2(Int fi, Term t1, Term t2 USES_REGS) { arith2_op f = fi; switch (f) { case op_plus: return p_plus(t1, t2 PASS_REGS); case op_minus: return p_minus(t1, t2 PASS_REGS); case op_times: return p_times(t1, t2 PASS_REGS); case op_div: return p_div(t1, t2 PASS_REGS); case op_idiv: return p_div2(t1, t2 PASS_REGS); case op_and: return p_and(t1, t2 PASS_REGS); case op_or: return p_or(t1, t2 PASS_REGS); case op_sll: return p_sll(t1, t2 PASS_REGS); case op_slr: return p_slr(t1, t2 PASS_REGS); case op_mod: return p_mod(t1, t2 PASS_REGS); case op_rem: return p_rem(t1, t2 PASS_REGS); case op_fdiv: return p_fdiv(t1, t2 PASS_REGS); case op_xor: return p_xor(t1, t2 PASS_REGS); case op_atan2: return p_atan2(t1, t2 PASS_REGS); case op_power: return p_exp(t1, t2 PASS_REGS); case op_power2: return p_power(t1, t2 PASS_REGS); case op_gcd: return p_gcd(t1, t2 PASS_REGS); case op_min: return p_min(t1, t2); case op_max: return p_max(t1, t2); case op_rdiv: return p_rdiv(t1, t2 PASS_REGS); } RERROR(); }
/* for a given input vector INSTANCE, returns the value of OUTPUT_VALUE that yields the maximum return value possible when passed into joint_prob_ln() */ Observation NBClassifier::joint_prob_arg_max(DataInstance::PtrConst _instance) const { Observation arg_max; /* initialized with a probability of 0.0; ln(0.0) = DOUBLE_MIN */ ProbabilityLn p_max(0.0), curr(0.0); /* iterate over possible return values of input_cond_ln_product and keep track of maximum */ for (uint32_t out_cond = 0; out_cond < range_size_; ++out_cond) { curr = joint_prob_ln(_instance, out_cond); if (curr > p_max){ arg_max = out_cond; p_max = curr; } } return arg_max; }
/** Constructor helper method * @param min :: nd-sized vector of the minimum edge of the box in each * dimension * @param max :: nd-sized vector of the maximum edge of the box * */ void MDBoxImplicitFunction::construct(const Mantid::Kernel::VMD &min, const Mantid::Kernel::VMD &max) { size_t nd = min.size(); if (max.size() != nd) throw std::invalid_argument( "MDBoxImplicitFunction::ctor(): Min and max vector sizes must match!"); if (nd == 0 || nd > 100) throw std::invalid_argument( "MDBoxImplicitFunction::ctor(): Invalid number of dimensions!"); double volume = 1; for (size_t d = 0; d < nd; d++) { volume *= (max[d] - min[d]); // Make two parallel planes per dimension // Normal on the min side, so it faces towards +X std::vector<coord_t> normal_min(nd, 0); normal_min[d] = +1.0; // Origin just needs to have its X set to the value. Other coords are // irrelevant std::vector<coord_t> origin_min(nd, 0); origin_min[d] = static_cast<coord_t>(min[d]); // Build the plane MDPlane p_min(normal_min, origin_min); this->addPlane(p_min); // Normal on the max side, so it faces towards -X std::vector<coord_t> normal_max(nd, 0); normal_max[d] = -1.0; // Origin just needs to have its X set to the value. Other coords are // irrelevant std::vector<coord_t> origin_max(nd, 0); origin_max[d] = static_cast<coord_t>(max[d]); // Build the plane MDPlane p_max(normal_max, origin_max); this->addPlane(p_max); } m_volume = volume; }
void RadialBasisInterpolation<KDDim,RBF>::prepare_for_use() { // Call base class methods for prep InverseDistanceInterpolation<KDDim>::prepare_for_use(); InverseDistanceInterpolation<KDDim>::construct_kd_tree(); #ifndef LIBMESH_HAVE_EIGEN libmesh_error_msg("ERROR: this functionality presently requires Eigen!"); #else START_LOG ("prepare_for_use()", "RadialBasisInterpolation<>"); // Construct a bounding box for our source points _src_bbox.invalidate(); const unsigned int n_src_pts = this->_src_pts.size(); const unsigned int n_vars = this->n_field_variables(); libmesh_assert_equal_to (this->_src_vals.size(), n_src_pts*this->n_field_variables()); { Point &p_min(_src_bbox.min()), &p_max(_src_bbox.max()); for (unsigned int p=0; p<n_src_pts; p++) { const Point &p_src(_src_pts[p]); for (unsigned int d=0; d<LIBMESH_DIM; d++) { p_min(d) = std::min(p_min(d), p_src(d)); p_max(d) = std::max(p_max(d), p_src(d)); } } } libMesh::out << "bounding box is \n" << _src_bbox.min() << '\n' << _src_bbox.max() << std::endl; // Construct the Radial Basis Function, giving it the size of the domain if(_r_override < 0) _r_bbox = (_src_bbox.max() - _src_bbox.min()).size(); else _r_bbox = _r_override; RBF rbf(_r_bbox); libMesh::out << "bounding box is \n" << _src_bbox.min() << '\n' << _src_bbox.max() << '\n' << "r_bbox = " << _r_bbox << '\n' << "rbf(r_bbox/2) = " << rbf(_r_bbox/2) << std::endl; // Construct the projection Matrix typedef Eigen::Matrix<Number, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> DynamicMatrix; //typedef Eigen::Matrix<Number, Eigen::Dynamic, 1, Eigen::ColMajor> DynamicVector; DynamicMatrix A(n_src_pts, n_src_pts), x(n_src_pts,n_vars), b(n_src_pts,n_vars); for (unsigned int i=0; i<n_src_pts; i++) { const Point &x_i (_src_pts[i]); // Diagonal A(i,i) = rbf(0.); for (unsigned int j=i+1; j<n_src_pts; j++) { const Point &x_j (_src_pts[j]); const Real r_ij = (x_j - x_i).size(); A(i,j) = A(j,i) = rbf(r_ij); } // set source data for (unsigned int var=0; var<n_vars; var++) b(i,var) = _src_vals[i*n_vars + var]; } // Solve the linear system x = A.ldlt().solve(b); //x = A.fullPivLu().solve(b); // save the weights for each variable _weights.resize (this->_src_vals.size()); for (unsigned int i=0; i<n_src_pts; i++) for (unsigned int var=0; var<n_vars; var++) _weights[i*n_vars + var] = x(i,var); STOP_LOG ("prepare_for_use()", "RadialBasisInterpolation<>"); #endif }
void redraw() { const cv::Mat& img = image.image->getRGBImage(); cv::Mat draw_img = img.clone(); std::stringstream ss; ss << "(" << (crawler.index() + 1) << "/" << crawler.filenames().size() << ") " << crawler.filename(); int i_entity = 1; cv::Mat segm_img(draw_img.rows, draw_img.cols, CV_32SC1, cv::Scalar(0)); for(std::vector<ed::EntityConstPtr>::const_iterator it = image.entities.begin(); it != image.entities.end(); ++it) { const ed::EntityConstPtr& e = *it; ed::MeasurementConstPtr m = e->bestMeasurement(); if (!m) continue; cv::Point p_min(img.cols, img.rows); cv::Point p_max(0, 0); const ed::ImageMask& mask = m->imageMask(); for(ed::ImageMask::const_iterator it = mask.begin(img.cols); it != mask.end(); ++it) { const cv::Point2i& p = *it; segm_img.at<int>(p) = i_entity; p_min.x = std::min(p_min.x, p.x); p_min.y = std::min(p_min.y, p.y); p_max.x = std::max(p_max.x, p.x); p_max.y = std::max(p_max.y, p.y); } cv::rectangle(draw_img, p_min, p_max, cv::Scalar(255, 255, 255), 2); cv::rectangle(draw_img, p_min - cv::Point(2, 2), p_max + cv::Point(2, 2), cv::Scalar(0, 0, 0), 2); cv::rectangle(draw_img, p_min + cv::Point(2, 2), p_max - cv::Point(2, 2), cv::Scalar(0, 0, 0), 2); ++i_entity; } for(int y = 0; y < img.rows; ++y) { for(int x = 0; x < img.cols; ++x) { int i = segm_img.at<int>(y, x); if (i < 1) draw_img.at<cv::Vec3b>(y, x) = 0.5 * draw_img.at<cv::Vec3b>(y, x); } } ss << " (area: " << image.area_name << ")"; cv::rectangle(draw_img, cv::Point(0,0), cv::Point(img.cols,16), CV_RGB(0,0,0), CV_FILLED); cv::putText(draw_img, ss.str().c_str(), cv::Point2i(0, 12), 0, 0.4, cv::Scalar(255,255,255), 1); for (std::vector<Annotation>::const_iterator it = image.annotations.begin(); it != image.annotations.end(); ++it) { const Annotation& a = *it; int x = a.px * img.cols; int y = a.py * img.rows; cv::Scalar text_color(255, 0, 255); if (a.is_supporting) text_color = cv::Scalar(255, 255, 0); cv::circle(draw_img, cv::Point2i(x, y), CIRCLE_RADIUS, cv::Scalar(255,0,0), CV_FILLED); cv::putText(draw_img, a.label.c_str(), cv::Point2i(x+15,y), 0, FONT_SIZE, text_color, 2); } if (!selected_type.empty()) { cv::putText(draw_img, selected_type, cv::Point2i(20, 50), 0, FONT_SIZE, cv::Scalar(100, 100, 255), 2); } else if (!possible_types.empty()) { int n = 3; int i_min = std::max<int>(0, i_possible_types - n + 1); int i_max = std::min<int>(possible_types.size(), i_min + n); for(int i = i_min; i < i_max; ++i) { cv::Scalar text_color(255, 0, 0); if (i == i_possible_types) text_color = cv::Scalar(255, 255, 0); cv::putText(draw_img, possible_types[i], cv::Point2i(20, 50 + 30 * (i - i_min)), 0, FONT_SIZE, text_color, 2); } } cv::imshow(WINDOW_NAME, draw_img); }