Esempio n. 1
0
/// 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]);
	}
}
Esempio n. 2
0
/// Apply noise on a constraint vector
void noisy::inject_noise_c(constraint_vector& c) const
{
	for(c_size_type i = 0; i < c.size(); i++){
		if(m_noise_type == NORMAL){
			c[i] += m_normal_dist(m_drng)*m_param_second+m_param_first;
		}
		else if(m_noise_type == UNIFORM){
			c[i] += m_uniform_dist(m_drng)*(m_param_second-m_param_first)+m_param_first;
		}
	}
}
Esempio n. 3
0
/// Apply noise on a fitness vector
void noisy::inject_noise_f(fitness_vector& f) const
{
	for(f_size_type i = 0; i < f.size(); i++){
		if(m_noise_type == NORMAL){
			f[i] += m_normal_dist(m_drng)*m_param_second+m_param_first;
		}
		else if(m_noise_type == UNIFORM){
			f[i] += m_uniform_dist(m_drng)*(m_param_second-m_param_first)+m_param_first;
		}
	}
}