color_generator(double s, double v) : s(s), v(v) {
        std::uniform_real_distribution<double> unif(0., 1.);
        std::random_device rand_dev;
        std::mt19937 rand_engine(rand_dev());

        h = unif(rand_engine);
    }
Exemple #2
0
// sum = 1
void randinit_w(std::vector<std::vector<double> > &points, int dimension, double lower_bound, double upper_bound)
{
  std::uniform_real_distribution<double> unif(lower_bound, upper_bound);

  std::random_device rand_dev;          // Use random_device to get a random seed.
  std::mt19937 rand_engine(rand_dev()); // mt19937 is a good pseudo-random number
  // generator.

  for(int i = 0; i < points.size();i++){
    std::vector<double> v(dimension);
    double sum = 0.0;
    for(int j = 0; j < dimension; j++){
      v[j] = (unif(rand_engine));
      sum += v[j];
    }

    double unit = 1.0 / sum;
    sum = 0;
    for(int j = 0; j < dimension; j++){
      v[j] *= unit;
      sum += v[j];
    }
    points[i] = v;
  }
}
Exemple #3
0
bool read_samples(const datasource& ds, std::vector<Sample>& samples) {
    std::size_t limit = 0;

    if (ds.limit > 0) {
        limit = ds.limit;
    }

    if (ds.reader == "mnist") {
        mnist::read_mnist_image_file<std::vector, Sample>(samples, ds.source_file, limit, [] { return Sample(1 * 28 * 28); });
    } else if(ds.reader == "text"){
        dll::text::read_images_direct<std::vector, Sample, Three>(samples, ds.source_file, limit);
    } else {
        std::cout << "dllp: error: unknown samples reader: " << ds.reader << std::endl;
        return false;
    }

    if (ds.binarize) {
        mnist::binarize_each(samples);
    }

    if (ds.normalize) {
        mnist::normalize_each(samples);
    }

    if (ds.shift) {
        for (auto& vec : samples) {
            for (auto& v : vec) {
                v += ds.shift_d;
            }
        }
    }

    if (ds.scale) {
        for (auto& vec : samples) {
            for (auto& v : vec) {
                v *= ds.scale_d;
            }
        }
    }

    if (ds.normal_noise) {
        mnist::normalize_each(samples);

        std::random_device rd;
        std::default_random_engine rand_engine(rd());
        std::normal_distribution<float> normal_distribution(0.0, ds.normal_noise_d);
        auto noise = std::bind(normal_distribution, rand_engine);

        for (auto& vec : samples) {
            for (auto& noisy_x : vec) {
                noisy_x += noise();
            }
        }

        mnist::normalize_each(samples);
    }

    return !samples.empty();
}
Exemple #4
0
/*get a rand double value*/
double get_rand(double lower_bound, double upper_bound)
{
  std::uniform_real_distribution<double> unif(lower_bound, upper_bound);
  std::random_device rand_dev;          // Use random_device to get a random seed.
  std::mt19937 rand_engine(rand_dev()); // mt19937 is a good pseudo-random number
  // generator.
  return unif(rand_engine);
}
Exemple #5
0
TEST_F(TrajectoryLibraryTest, TimingTest) {
    StereoOctomap octomap(bot_frames_);

    double altitude = 30;

    // create a random point cloud

    int num_points = 10000;
    int num_lookups = 1000;

    std::uniform_real_distribution<double> uniform_dist(-1000, 1000);
    std::random_device rd;
    std::default_random_engine rand_engine(rd());

    float x[num_points], y[num_points], z[num_points];

    for (int i = 0; i < num_points; i++) {


        // generate a random point
        x[i] = uniform_dist(rand_engine);
        y[i] = uniform_dist(rand_engine);
        z[i] = uniform_dist(rand_engine);

        //std::cout << "Point: (" << this_point[0] << ", " << this_point[1] << ", " << this_point[2] << ")" << std::endl;

    }

    AddManyPointsToOctree(&octomap, x, y, z, num_points, altitude);

    TrajectoryLibrary lib(0);

    lib.LoadLibrary("trajtest/many", true);

    BotTrans trans;
    bot_trans_set_identity(&trans);
    trans.trans_vec[2] = altitude;

    tic();

    for (int i = 0; i < num_lookups; i++) {
        double dist;
        const Trajectory *best_traj;
        std::tie(dist, best_traj) = lib.FindFarthestTrajectory(octomap, trans, 50.0);
    }

    double num_sec = toc();

    std::cout << num_lookups <<  " lookups with " << lib.GetNumberTrajectories() << " trajectories on a cloud (" << num_points << ") took: " << num_sec << " sec (" << num_sec / (double)num_lookups*1000.0 << " ms / lookup)" << std::endl;
}
Exemple #6
0
/*Uniform distribution data*/
void randinit(std::vector<std::vector<double> > &points, int dimension, double lower_bound, double upper_bound)
{
  std::uniform_real_distribution<double> unif(lower_bound, upper_bound);

  std::random_device rand_dev;          // Use random_device to get a random seed.
  std::mt19937 rand_engine(rand_dev()); // mt19937 is a good pseudo-random number
  // generator.

  for(int i = 0; i < points.size();i++){
    std::vector<double> v;
    for(int j = 0; j < dimension; j++)
      v.push_back(unif(rand_engine));
    points[i] = v;
  }
}
Exemple #7
0
void DifferentialEvolution::initialize_vector(Parameters &ctl_pars)
{
	std::uniform_real_distribution<double> distribution(0.0, 1.0);
	
	for (const auto &i : parameter_info)
	{
		double p_val; 
		const string &p_name = i.first;
		double rnum = rand_engine();
		// use uniform distribution to initialize parameters
		if (i.second.log_transform)
		{
			double r_num = distribution(rand_engine);
			p_val = log10(i.second.lower_bnd) + r_num * (log10(i.second.upper_bnd) - log10(i.second.lower_bnd));
			p_val = pow(10.0, p_val);
			ctl_pars.insert(p_name, p_val);
		}
		else
		{
			p_val = i.second.lower_bnd + distribution(rand_engine) * (i.second.upper_bnd - i.second.lower_bnd);
			ctl_pars.insert(p_name, p_val);
		}
	}
}
Exemple #8
0
T uniform_bits(){
  std::uniform_int_distribution<T> 
    dist(std::numeric_limits<T>::lowest(),std::numeric_limits<T>::max());
  return dist( rand_engine() );
}
	inline void seed_rand(random_engine::result_type seed)
	{
		rand_engine().seed(seed);
	}
	inline void seed_rand()
	{
		rand_engine().seed(rd());
	}
Exemple #11
0
TEST_F(StereoOctomapTest, CheckAgainstLinearSearch) {

    int num_points = 10000;

    vector<float> x;
    vector<float> y;
    vector<float> z;

    StereoOctomap *stereo_octomap = new StereoOctomap(bot_frames_);

    // create a random point cloud

    std::uniform_real_distribution<double> uniform_dist(-1000, 1000);
    std::random_device rd;
    std::default_random_engine rand_engine(rd());

    for (int i = 0; i < num_points; i++) {

        double this_point[3];

        // generate a random point
        this_point[0] = uniform_dist(rand_engine);
        this_point[1] = uniform_dist(rand_engine);
        this_point[2] = uniform_dist(rand_engine);

        //std::cout << "Point: (" << this_point[0] << ", " << this_point[1] << ", " << this_point[2] << ")" << std::endl;

        double translated_point[3];

        GlobalToCameraFrame(this_point, translated_point);

        x.push_back(translated_point[0]);
        y.push_back(translated_point[1]);
        z.push_back(translated_point[2]);
    }

    lcmt::stereo msg;

    msg.timestamp = GetTimestampNow();

    msg.x = x;
    msg.y = y;
    msg.z = z;

    msg.number_of_points = num_points;

    msg.frame_number = 0;
    msg.video_number = 0;

    stereo_octomap->ProcessStereoMessage(&msg);

    // now perform a bunch of searches

    double time_linear = 0, time_octomap = 0;

    int num_searches = 1000;

    for (int i = 0; i < num_searches; i++) {

        double search_point[3];

        // generate a random point
        search_point[0] = uniform_dist(rand_engine);
        search_point[1] = uniform_dist(rand_engine);
        search_point[2] = uniform_dist(rand_engine);

        //std::cout << "search_point: (" << search_point[0] << ", " << search_point[1] << ", " << search_point[2] << ")" << std::endl;


        tic();
        double linear_search_dist = NearestNeighborLinear(x, y, z, search_point);
        time_linear += toc();

        tic();
        double octomap_dist = stereo_octomap->NearestNeighbor(search_point);
        time_octomap += toc();

        EXPECT_NEAR(octomap_dist, linear_search_dist, TOLERANCE);

    }

    std::cout << "\tFor " << num_searches << " searches over " << num_points << " points: " << std:: endl << "\t\tlinear time = " << time_linear << ", octree time = " << time_octomap << ", for a speedup of: " << time_linear / time_octomap << "x" << std::endl;


    delete stereo_octomap;

}
Exemple #12
0
		int operator()(int min_inclusive, int max_inclusive)
		{
			return distribution(rand_engine(), int_distribution::param_type{ min_inclusive, max_inclusive });
		}
Exemple #13
0
		int operator()()
		{
			return distribution(rand_engine());
		}