/// Apply noise on the decision vector based on rho void robust::inject_noise_x(decision_vector &x) const { // We follow the algorithm at // http://math.stackexchange.com/questions/87230/picking-random-points-in-the-volume-of-sphere-with-uniform-probability // 0. Define the radius double radius = m_rho * pow(m_uniform_dist(m_drng),1.0/x.size()); // 1. Sampling N(0,1) on each dimension std::vector<double> perturbation(x.size(), 0.0); double c2=0; for(size_type i = 0; i < perturbation.size(); i++){ perturbation[i] = m_normal_dist(m_drng); c2 += perturbation[i]*perturbation[i]; } // 2. Normalize the vector for(size_type i = 0; i < perturbation.size(); i++){ perturbation[i] *= (radius / sqrt(c2) ); x[i] += perturbation[i]; } // 3. Clip the variables to the valid bounds for(base::size_type i = 0; i < x.size(); i++){ x[i] = std::max(x[i], get_lb()[i]); x[i] = std::min(x[i], get_ub()[i]); } }
/// Implementation of the sparsity structure: automated detection void earth_planet::set_sparsity(int &lenG, std::vector<int> &iGfun, std::vector<int> &jGvar) const { //Initial point decision_vector x0(get_dimension()); for (pagmo::decision_vector::size_type i = 0; i<x0.size(); ++i) { x0[i] = get_lb()[i] + (get_ub()[i] - get_lb()[i]) / 3.12345; } //Numerical procedure estimate_sparsity(x0, lenG, iGfun, jGvar); }
double antibodies_problem::compute_distance(const decision_vector &x) const { double distance = 0.; // hamming distance switch(m_method) { case(algorithm::cstrs_immune_system::HAMMING): { const decision_vector &lb = get_lb(); const decision_vector &ub = get_ub(); for(decision_vector::size_type i=0; i<x.size(); i++) { std::vector<int> current_binary_gene = double_to_binary(x.at(i), lb.at(i), ub.at(i)); for(decision_vector::size_type j=0; j<m_pop_antigens.size(); j++) { std::vector<int> antigens_binary_gene = double_to_binary((m_pop_antigens.at(j)).at(i), lb.at(i), ub.at(i)); for(std::vector<int>::size_type k=0; k<antigens_binary_gene.size(); k++) { distance += antigens_binary_gene.at(k) && current_binary_gene.at(k); } } } // we take the inverse of the distance as the measure we need is // how close the x is from the antigen population // which means that we need to maximize the ressemblance distance = - distance; break; } case(algorithm::cstrs_immune_system::EUCLIDEAN): { for(decision_vector::size_type j=0; j<m_pop_antigens.size(); j++) { double euclid = 0.; const decision_vector &antigen_decision = m_pop_antigens.at(j); for(decision_vector::size_type i=0; i<x.size(); i++) { euclid += std::pow(x.at(i) - antigen_decision.at(i),2); } distance += std::sqrt(euclid); } break; } } return distance; }